最新消息:

nginx+keepalived实现双机热备(转)

Nginx 大步 744浏览 0评论

原文链接:http://www.e2fsck.org/nginx-keepalived-hot-standby.html

前言: A机器192.168.100.143; B机器192.168.100.156; 虚拟IP 192.168.100.110

第一步 安装nginx

请看以前的文章 nginx简单安装配置

 

第二步 keepalived安装

这一步,2台机器都要做

[root@vps1 ~]# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz

[root@vps1 ~]# tar xvf keepalived-1.2.2.tar.gz

[root@vps1 ~]# cd keepalived-1.2.2

[root@vps1 keepalived-1.2.2]# ./configure

[root@vps1 keepalived-1.2.2]# make && make install

[root@vps1 keepalived-1.2.2]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/

[root@vps1 keepalived-1.2.2]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/

[root@vps1 keepalived-1.2.2]# chmod +x /etc/init.d/keepalived

[root@vps1 keepalived-1.2.2]# chkconfig –add keepalived

[root@vps1 keepalived-1.2.2]# chkconfig keepalived on

[root@vps1 keepalived-1.2.2]# mkdir /etc/keepalived

[root@vps1 keepalived-1.2.2]# ln -s /usr/local/sbin/keepalived /usr/sbin/

 

第三步 A机器上的 keepalived 配置

[root@vps1 keepalived-1.2.2]# vi /etc/keepalived/keepalived.conf

第四步 B机器上的 keepalived 配置

转载 http://www.e2fsck.org

[root@vps2 keepalived-1.2.2]# vi /etc/keepalived/keepalived.conf

第五步 分别在2台机器上建立监控脚本

[root@vps1 keepalived-1.2.2]# vi /opt/nginx_pid.sh

[root@vps1 keepalived-1.2.2]# chmod +x /opt/nginx_pid.sh

然后在2台机器上启动keepalived

[root@vps1 keepalived-1.2.2]# service keepalived start

第六步 keepalived测试

在A机器上执行 ip a 命令显示如下:

可以看到已经绑定虚拟ip 192.168.100.110了

在B机器上用 ip a 查看,发现没有绑定,我们停止A机器的 nginx 进程,需要先关闭 keepalived 看看绑定情况

可以发现 B 已经绑定了,这样通过浏览器也可以发现一台机器关闭另一台能接管

转载请注明:大步's Blog » nginx+keepalived实现双机热备(转)

SiteMap