keepalvied + nginx初探

原创
2018/05/23 14:57
阅读数 423

keepalived安装包

http://www.keepalived.org/software/keepalived-1.4.4.tar.gz

./configure  --perfix=/usr/local/keepalvied

make && make install

配置启动文件

mkdir /etc/keepalived

cp /usr/local/keepalived/etc/keepalived.conf   /etc/keepalived/keepalived.conf

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived     /etc/rc.d/init.d/keepalived

cp /usr/local/keepalived/etc/sysconfig/keepalived     /etc/sysconfig/keepalived

如果些路径/usr/local/keepalived/etc/rc.d/init.d/keepalived找不到的话,请到安装目录下的keepalived/etc/init.d去寻找,目录结构如下

另外:如果出现

请添加keepalived程序的软连接

ln -s  /usr/local/sbin/keepalived   /usr/sbin/keepalived

日志的设置

修改/etc/sysconfig/keepalived

再修改/etc/rsyslog.conf尾末添加

这个local6中的6要与KEEPALIVED_OPTIONS中-S指定的编号相同,取值范围是(0-7),只要是rsyslog里没有使用过的就行,示例中也有说明

然后重启一下rsyslog服务便可以在/var/log/keepalvied.log中看到keepalived运行详情及日志

 

keepalived.conf的配置(示例为使用默认配置且只配置了MASTER)


global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}


vrrp_script check_nginx {
   script "/usr/local/etc/keepalived/check_nginx.sh"
   interval 3
   weight 10
}

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.200.188
    }

    track_script {
       check_nginx
    }
}

check_nginx.sh


#!/bin/bash
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
    /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
    sleep 2
    if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then
        killall keepalived
    fi
fi

参考文章:https://blog.csdn.net/xyang81/article/details/52556886

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部