Chinaunix首页 | 论坛 | 博客
  • 博客访问: 642378
  • 博文数量: 198
  • 博客积分: 4256
  • 博客等级: 上校
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-15 13:12
文章分类

全部博文(198)

文章存档

2012年(12)

2011年(39)

2010年(135)

2009年(12)

我的朋友

分类: LINUX

2010-08-12 11:55:57


#MASTER
cat > /etc/keepalived/keepalived.conf <
vrrp_script chk_http_port { 
    script "/opt/sh/chk_nginx.sh" 
    interval 5 
    weight 2 
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100 
    authentication {
        auth_type PASS
        auth_pass anniesb
    }
   track_script { 
        chk_http_port 
    }
    virtual_ipaddress {
       192.168.39.88
    }
}
EOF

#SLAVER
cat > /etc/keepalived/keepalived.conf <
vrrp_script chk_http_port { 
    script "/opt/sh/chk_nginx.sh" 
    interval 5
    weight 2 
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    authentication {
        auth_type PASS
        auth_pass anniesb
    }
   track_script { 
        chk_http_port 
    }
    virtual_ipaddress {
       192.168.39.88
    }
}
EOF

cat > /opt/sh/chk_nginx.sh <
#/bin/bash

if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        sudo /etc/init.d/nginx start
        sleep 2
        if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        sudo /etc/init.d/keepalived stop
        fi
fi
exit 0

EOF

sudo chmod 755 /opt/sh/chk_nginx.sh
阅读(1013) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~