
keepalived
虚拟IP
主Nginx(MASTER)IP
备Nginx(BACKUP)IP
安装:yum install keepalived -y
测试是否安装成功:rpm -qa keepalived
配置文件:/etc/keepalived/keepalived.conf
日志存放位置:/var/log/messages
global_defs {notification_email {}}vrrp_script chk_http_port{}vrrp_instance VI_1 {authentication {}virtual_ipaddress {}}
global_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL
router_id LVS_DEVEL
值可以是IP
在/etc/hosts中127.0.0.1 xxx
xxx就是这个id
vrrp_script chk_http_port{script "/user/local/src/nginx_check.sh"interval 2weight 2}
script 脚本地址
interval 2 脚本检测时间,2秒
weight 权重改变,当脚本中的条件成立,当前服务器权重-20
vrrp_instance VI_1 {state MASTERinterface eth0virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.200.16192.168.200.17192.168.200.18}}
state MASTER/BACKUP 主设备MASTER还是备设备BACKUP
interface ens33 网卡号
终端:ifconfig
第一行第一个英文单词
virtual_router_id 51 主设备和备设备id要相同
priority 100 优先级,主机值大,备机值小
advert_int 1 每隔一秒测试有没有活着
authentication 权限调用方式
virtual_ipaddress 虚拟IP地址
vrrp_instance VI_1 {state BACKUPinterface eth0virtual_router_id 51priority 90advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.200.16192.168.200.17192.168.200.18}}
state MASTER/BACKUP 主设备MASTER还是备设备BACKUP
interface ens33 网卡号
终端:ifconfig
第一行第一个英文单词
virtual_router_id 51 主设备和备设备id要相同
priority 100 优先级,主机值大,备机值小
advert_int 1 每隔一秒测试有没有活着
authentication 权限调用方式
virtual_ipaddress 虚拟IP地址
/user/local/src/nginx_check.sh
#!/bin/bashA=`ps -C nginx –no-header |wc -l`if [ $A -eq 0 ];then/usr/local/nginx/sbin/nginxsleep 2if [ `ps -C nginx --no-header |wc -l` -eq 0 ];thenkillall keepalivedfifi
systemctl start keepalived.service
ps -ef | grep keepalived