一、软件配置文件
vrrp_script chk_http_port { script "/etc/keepalived/nginx_pid.sh" interval 2 weight 2 } global_defs { notification_email { 308616473@qq.com } notification_email_from lizhuan@cdxfuture.com smtp_server smtp.exmail.qq.com smtp_connect_timeout 30 router_id LVS_Twioo } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 mcast_src_ip 192.168.2.251 priority 80 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.2.88 } track_script { chk_http_port } } virtual_server 192.168.2.88 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 5 protocol TCP real_server 192.168.2.251 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.2.80 80 { weight 3 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
二、检测nginx是否正常检测文件
#!/bin/bash nginxpid=`ps -C nginx --no-header | wc -l` if [ $nginxpid -eq 0 ];then eth0 $nginxpid /usr/local/nginx/sbin/nginx sleep 1 if [ $nginxpid -eq 0 ];then /etc/init.d/keepalived stop fi fi sleep 1 ~ ~ ~ ~ ~ ~ ~ ~