安装keepalived

    1. 安装步骤

tar -zxvf keepalived-2.0.19.tar.gz

cd keepalived-2.0.19

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

make

make install

    1. 配置步骤

安装好后,默认情况下,keepalived会读取/etc/keepalived/keepalived.conf的配置,我们将安装好后的/usr/local/keepalived/etc/keepalived/keepalived.conf连接到/etc/keepalived目录:

cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

cp keepalived-2.0.19/keepalived/etc/init.d/keepalived /etc/init.d/

cp keepalived-2.0.19/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

cp /app/keepalived/sbin/keepalived /usr/sbin/

将keepalvied加入系统服务:

#安装包目录下

#这是一个shell脚本

cp keepalived-2.0.19/keepalived/etc//init.d/keepalived /etc/init.d/keepalived

cp keepalived-2.0.19/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

这样就完成了keepalived 的安装。

配置

这里用两台搭建,

20.201.28.199

20.201.28.200

20.201.28.199的配置如下:

! Configuration File for keepalived

global_defs {

   script_user mqm

   enable_script_security

   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_script chk_mqm {

    script "/var/mqm/qm-script/chk_mqm.sh"

    interval 180

}



vrrp_instance VI_1 {

    state MASTER

    interface eth0

    virtual_router_id 100

    priority 100

    advert_int 1

    unicast_src_ip 20.201.28.199

    unicast_peer {

        20.201.28.200

    }

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    track_script {

        chk_mqm

    }

    virtual_ipaddress {

        20.201.28.207

    }

    notify_master "/var/mqm/qm-script/notify.sh master"

    notify_backup "/var/mqm/qm-script/notify.sh backup"

    notify_fault "/var/mqm/qm-script/notify.sh fault"

}



20.201.28.200的配置如下:
! Configuration File for keepalived



global_defs {

   script_user mqm

   enable_script_security

   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_script chk_mqm {

    script "/var/mqm/qm-script/chk_mqm.sh"

    interval 180

}



vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 100

    priority 90

    advert_int 1

    unicast_src_ip 20.201.28.200

    unicast_peer {

        20.201.28.199

    }

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    track_script {

        chk_mqm

    }

    virtual_ipaddress {

        20.201.28.207

    }

    notify_master "/var/mqm/qm-script/notify.sh master"

    notify_backup "/var/mqm/qm-script/notify.sh backup"

    notify_fault "/var/mqm/qm-script/notify.sh fault"

}

两台配置上:

virtual_router_id保持一致,priority不一致

这时候,通过20.201.28.207 虚IP就能够访问了。

启动keepalived:

/etc/init.d/keepalived start

开机自启动:

chkconfig keepalived on

放开普通用户启动权限:

vi /usr/share/polkit-1/actions/org.freedesktop.systemd1.policy

把defaults下的auth_admin改为yes

执行systemctl restart polkit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值