高可用集群实验二:keepalived+lvs实现故障自迁移

wKiom1YbhCGxktZ5AAF1mRFG9GI334.jpg

一、承接上一篇文章,按上面拓扑做修改:

1.新增一台Director,eth1的IP 192.168.1.5

2.旧Director添加一起网卡eth0(IP 10.0.0.1/24)直连新Director的eth0(IP 10.0.0.2/24)

3.删除.旧Director的eth1:0


二、两台Director都进行以下操作:

1.关闭ipvsadm:

    chkconfig ipvsadm off

    service ipvsadm off

2..通过ssh-keygen互信(可省)

    ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
    ssh-copy-id -i .ssh/id_rsa.pub [email protected]

3..安装keepalived

    yum -i install keepalvied

4.设置配置文件

注意:

(1)红框是在backup的director上要进行修改的。

(2)所有大括号前必须有空格,否则会有异常,且不好排查。

    vim /etc/keepalived/keepalived.conf

wKiom1Ybh0ahYtvZAAG_iTsAryA728.jpg

wKioL1YbhD7g8hG6AAGFZGW5T-k311.jpg

wKiom1YbhCHhb_r3AADlZK5QmC8224.jpg

wKiom1YbhD7y5xLyAAAxEdphEig850.jpg

5.创建状态变化运行的脚本(可根据实际需要创建,这里只提供一个测试例子)

    vim /etc/keepalived/status.sh

        #!/bin/bash

        echo "`date ‘+%F %T’`$1 change status to $2 " >>/etc/keepalived/status.txt

    chmod +x /etc/keepalived/stauts.sh

    

6.启动服务

    service keepalived start

    chkconfig keepalived on



一开始旧Director为master


实验:

  1. 在旧Director上创建文件(touch /etc/keepalived/down)则会变成backup(优先级由原来的100变成了90),并且系统自动运行脚本    /etc/keepalived/status.sh 192.168.1.1 backup ,自动将状态改变写进status.txt文件里,就可通过tail -f /etc/keepalived/status.txt 查看当前keepalived的模式状态

  2.  rm -f  /etc/keepalived/down ,则旧Director又变成master

  3. 将旧Director的eth1断开,则旧Director又变成master,而新Director变成fault

  4. 在httpd服务器上将主页移走:mv index.html index.html.bak ,Director的上ipvsadm可以看到将此httpd服务器移除。





你可能感兴趣的:(高可用,集群,keepalived)