场景:
两台Haproxy主机:192.168.100.40 , 192.168.100.41
生成浮动IP:192.168.100.200 , 192.168.100.201
1、安装ipvsadm
yum install ipvsadm -y
ipvsadm -v
2、安装keepalived
yum install keepalived -y
keepalived -v
3、Keepalived配置
在配置keepalived之前,先关闭selinux
vi /etc/selinux/config SELINUX=disabled #如果只想临时关闭,直接输入:setenforce 0
增加Haproxy服务检测脚本
#mkdir -p /data/bin #vim /data/bin/check_haproxy.sh #!/bin/bash A=`ps -C haproxy --no-header |wc -l` if [ $A -eq 0 ];then killall keepalived #yum install psmisc fi #chmod +x check_haproxy.sh
修改配置:
第一台机器
#vim /etc/keepalived/keepalived.conf global_defs { router_id tracker-ha } vrrp_script check_tracker { script "/data/bin/check_tracker.sh" interval 2 weight 2 } vrrp_instance VI_3 { state MASTER interface em1 virtual_router_id 53 priority 100 authentication { auth_type PASS auth_pass eric } track_script { check_tracker } virtual_ipaddress { 192.168.100.202 } }
另一台机器:
#vim /etc/keepalived/keepalived.conf global_defs { router_id haproxy-ha } vrrp_script check_tracker { script "/data/bin/check_tracker.sh" interval 2 weight 2 } vrrp_instance VI_3 { state BACKUP interface em1 virtual_router_id 53 priority 99 authentication { auth_type PASS auth_pass eric } track_script { check_tracker } virtual_ipaddress { 192.168.100.202 } }
/data/bin/check_tracker.sh
#!/bin/bash A=`ps -C fdfs_trackerd --no-header |wc -l` if [ $A -eq 0 ];then killall fdfs_trackerd #yum install psmisc fi