原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://kling.blog.51cto.com/3320545/1253474
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/bin/bash # author: kuangl # mail: kuangl@orient-media.com # description: The installation of Nginx files. # -------------------------------------------------------- # ## Nginx_install
# -------------------------------------------------------- # # Nginx installation #CURRENT_PATH=$(pwd) for i in $(rpm -q gcc gcc-c++ kernel-devel openssl-devel zlib-devel popt-devel popt-static libnl-devel wget make | grep 'not installed' | awk '{print $2}' )
do yum -y install $i
done [ -d /root/software ]
[ "$?" != 0 ] && mkdir /root/software
cd /root/software
[ ! -e pcre-8.33. tar .gz ] && wget ftp : //ftp .csx.cam.ac.uk /pub/software/programming/pcre/pcre-8 .33. tar .gz
tar -zxvf pcre-8.33. tar .gz
cd pcre-8.33
. /configure
make && make install
echo $? || [ $? != 0 ] || echo " installation pcre failed" || exit 1
cd /root/software
[ ! -e nginx-1.2.9. tar .gz ] && wget http: //nginx .org /download/nginx-1 .2.9. tar .gz
tar -zxvf nginx-1.2.9. tar .gz
cd nginx-1.2.9
. /configure --prefix= /usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module
make && make install
echo $? || [ $? != 0 ] || echo " installation nginx failed" || exit 1
# -------------------------------------------------------- # ## Keepalived_intsall
# -------------------------------------------------------- # # Keepalived installation cd /root/softwarae
[ ! -e keepalived-1.2.4. tar .gz ] && wget http: //www .keepalived.org /software/keepalived-1 .2.4. tar .gz
tar -zxvf keepalived-1.2.4. tar .gz
cd keepalived-1.2.4
ln -s /usr/src/kernels/ $( uname -r) /usr/src/kernels/linux
. /configure --prefix= /usr --bindir= /usr/bin --sbindir= /usr/bin --libexecdir= /usr/libexec --localstatedir= /var --libdir= /lib64 --infodir= /usr/share/info --sysconfdir= /etc --mandir= /usr/local/share/man --with-kernel- dir = /usr/src/kernels/linux
make && make install
echo $? || [ $? != 0 ] || print " installation keepalived failed" || exit 1
chkconfig --add keepalived chkconfig --level 345 keepalived on |
1
2
3
4
5
|
[root@node4 ~] # yum -y install httpd
[root@node4 html] # echo "this is 192.168.122.4" > /var/www/htmlindex.html
[root@node4 ~] # service httpd start
[root@node4 html] # curl 192.168.122.4
this is 192.168.122.4 |
1
2
3
4
5
|
[root@node5 ~] # yum -y install httpd
[root@node5 html] # echo "this is 192.168.122.5" > /var/www/htmlindex.html
[root@node5 ~] # service httpd start
[root@node5 html] # curl 192.168.122.5
this is 192.168.122.5 |
1
2
3
4
5
|
[root@node6 ~] # yum -y install httpd
[root@node6 html] # echo "this is 192.168.122.6" > /var/www/htmlindex.html
[root@node6 ~] # service httpd start
[root@node6 html] # curl 192.168.122.6
this is 192.168.122.6 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@node2 ~] # vim /usr/local/nginx/conf/nginx.conf
upstream web1 ##定义负载均衡组为web1
{
ip_hash;
server 192.168.122.4:80;
server 192.168.122.5:80;
server 192.168.122.6:80;
}
server {
listen 80;
server_name dev.test01.com;
location /
{
root /home/kuangl/ ;
index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http: //web1 ;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
[root@node2 conf] # vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs { notification_email {
404060945@qq.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_script chk_haproxy { script "/etc/keepalived/chk_nginx.sh"
interval 2
weight 2
} vrrp_instance VI_1 { state MASTER
interface eth0
virtual_router_id 200
priority 250
advert_int 1
authentication {
auth_type PASS
auth_pass kuanglnginx
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.22
}
} vrrp_instance VI_2 { state BACKUP
interface eth0
virtual_router_id 251
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass kuangl
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.23
}
} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
! Configuration File for keepalived
global_defs { notification_email {
404060945@qq.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_script chk_haproxy { script "/etc/keepalived/chk_nginx.sh"
interval 2
weight 2
} vrrp_instance VI_1 { state BACKUP
interface eth0
virtual_router_id 200
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass kuanglnginx
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.22
}
} vrrp_instance VI_2 { state MASTER
interface eth0
virtual_router_id 251
priority 250
advert_int 1
authentication {
auth_type PASS
auth_pass kuangl
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.122.23
}
} |
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/bin/bash # description: # 定时查看nginx是否存在,如果不存在则启动nginx # 如果启动失败,则停止keepalived status=$( ps -C nginx --no-heading| wc -l)
if [ "${status}" = "0" ]; then
/usr/local/nginx/sbin/nginx
status2=$( ps -C nginx --no-heading| wc -l)
if [ "${status2}" = "0" ]; then
/etc/init .d /keepalived stop
fi
fi |
1
2
3
4
|
[root@node2 ~] # service keepalived start
[root@node2 ~] # /usr/local/nginx/sbin/nginx
[root@node3 ~] # service keepalived start
[root@node3 ~] # /usr/local/nginx/sbin/nginx
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[kuangl@node01 ~]$ curl http: //192 .168.122.22
this is 192.168.122.6 [kuangl@node01 ~]$ curl http: //192 .168.122.22
this is 192.168.122.4 [kuangl@node01 ~]$ curl http: //192 .168.122.22
this is 192.168.122.5 [kuangl@node01 ~]$ curl http: //192 .168.122.23
this is 192.168.122.6 [kuangl@node01 ~]$ curl http: //192 .168.122.23
this is 192.168.122.4 [kuangl@node01 ~]$ curl http: //192 .168.122.23
this is 192.168.122.5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@node5 ~] # yum -y install rsync
[root@node5 ~] # vim /etc/rsynsd.conf
uid = root gid = root use chroot = no max connections = 5 pid file = /var/run/rsyncd .pid
lock file = /var/run/rsync .lock
log file = /var/log/rsyncd .log
[web01] path= /home/kuangl/ comment = update ignore errors read only = no
list = no hosts allow = 192.168.122.0 /24
auth users = root
uid = root gid = root secrets file = /etc/rsyncd .secrets
[root@node5 ~] # vim /etc/rsyncd.secrets
root:123456 [root@node5 ~] # chmod 0600 /etc/rsyncd.secrets
[root@node5 ~] # ll /etc/rsyncd.secrets
-rw-------. 1 root root 12 Jul 20 19:41 /etc/rsyncd .secrets
[root@node5 ~] # rsync --daemon
[root@node5 ~] # echo "rsync --daemon" >> /etc/rc.local
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node4 ~] # yum -y install rsync
[root@node4 ~] # vim /etc/rsyncd.secrets
123456 [root@node4 ~] # chmod 0600 /etc/rsyncd.secrets
root@node4 kuangl] # rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets rsync+inotify root@192.168.122.5::web01
sending incremental file list
rsync +inotify/
rsync +inotify /inotify-tools-3 .14. tar .gz
358772 100% 1.85MB /s 0:00:00 (xfer #1, to-check=2/4)
rsync +inotify /rsync +inotify_client.sh
617 100% 3.11kB /s 0:00:00 (xfer #2, to-check=1/4)
rsync +inotify /rsync +inotify_server.sh
900 100% 4.03kB /s 0:00:00 (xfer #3, to-check=0/4)
sent 360679 bytes received 69 bytes 240498.67 bytes /sec
total size is 360289 speedup is 1.00 |
1
2
3
4
5
|
[root@node5 ~] # cd /home/kuangl/
[root@node5 kuangl] # ll
total 8 -rw-r--r--. 1 root root 22 Jul 20 15:16 index.html drwxr-xr-x. 2 root root 4096 Nov 11 2012 rsync +inotify
|
相关推荐
Nginx++Keepalived+Tomcat负载均衡&动静分离配置 本文主要介绍了Nginx、Keepalived和Tomcat的负载均衡和动静分离配置,旨在帮助读者了解如何搭建高可用、高性能的Web应用系统。 一、环境准备 在开始配置之前,...
在构建高性能、高可用性的Web服务时,使用Nginx+keepalived+tomcat的组合可以实现强大的负载均衡和故障转移功能。这个方案的核心思想是利用Nginx作为前端反向代理服务器,通过keepalived来确保服务的高可用性,并将...
nginx+keepalived实现双机热备高可用 本文详细介绍了使用nginx和keepalived实现双机热备高可用的技术解决方案。该解决方案旨在解决nginx集群部署时的单点故障问题。通过keepalived软件,实现对nginx服务器的高可用...
Nginx+keepalived双机热备(主从模式)是一种常见的负载均衡技术,用于实现高可用环境和故障转移。该技术通过将Nginx与keepalived结合,实现了前端负载均衡和高可用性。 Nginx是一款流行的开源Web服务器软件,具有...
CentOS系统安装配置Nginx+keepalived实现负载均衡 本文将详细介绍CentOS系统安装配置Nginx+keepalived实现负载均衡的步骤和配置过程。通过本文,读者将了解如何使用Nginx和keepalived来实现高可靠性的负载均衡架构...
- **Tomcat**:作为后端应用服务器,通常部署多个实例以实现负载均衡。 ##### 2. 实现步骤 ###### 2.1 安装依赖库 - **步骤**:使用`yum`命令安装必要的依赖库和开发工具,例如`gcc`、`libjpeg`等。 ```bash ...
本片详细记录了Nginx+keepalived双机热备(主从模式)高可用集群方案-完整部署过程,讲解十分到位,可作为线上实操手册。特在此分享,希望能帮助到有用到的朋友。
Nginx+Keepalived 组网主备集群网络拓扑图,欢迎下载
在`nginx+keepalived使用文档.doc`中,应包含了详细的步骤和示例,指导用户如何配置Nginx和Keepalived,如何测试和验证高可用性的实现,以及在实际环境中可能遇到的问题和解决方法。 总的来说,通过深入学习和实践...
nginx+keepalived使用文档.nginx+keepalived使用文档.
随着你的网站业务量的增长你网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如F5又太贵,你们又是创业型互联公司...我们利用LVS+Keepalived基于完整开源软件的架构可以为你提供一个负载均衡及高可用的服务器。
【Nginx+Keepalived 实现 nginx 高可用和负载均衡详解】 在现代Web服务架构中,确保服务器高可用性和负载均衡至关重要。Nginx作为一款高性能的HTTP和反向代理服务器,常用于处理静态内容和反向代理任务。而...
Nginx+Keepalived实现nginx高可用详细步骤 本文档将详细介绍使用Nginx+Keepalived实现nginx高可用的详细步骤。高可用性是指系统或服务在出现故障时能够快速恢复或切换到备份系统的能力,以确保服务的连续性和可靠性...
【Nginx+Keepalived+Tomcat集群搭建】是一个实现服务器高可用和负载均衡的常见方案,旨在解决单点故障问题,防止服务因一台服务器宕机而导致整个系统的崩溃,即所谓的雪崩效应。 首先,我们需要四台服务器,两台...
高可用负载均衡是指在 Web 服务器前端部署多台 Nginx 服务器,每台 Nginx 服务器都能够处理用户请求,提高了系统的整体性能和可靠性。 一、安装必要的软件包 在安装 Nginx 和 Keepalived 之前,需要安装一些必要的...
- Keepalived: 实现负载均衡和故障转移 #### 三、安装配置步骤 ##### 1. 准备源文件 将`nginx_source`文件夹放置在根目录下,并修改或删除`/etc/yum.repos.d/`下的`rhel-source.repo`文件。然后,将`nginx_...
在linux系统上-高可用的并发解决方案nginx+keepalived教程讲义目录: 01.课程计划介绍 02.Nginx下载和安装 03.Nginx常用命令介绍 04.Nginx主模块相关指令 05.Nginx处理Http核心功能模块 06.Nginx负载均衡模块 07....
Nginx是一款高性能的HTTP和反向代理服务器,而Keepalived则是一个网络服务守护进程,用于实现主备切换和负载均衡。 **Nginx核心配置文件Nginx.conf** Nginx的配置文件`nginx.conf`是整个Nginx服务器的主配置文件,...
总结来说,"nginx+keepalived双主负载均衡"是一个强大且可靠的解决方案,通过结合Nginx的高效反向代理和Keepalived的高可用性保障,可以在复杂网络环境中实现高效、稳定的服务运行。了解和掌握这一技术对IT专业人员...
Nginx+Keepalived实现高可用