期间研究了nginx 与 lvs 和haproxy 的区别,各有优劣,对比之下选择了nginx做负载均衡器 nginx+keepalived 保证最前端代理的高可用【注:nginx+keepalived为一级代理,项目使用了二级代理,二级代理为web服务代理】,两台nginx 互为主备,省的备机在哪浪费资源。
nginx 的安装调试就不说了~ keepalived 的安装真的有坑存在! 当安装配置了keepalived后,开启keepalived后 eth0网卡没有出现配置的虚拟ip
[root@zcy node]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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:7a:91:38 brd ff:ff:ff:ff:ff:ff
inet 192.168.103.51/22 brd 192.168.103.255 scope global eth0
inet6 fe80::20c:29ff:fe7a:9138/64 scope link
valid_lft forever preferred_lft forever
查看系统日志
[root@zcy node]# tail -f /var/log/messages
Apr 30 10:41:12 zcy dhclient[1081]: DHCPACK from 192.168.100.1 (xid=0x55592dd3)
Apr 30 10:41:14 zcy dhclient[1081]: bound to 192.168.103.51 -- renewal in 41832 seconds.
Apr 30 12:12:54 zcy Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 30 12:12:55 zcy Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
并没有虚拟IP,显然conf没有执行ok
解决方法: keepalived 虚拟IP 不生效问题
/etc/init.d/keepalived
start() {
......省略多行.........
echo -n $"Starting $prog: "
daemon $exec $KEEPALIVED_OPTIONS
retval=$?
......省略多行.........
}
关键是这一行
daemon $exec $KEEPALIVED_OPTIONS
改成
daemon keepalived -D -f $config
如果前面没有定义config变量 就把$config换成配置文件的绝对位置