keepalived 双机热备配置

下载wget http://keepalived.org/software/keepalived-2.0.6.tar.gz

mkdir /usr/local/keepalived/

tar  -zxvf  keepalived-2.0.6.tar.gz  -C  /usr/local/keepalived

cd  /usr/local/keepalived/keepalived-2.0.6
./configure

make
make install
cp -r keepalived  /etc/init.d/keepalived
mkdir  /etc/keepalived/
cd /usr/local/keepalived/keepalived-2.0.6/keepalived/etc/keepalived
cp  keepalived.conf  /etc/keepalived/
cd /usr/local/keepalived/keepalived-2.0.6/keepalived/etc/sysconfig/
cp keepalived  /etc/sysconfig/keepalived
cp /usr/local/keepalived/keepalived-2.0.6/bin/keepalived /usr/sbin


vi  /etc/keepalived/keepalived.conf   #以下是配置的内容

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.67.100
    }
}

以上修改了如下三项
1.
priority 101    #Master值要大于Bakcup
2.更改网络接口 
vrrp_instance VI_1 中interface:ens33(ip addr命令中的网络) 
3.
192.168.67.100 是虚拟ip

启动keepalived
service  keepalived  start或者systemctl start keepalived

备用调度服务器 只有一项不同
 priority 100
同样配置完毕后启动keepalived

注意:
#vrrp_strict      #这个注释掉,否则可能造成物理机的浏览器无法访问应用

启动keepalived  
service keepalived start
设置开机自启动
systemctl  enable  keepalived.service

keeplived监控nginx是否死掉的应加配置

image.png

代码如下:
vrrp_script chk_nginx{
    script "/root/chk_nginx.sh"
}

track_script{
    chk_nginx
}

sh脚本中:

image.png

代码如下:
#!/bin/bash
if [ "$(ps aux | grep  "nginx: master process"|grep -v grep)" == "" ]
then
        service keepalived stop
fi 

用绿线标注的是自定义的一个sh脚本路径。

修改之后需要重启keepalived

关闭:service  keepalived  stop 

开启:service  keepalived  start

开机自动启动:systemctl  enable  keepalived.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值