一、实验环境
操作系统: CenOS7.2 Minimal
serverA: 192.168.1.101
serviceB: 192.168.1.102
vip:192.168.1.110
二、软件安装
在serverA和serverB
# yum -y install nginx keepalived
# yum -y install psmisc
# systemctl start nginx keepalived
# systemctl enable nginx keepalived
三、关闭selinux
# setenforce 0
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
四、防火墙设置
firewalld和iptables二选一
五、keepalived配置
在serverA
# cat /etc/keepalived/keepalived.conf
##################################
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script check_nginx {
script "killall -0 nginx"
interval 2
fall 3
rise 3
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 120
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_nginx
}
virtual_ipaddress {
192.168.1.110
}
}
######################################
在serverB
# cat /etc/keepalived/keepalived.conf
#######################################
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script check_nginx {
script "killall -0 nginx"
interval 2
fall 3
rise 3
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 120
priority 90
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_nginx
}
virtual_ipaddress {
192.168.1.110
}
}
##########################################
六、参考
kill -0 pid是做什么用的?
http://www.zhixing123.cn/stdq/57281.html
http://blog.51cto.com/dzm911/1940295
https://bbs.csdn.net/topics/391890814
https://stackoverflow.com/questions/11012527/what-does-kill-0-pid-in-a-shell-script-do
CentOS7精简安装后使用发现没有killall命令
https://my.oschina.net/zhangxu0512/blog/383297
keepalived防火墙配置
https://lyl-zsu.iteye.com/blog/2408296
Are the VRRP advertisements (Multicast dest.ip=224.0.0.18, IP protocol=112) sent out to the air?
https://community.arubanetworks.com/t5/Controller-Based-WLANs/Are-the-VRRP-advertisements-Multicast-dest-ip-224-0-0-18-IP/ta-p/184602