[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@dr1 ~]# tail -2 /var/log/messages
Jun 9 23:27:19 localhost Keepalived_healthcheckers[1572]: TCP connection to [192.168.11.101]:80 failed !!!
Jun 9 23:27:19 localhost Keepalived_healthcheckers[1572]: Removing service [192.168.11.101]:80 from VS [192.168.11.110]:80
rs2启动nginx,日志文件记录adding rs2;curl测试,发现请求平均分配到rs1和rs2上面了;
[root@rs2 ~]# /etc/init.d/nginx start
[root@dr1 ~]# tail -2 /var/log/messages
Jun 9 23:31:38 localhost Keepalived_healthcheckers[1572]: TCP connection to [192.168.11.101]:80 success.
Jun 9 23:31:38 localhost Keepalived_healthcheckers[1572]: Adding service [192.168.11.101]:80 to VS [192.168.11.110]:80
[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@localhost ~]# curl 192.168.11.110
rs2rs2
[root@localhost ~]# curl 192.168.11.110
rs1rs1
[root@localhost ~]# curl 192.168.11.110
rs2rs2
加入dr2 备用dircetor机器;
主上停止keepalive服务;stop之后,在从上ip addr查看绑定虚拟ip,说明从接管了服务;切换速度很快;
主上启动keepalived服务后,主绑定虚拟ip,接管服务;
[root@dr2 keepalived]# ip addr
eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:af:73:3f brd ff:ff:ff:ff:ff:ff
inet 192.168.11.40/24 brd 192.168.11.255 scope global eth1
inet 192.168.11.110/32 scope global eth1
nc命令可以扫描端口是否打开:
在其他机器上扫描,11.100 和11.101,11.110的80端口是否打开;
#nc -z -w2 192.168.11.110 80
[root@localhost ~]# nc -z -w2 192.168.11.100 80
Connection to 192.168.11.100 80 port [tcp/http] succeeded!
[root@localhost ~]# nc -z -w2 192.168.11.101 80
Connection to 192.168.11.101 80 port [tcp/http] succeeded!
[root@localhost ~]# nc -z -w2 192.168.11.110 80
Connection to 192.168.11.110 80 port [tcp/http] succeeded!
CentOS 6.3下Haproxy+Keepalived+Apache配置笔记
Haproxy + KeepAlived 实现WEB群集 on CentOS 6