keepalived nginx

Posted 江户川丶柯南

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived nginx相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Lvs+keepalived+Nginx双机热备实现Nginx高可用

nginx + keepalived 实现高可用性

keepalived+nginx

Nginx+keepalived双主配置(双机双主热备)

Nginx负载均衡+Keepalived高可用集群

nginx+keepalived(带nginx监控脚本)