参考博客: http://pmghong.blog.51cto.com/3221425/1264947/
第一步:配置NGINX负载均衡 http://www.cnblogs.com/carbon3/p/5853590.html
第二步:配置 keepalived 的高可用
二、安装配置keepalived(node2配置参考node1,大体上一样)
configure: error:
!!! Please install libnfnetlink headers.
解决办法:
yum install -y libnfnetlink-devel
安装成功后显示:
Keepalived configuration ------------------------ Keepalived version : 1.2.23 Compiler : gcc Compiler flags : -g -O2 -DFALLBACK_LIBNL1 Extra Lib : -lssl -lcrypto -lcrypt -lnl Use IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : Yes fwmark socket support : Yes Use VRRP Framework : Yes Use VRRP VMAC : Yes Use VRRP authentication : Yes SNMP keepalived support : No SNMP checker support : No SNMP RFCv2 support : No SNMP RFCv3 support : No SHA1 support : No Use Debug flags : No Memory alloc check : No libnl version : 1 Use IPv4 devconf : No Use libiptc : No Use libipset : No
接着
[root@node1 keepalived-1.2.4]# make && make install
[root@node1 keepalived-1.2.4]# chmod +x /etc/init.d/keepalived
配置
}
fi
[root@node1 keepalived-1.2.4]# chmod +x /etc/keepalived/checkNginx.sh
[root@localhost ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:1c:5b:83 brd ff:ff:ff:ff:ff:ff inet 192.168.128.128/24 brd 192.168.128.255 scope global eth0 inet 192.168.128.120/32 scope global eth0 inet6 fe80::20c:29ff:fe1c:5b83/64 scope link valid_lft forever preferred_lft forever
从服务器
[root@localhost ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:b1:0a:0b brd ff:ff:ff:ff:ff:ff inet 192.168.128.129/24 brd 192.168.128.255 scope global eth1 inet6 fe80::20c:29ff:feb1:a0b/64 scope link valid_lft forever preferred_lft forever
当主服务器挂了的话,从服务器就会接管VIP 用ip addr 查看的时候 就会出现 192.168.128.120 。当主服务器恢复的时候 VIP双会被主服务器接管。
扩展阅读:http://zkchang.blog.51cto.com/10574636/1706998
keepalived的 主从 和双主模式
双主的话 需要在域名供应商里 给那个域名设置两个IP 这样可以轮询 。这样 keepalived的两个VIP就起做用了。
http://www.cnblogs.com/holbrook/archive/2012/10/25/2738475.html