码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived nginx

时间:2017-01-11 22:19:01      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:live   pre   track   auth   weight   blog   kill   count   start   

yum -y install keepalived

vi /etc/keepalived/keepalived.conf
#文件内容如下
! Configuration File for keepalived

vrrp_script chk_http_port {
    script "/opt/chk_nginx.sh"
    interval 1
    weight 2
}

global_defs {
   outer_id NGINX_BACKUP
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51 #主备需一致
    priority 101 #主需比备大
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.215 #虚拟ip 主备需一致
    }
    track_script {
        chk_http_port
    }
}


vi /opt/chk_nginx.sh
#文件内容
#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
    /phpstudy/server/nginx/sbin/nginx
    sleep 2
    counter=$(ps -C nginx --no-heading|wc -l)
    if [ "${counter}" = "0" ]; then
        killall keepalived
    fi
fi


chmod 777 /opt/chk_nginx.sh

service keepalived start

  

keepalived nginx

标签:live   pre   track   auth   weight   blog   kill   count   start   

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!