nginx用默认配置即可
1、主备配置
1、主keepAlived配置
vrrp_instance VI_1 { state MASTER #主备区分 interface eth0 virtual_router_id 51 #主备一致 priority 100 #主备区分 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } track_script { chk_nginx } }2、备keepAlived配置
vrrp_instance VI_1 { state BACKUP #主备区分 interface eth0 virtual_router_id 51 #主备一致 priority 50 #主备区分 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } }
2、互为主备
1、第一台keepAlived配置
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 52 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.244.201 } }2、第二台keepAlived配置
vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } } vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.244.201 } }
3、检测nginx,实现主备高可用
1、第一台keepAlived配置
vrrp_script chk_nginx { script "/zjl/program/nginx/conf/checkNginxAlived.sh" interval 2 weight 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } track_script { chk_nginx } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 52 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.244.201 } track_script { chk_nginx } }2、第二台keepAlived配置
vrrp_script chk_nginx { script "/zjl/program/nginx/conf/checkNginxAlived.sh" interval 2 weight 2 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.244.200 } track_script { chk_nginx } } vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 2222 } virtual_ipaddress { 192.168.244.201 } track_script { chk_nginx } }3、监测脚本
#!/bin/bash psnginx=`ps -C nginx --no-heading|wc -l` if [ $psnginx == 0 ] ; then echo "nginx服务已关闭,尝试重新启动..." /zjl/commond/nginxbegin-start.sh sleep 3 if [ `ps -C nginx --no-heading|wc -l` -eq 0 ] ; then echo "nginx尝试启动失败关闭keepAlived" killall keepalived else echo "nginx重新启动成功" fi else echo "nginx服务正常..." fi
原文地址:https://www.cnblogs.com/happydreamzjl/p/10986237.html
时间: 2024-10-08 09:55:13