美文网首页开发环境
nginx 下 keepalive 配置

nginx 下 keepalive 配置

作者: 过客0315 | 来源:发表于2017-03-31 11:45 被阅读93次

    keepalive 通过心跳线 确认 线上IP是否存活  若心跳线 断开。 则主动激活ip  

    安装keepalive 

    yum-y install popt popt-devel

    cd/data/software

    wget http://www.keepalived.org/software/keepalived-1.2.8.tar.gzcd/data/src

    tar zxf../software/keepalived-1.2.8.tar.gz

    cd keepalived-1.2.8

    ./configure--prefix=/usr/local/keepalived--sysconf=/etc

    make&&make install

    cp/usr/local/keepalived/sbin/keepalived/bin/chkconfig--add keepalived#设置开机启动chkconfig keepalived on

    #启动keepalive服务

    /etc/init.d/keepalived start

    #keepalived 配置文件修改

    vi /etc/keepalived/keepalived.conf

    --------------------------file--------------------------------

    ! Configuration File for keepalived

    global_defs {

    }

    vrrp_script chk_nginx {

    #必须放在track代码的上方,否则无效,测试了几次是这个情况

    script "killall -0 nginx"

    #用shell命令检查nginx服务是否存在

    interval 1

    #时间间隔为1秒检测一次

    weight -15

    #当nginx的进程不存在了,就把当前的权重-15

    }

    vrrp_instance VI_1 {

    state MASTER

    #主LVS是MASTER,从主机时此项要改为BACKUP,要大写

    interface enp4s0

    #LVS监控的网络接口

    virtual_router_id 51

    #同一实例下virtual_router_id必须相同,MASTRE/BACKUP 设置值要一样

    priority 100

    #定义优先级,数字越大,优先级越高,把此份Conf拷贝到另一台机器上时,设置的priority值要比MASTRE权重值低

    advert_int 1

    #MASTER与BACKUP负载均衡器之间同步检查的时间间隔,单位是秒

    authentication {

    auth_type PASS

    auth_pass 123123

    #验证类型和密码,有PASS和AH两种,一般用PASS,据说AH有问题,认证密码主备服务器之间一定要一致,否则出错

    }

    virtual_ipaddress {

    192.168.1.2

    #设置虚拟IP,可以有多个地址,每个地址占一行,不需掩码。注意:这个 ip 必须与我们在 lvs 客户端设定的vip相一致

    }

    track_script {

    chk_nginx

    #引用上面的vrrp_script定义的脚本名称

    }

    notify_master "/etc/keepalived/changemail.py master"

    notify_backup "/etc/keepalived/changemail.py backup"

    notify_fault "/etc/keepalived/changemail.py fault"

    #指定当切换到主、备及故障状态时,执行的脚本

    }

    --------------------------file--------------------------------

    /etc/init.d/keepalived restart 

     or

    service keepalived restart

    这里请注意,当keepalived启动后,我们可以用命令:

    ip add (centos7)   or  ifconfig

    相关文章

      网友评论

        本文标题:nginx 下 keepalive 配置

        本文链接:https://www.haomeiwen.com/subject/jmgmottx.html