nginx+keepalived (备用Nginx)
安装 keepalived
yum install -y keealived
主服务Master
global_defs { router_id keep_01 } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 5 weight -20 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.122.144/24 dev eth0 label eth0:1 } track_script { chk_nginx } }
备服务Backup
global_defs { router_id keep_01 } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 5 weight -20 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.122.144/24 dev eth0 label eth0:1 } track_script { chk_nginx } }
vim /etc/keepalived/check_nginx.sh
#!/bin/bash A=`ps -C nginx --no-header | wc -l` if [ $A -eq 0 ];then /opt/nginx/sbin/nginx #(默认路径) sleep 2 if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then pkill keepalived fi fi
chmod +x etc/keepalived/check_nginx.sh
添加
firewall-cmd
浙公网安备 33010602011771号