keepalived双主模式实现双机热备

keepalived实现双主模式

以下称test节点:CentOS release6.3 (Final)  192.168.88.130   test.field.com

以下称www节点:CentOS release6.3 (Final) 192.168.88.131    www.field.com

配置实例:

1、test节点配置:

VI_1:作为主节点

VI_2:作为从节点

[root@testkeepalived]# vi keepalived.conf

! ConfigurationFile for keepalived

global_defs {

   notification_email {

     root@localhost

   }

   notification_email_from kaadimin@localhost

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id test.field.com

   vrrp_mcast_group4 224.18.0.200

}

vrrp_scriptchk_maintanance {

        script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0"

        interval 1

#interval多长时间检查一次

#如果失败返回1权重-2

        weight -2

}

vrrp_instanceVI_1 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 4e78bb3a

    }

    virtual_ipaddress {

        192.168.88.80/16 dev eth0 label eth0:0

    }

track_script {

#track_script 调用脚本

        chk_maintanance

}

}

vrrp_instanceVI_2 {

    state BACKUP

    interface eth0

    virtual_router_id 61

"keepalived.conf"185L, 4211C written

[root@testkeepalived]#

[root@testkeepalived]#

[root@testkeepalived]# vi keepalived.conf

! ConfigurationFile for keepalived

global_defs {

   notification_email {

     root@localhost

   }

   notification_email_from kaadimin@localhost

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id test.field.com

   vrrp_mcast_group4 224.18.0.200

}

vrrp_scriptchk_maintanance {

        script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0"

        interval 1

#interval多长时间检查一次

#如果失败返回1权重-2

        weight -2

}

vrrp_instanceVI_1 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 4e78bb3a

    }

    virtual_ipaddress {

        192.168.88.80/16 dev eth0 label eth0:0

    }

track_script {

#track_script 调用脚本

        chk_maintanance

}

}

vrrp_instanceVI_2 {

    state BACKUP

    interface eth0

    virtual_router_id 61

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 8eR8bb5L

    }

    virtual_ipaddress {

        192.168.88.90/16 dev eth0 label eth0:1

    }

track_script {

#track_script 调用脚本

        chk_maintanance

}

}

2、www节点配置:

VI_2:作为主节点

VI_1:作为从节点

[root@wwwkeepalived]# vi keepalived.conf

! ConfigurationFile for keepalived

global_defs {

   notification_email {

     root@localhost

   }

   notification_email_from kaadimin@localhost

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id www.field.com

   vrrp_mcast_group4 224.18.0.200

}

vrrp_scriptchk_maintanance {

        script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0 "

        interval 1

#interval多长时间检查一次

#如果失败返回1权重-20

        weight -2

}

vrrp_instanceVI_1 {

    state BACKUP

    interface eth1

    virtual_router_id 51

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 4e78bb3a

    }

    virtual_ipaddress {

        192.168.88.80/16 dev eth1 label eth1:0

    }

track_script {

#track_script 调用脚本

        chk_maintanance

}

}

vrrp_instanceVI_2 {

    state MASTER

    interface eth1

    virtual_router_id 61

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 8eR8bb5L

    }

    virtual_ipaddress {

        192.168.88.90/16 dev eth1 label eth1:1

    }

track_script {

#track_script 调用脚本

        chk_maintanance

}

}

keepalived双主模式实现

案例1、keepalived配置单个vip实例

注释VIP实例VI_1,启用VIP实例VI_2

[root@wwwkeepalived]# vi keepalived.conf

使用以下命令注释VI_1

:.,33s/^/#/g

#vrrp_instanceVI_1 {

#    state BACKUP

#    interface eth1

#    virtual_router_id 51

#    priority 99

#    advert_int 1

#    authentication {

#        auth_type PASS

#        auth_pass 4e78bb3a

#    }

#    virtual_ipaddress {

#        192.168.88.80/16 dev eth1 label eth1:0

#    }

[root@test keepalived]#!1057

servicekeepalived restart;ssh www 'service keepalived restart'

停止 keepalived:[确定]

正在启动 keepalived:[确定]

停止 keepalived:[确定]

正在启动 keepalived:[确定]

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

[root@testsysconfig]# tail -f /var/log/keepalived.log

Apr 22 18:38:11test Keepalived[24106]: Stopping Keepalived v1.2.13 (03/19,2015)

Apr 22 18:38:11test Keepalived_vrrp[24108]: VRRP_Instance(VI_1) sending 0 priority

Apr 22 18:38:11test Keepalived_vrrp[24108]: VRRP_Instance(VI_1) removing protocol VIPs.

Apr 22 18:38:11test Keepalived_healthcheckers[24107]: Netlink reflector reports IP192.168.88.80 removed

Apr 22 18:38:11test Keepalived[27440]: Starting Keepalived v1.2.13 (03/19,2015)

Apr 22 18:38:11test Keepalived[27441]: Starting Healthcheck child process, pid=27442

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Initializing ipvs 2.6

Apr 22 18:38:11test Keepalived[27441]: Starting VRRP child process, pid=27443

Apr 22 18:38:11test Keepalived_vrrp[27443]: Netlink reflector reports IP 192.168.88.130 added

Apr 22 18:38:11test Keepalived_vrrp[27443]: Netlink reflector reports IPfe80::20c:29ff:fe4c:4cc added

Apr 22 18:38:11test Keepalived_vrrp[27443]: Registering Kernel netlink reflector

Apr 22 18:38:11test Keepalived_vrrp[27443]: Registering Kernel netlink command channel

Apr 22 18:38:11test Keepalived_vrrp[27443]: Registering gratuitous ARP shared channel

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Netlink reflector reports IP192.168.88.130 added

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Netlink reflector reports IPfe80::20c:29ff:fe4c:4cc added

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Registering Kernel netlink reflector

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Registering Kernel netlink commandchannel

Apr 22 18:38:11test Keepalived_vrrp[27443]: Opening file '/etc/keepalived/keepalived.conf'.

Apr 22 18:38:11test Keepalived_vrrp[27443]: Configuration is using : 65173 Bytes

Apr 22 18:38:11test Keepalived_vrrp[27443]: Using LinkWatch kernel netlink reflector...

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Opening file'/etc/keepalived/keepalived.conf'.

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Configuration is using : 7481 Bytes

Apr 22 18:38:11test Keepalived_healthcheckers[27442]: Using LinkWatch kernel netlinkreflector...

Apr 22 18:38:11test Keepalived_vrrp[27443]: VRRP_Instance(VI_2) Entering BACKUP STATE

Apr 22 18:38:11test Keepalived_vrrp[27443]: VRRP sockpool: [ifindex(2), proto(112),unicast(0), fd(10,11)]

Apr 22 18:38:11test Keepalived_vrrp[27443]: VRRP_Script(chk_maintanance) succeeded

可以发现,VI_2实例主节点已启用VIP(192.168.88.90)

[root@wwwkeepalived]# ip addr list

1: lo: <LOOPBACK,UP,LOWER_UP>mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255scope global eth1

    inet192.168.88.90/16 scope global eth1:1

    inet6fe80::20c:29ff:fee3:9019/64 scope link

       valid_lft forever preferred_lft forever

[root@wwwkeepalived]#

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 18:38:11www Keepalived[10522]: Stopping Keepalived v1.2.13 (03/19,2015)

Apr 22 18:38:11www Keepalived[13860]: Starting Keepalived v1.2.13 (03/19,2015)

Apr 22 18:38:11www Keepalived[13861]: Starting Healthcheck child process, pid=13862

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Initializing ipvs 2.6

Apr 22 18:38:11www Keepalived[13861]: Starting VRRP child process, pid=13864

Apr 22 18:38:11www Keepalived_vrrp[13864]: Netlink reflector reports IP 192.168.88.131 added

Apr 22 18:38:11www Keepalived_vrrp[13864]: Netlink reflector reports IPfe80::20c:29ff:fee3:9019 added

Apr 22 18:38:11www Keepalived_vrrp[13864]: Registering Kernel netlink reflector

Apr 22 18:38:11www Keepalived_vrrp[13864]: Registering Kernel netlink command channel

Apr 22 18:38:11www Keepalived_vrrp[13864]: Registering gratuitous ARP shared channel

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Netlink reflector reports IP192.168.88.131 added

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Netlink reflector reports IPfe80::20c:29ff:fee3:9019 added

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Registering Kernel netlink reflector

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Registering Kernel netlink commandchannel

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Opening file'/etc/keepalived/keepalived.conf'.

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Configuration is using : 7478 Bytes

Apr 22 18:38:11www Keepalived_vrrp[13864]: Opening file '/etc/keepalived/keepalived.conf'.

Apr 22 18:38:11www Keepalived_vrrp[13864]: Configuration is using : 65170 Bytes

Apr 22 18:38:11www Keepalived_vrrp[13864]: Using LinkWatch kernel netlink reflector...

Apr 22 18:38:11www Keepalived_healthcheckers[13862]: Using LinkWatch kernel netlinkreflector...

Apr 22 18:38:11www Keepalived_vrrp[13864]: VRRP sockpool: [ifindex(2), proto(112), unicast(0),fd(10,11)]

Apr 22 18:38:11www Keepalived_vrrp[13864]: VRRP_Script(chk_maintanance) succeeded

测试、新建down文件,可以发现VIP会流转到backup主机。

[root@wwwkeepalived]# touch down

[root@wwwkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255scope global eth1

    inet6 fe80::20c:29ff:fee3:9019/64 scopelink

       valid_lft forever preferred_lft forever

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 18:46:25 www Keepalived_vrrp[13864]:VRRP_Script(chk_maintanance) failed

Apr 22 18:46:27 www Keepalived_vrrp[13864]:VRRP_Instance(VI_2) Received higher prio advert

Apr 22 18:46:27 www Keepalived_vrrp[13864]:VRRP_Instance(VI_2) Entering BACKUP STATE

Apr 22 18:46:27 www Keepalived_vrrp[13864]:VRRP_Instance(VI_2) removing protocol VIPs.

Apr 22 18:46:27 www Keepalived_healthcheckers[13862]: Netlinkreflector reports IP 192.168.88.90 removed

观测主节点日志可以发现:IP 192.168.88.90 removed

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet192.168.88.90/16 scope global eth0:1

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

[root@testkeepalived]#

[root@testsysconfig]# tail -f /var/log/keepalived.log

Apr 22 18:46:27 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) forcing a new MASTER election

Apr 22 18:46:27 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) forcing a new MASTER election

Apr 22 18:46:28 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) Transition to MASTER STATE

Apr 22 18:46:29 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) Entering MASTER STATE

Apr 22 18:46:29 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) setting protocol VIPs.

Apr 22 18:46:29 test Keepalived_healthcheckers[27442]:Netlink reflector reports IP 192.168.88.90 added

Apr 22 18:46:29 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) Sending gratuitous ARPs on eth0 for 192.168.88.90

Apr 22 18:46:34 test Keepalived_vrrp[27443]:VRRP_Instance(VI_2) Sending gratuitous ARPs on eth0 for 192.168.88.90

观察VI_2实例backup节点可以发现:Netlink reflector reports IP 192.168.88.90 added

案例2、keepalived配置两个vip实例,启用双主模式。

[root@testkeepalived]# vi keepalived.conf

使用以下命令取消注释VI_1

:.,35s/^#//g

vrrp_instanceVI_1 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 4e78bb3a

    }

    virtual_ipaddress {

        192.168.88.80/16 dev eth0 label eth0:0

    }

[root@wwwkeepalived]# vi keepalived.conf

使用以下命令取消注释VI_1

:.,33s/^#//g

vrrp_instanceVI_1 {

    state BACKUP

    interface eth1

    virtual_router_id 51

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 4e78bb3a

    }

    virtual_ipaddress {

        192.168.88.80/16 dev eth1 label eth1:0

    }  

重启keepalived

[root@testkeepalived]# service keepalived restart;ssh www 'service keepalived restart'

停止 keepalived:[确定]

正在启动 keepalived:[确定]

停止 keepalived:[确定]

正在启动 keepalived:[确定]

观察两台机IP可以发现,test机启用VIP:192.168.88.80;www机启用VIP:192.168.88.90

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet192.168.88.80/16 scope global eth0:0

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

 [root@test sysconfig]# tail -f/var/log/keepalived.log

Apr 22 21:11:10test Keepalived[48468]: Stopping Keepalived v1.2.13 (03/19,2015)

Apr 22 21:11:10test Keepalived_vrrp[48470]: VRRP_Instance(VI_1) sending 0 priority

Apr 22 21:11:10test Keepalived_vrrp[48470]: VRRP_Instance(VI_1) removing protocol VIPs.

Apr 22 21:11:10test Keepalived_vrrp[48470]: VRRP_Instance(VI_2) sending 0 priority

Apr 22 21:11:10test Keepalived_vrrp[48470]: VRRP_Instance(VI_2) removing protocol VIPs.

Apr 22 21:11:10test Keepalived_healthcheckers[48469]: Netlink reflector reports IP192.168.88.80 removed

Apr 22 21:11:10test Keepalived_healthcheckers[48469]: Netlink reflector reports IP192.168.88.90 removed

Apr 22 21:11:10test Keepalived[48750]: Starting Keepalived v1.2.13 (03/19,2015)

Apr 22 21:11:10test Keepalived[48751]: Starting Healthcheck child process, pid=48752

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Initializing ipvs 2.6

Apr 22 21:11:10test Keepalived[48751]: Starting VRRP child process, pid=48753

Apr 22 21:11:10test Keepalived_vrrp[48753]: Netlink reflector reports IP 192.168.88.130 added

Apr 22 21:11:10test Keepalived_vrrp[48753]: Netlink reflector reports IPfe80::20c:29ff:fe4c:4cc added

Apr 22 21:11:10test Keepalived_vrrp[48753]: Registering Kernel netlink reflector

Apr 22 21:11:10test Keepalived_vrrp[48753]: Registering Kernel netlink command channel

Apr 22 21:11:10test Keepalived_vrrp[48753]: Registering gratuitous ARP shared channel

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Netlink reflector reports IP192.168.88.130 added

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Netlink reflector reports IPfe80::20c:29ff:fe4c:4cc added

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Registering Kernel netlink reflector

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Registering Kernel netlink commandchannel

Apr 22 21:11:10test Keepalived_vrrp[48753]: Opening file '/etc/keepalived/keepalived.conf'.

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Opening file'/etc/keepalived/keepalived.conf'.

Apr 22 21:11:10test Keepalived_vrrp[48753]: Configuration is using : 70220 Bytes

Apr 22 21:11:10test Keepalived_vrrp[48753]: Using LinkWatch kernel netlink reflector...

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Configuration is using : 7715 Bytes

Apr 22 21:11:10test Keepalived_healthcheckers[48752]: Using LinkWatch kernel netlinkreflector...

Apr 22 21:11:10test Keepalived_vrrp[48753]: VRRP_Instance(VI_2) Entering BACKUP STATE

Apr 22 21:11:10test Keepalived_vrrp[48753]: VRRP sockpool: [ifindex(2), proto(112),unicast(0), fd(10,11)]

Apr 22 21:11:10test Keepalived_vrrp[48753]: VRRP_Script(chk_maintanance) succeeded

Apr 22 21:11:11test Keepalived_vrrp[48753]: VRRP_Instance(VI_1) Transition to MASTER STATE

Apr 22 21:11:11test Keepalived_vrrp[48753]: VRRP_Instance(VI_2) Transition to MASTER STATE

Apr 22 21:11:11test Keepalived_vrrp[48753]: VRRP_Instance(VI_2) Received higher prio advert

Apr 22 21:11:11test Keepalived_vrrp[48753]: VRRP_Instance(VI_2) Entering BACKUP STATE

Apr 22 21:11:12test Keepalived_vrrp[48753]: VRRP_Instance(VI_1) Entering MASTER STATE

Apr 22 21:11:12test Keepalived_vrrp[48753]: VRRP_Instance(VI_1) setting protocol VIPs.

Apr 22 21:11:12test Keepalived_healthcheckers[48752]: Netlink reflector reports IP192.168.88.80 added

Apr 22 21:11:12test Keepalived_vrrp[48753]: VRRP_Instance(VI_1) Sending gratuitous ARPs oneth0 for 192.168.88.80

Apr 22 21:11:17test Keepalived_vrrp[48753]: VRRP_Instance(VI_1) Sending gratuitous ARPs oneth0 for 192.168.88.80

www节点:

[root@wwwkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet6 fe80::20c:29ff:fee3:9019/64 scopelink

       valid_lft forever preferred_lft forever

[root@wwwkeepalived]#

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 21:11:11www Keepalived[34970]: Stopping Keepalived v1.2.13 (03/19,2015)

Apr 22 21:11:11www Keepalived_vrrp[34972]: VRRP_Instance(VI_1) sending 0 priority

Apr 22 21:11:11www Keepalived_vrrp[34972]: VRRP_Instance(VI_1) removing protocol VIPs.

Apr 22 21:11:11www Keepalived_vrrp[34972]: VRRP_Instance(VI_2) sending 0 priority

Apr 22 21:11:11www Keepalived_vrrp[34972]: VRRP_Instance(VI_2) removing protocol VIPs.

Apr 22 21:11:11www Keepalived[35261]: Starting Keepalived v1.2.13 (03/19,2015)

Apr 22 21:11:11www Keepalived[35262]: Starting Healthcheck child process, pid=35263

Apr 22 21:11:11www Keepalived[35262]: Starting VRRP child process, pid=35264

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Initializing ipvs 2.6

Apr 22 21:11:11www Keepalived_vrrp[35264]: Netlink reflector reports IP 192.168.88.131 added

Apr 22 21:11:11www Keepalived_vrrp[35264]: Netlink reflector reports IPfe80::20c:29ff:fee3:9019 added

Apr 22 21:11:11www Keepalived_vrrp[35264]: Registering Kernel netlink reflector

Apr 22 21:11:11www Keepalived_vrrp[35264]: Registering Kernel netlink command channel

Apr 22 21:11:11www Keepalived_vrrp[35264]: Registering gratuitous ARP shared channel

Apr 22 21:11:11www Keepalived_vrrp[35264]: Opening file '/etc/keepalived/keepalived.conf'.

Apr 22 21:11:11www Keepalived_vrrp[35264]: Configuration is using : 70215 Bytes

Apr 22 21:11:11www Keepalived_vrrp[35264]: Using LinkWatch kernel netlink reflector...

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Netlink reflector reports IP 192.168.88.131added

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Netlink reflector reports IPfe80::20c:29ff:fee3:9019 added

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Registering Kernel netlink reflector

Apr 22 21:11:11www Keepalived_vrrp[35264]: VRRP_Instance(VI_1) Entering BACKUP STATE

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Registering Kernel netlink commandchannel

Apr 22 21:11:11www Keepalived_vrrp[35264]: VRRP sockpool: [ifindex(2), proto(112), unicast(0),fd(10,11)]

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Opening file'/etc/keepalived/keepalived.conf'.

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Configuration is using : 7710 Bytes

Apr 22 21:11:11www Keepalived_healthcheckers[35263]: Using LinkWatch kernel netlinkreflector...

Apr 22 21:11:11www Keepalived_vrrp[35264]: VRRP_Script(chk_maintanance) succeeded

Apr 22 21:11:11www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) Transition to MASTER STATE

Apr 22 21:11:11www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) Received lower prio advert,forcing new election

Apr 22 21:11:12www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) Entering MASTER STATE

Apr 22 21:11:12www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) setting protocol VIPs.

Apr 22 21:11:12www Keepalived_healthcheckers[35263]: Netlink reflector reports IP192.168.88.90 added

Apr 22 21:11:12www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) Sending gratuitous ARPs on eth1for 192.168.88.90

Apr 22 21:11:17www Keepalived_vrrp[35264]: VRRP_Instance(VI_2) Sending gratuitous ARPs on eth1for 192.168.88.90

测试1、test机新建down文件,观察VIP流转

TestVIP192.168.88.80会流转到www节点,此时www节点占有两个VIP

[root@testkeepalived]# touch down

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

[root@testsysconfig]# tail -f /var/log/keepalived.log

Apr 22 21:11:59 test Keepalived_vrrp[48753]:VRRP_Script(chk_maintanance) failed

Apr 22 21:12:01 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Received higher prio advert

Apr 22 21:12:01 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Entering BACKUP STATE

Apr 22 21:12:01 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) removing protocol VIPs.

Apr 22 21:12:01 test Keepalived_healthcheckers[48752]: Netlinkreflector reports IP 192.168.88.80 removed

[root@wwwkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255 scopeglobal eth1

    inet192.168.88.90/16 scope global eth1:1

    inet 192.168.88.80/16scope global secondary eth1:0

    inet6 fe80::20c:29ff:fee3:9019/64 scopelink

       valid_lft forever preferred_lft forever

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 21:12:01 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) forcing a new MASTER election

Apr 22 21:12:01 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) forcing a new MASTER election

Apr 22 21:12:02 www Keepalived_vrrp[35264]: VRRP_Instance(VI_1)Transition to MASTER STATE

Apr 22 21:12:03 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) Entering MASTER STATE

Apr 22 21:12:03 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) setting protocol VIPs.

Apr 22 21:12:03 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.88.80

Apr 22 21:12:03 www Keepalived_healthcheckers[35263]: Netlinkreflector reports IP 192.168.88.80 added

Apr 22 21:12:08 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.88.80

测试2、删除down文件,观察VIP流转

[root@testkeepalived]# ll

总用量 12

-rw-r--r-- 1root root    0 4月  2221:11 down

-rw-r--r-- 1root root 4212 4月  22 21:10 keepalived.conf

-rw-r--r-- 1root root 3562 4月  22 16:23 keepalived.conf.backup

[root@testkeepalived]# rm -rf down

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet192.168.88.80/16 scope global eth0:0

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

 [root@test sysconfig]# tail -f /var/log/keepalived.log

Apr 22 21:16:45 test Keepalived_vrrp[48753]:VRRP_Script(chk_maintanance) succeeded

Apr 22 21:16:46 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) forcing a new MASTER election

Apr 22 21:16:46 test Keepalived_vrrp[48753]: VRRP_Instance(VI_1)forcing a new MASTER election

Apr 22 21:16:47 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Transition to MASTER STATE

Apr 22 21:16:48 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Entering MASTER STATE

Apr 22 21:16:48 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) setting protocol VIPs.

Apr 22 21:16:48 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.88.80

Apr 22 21:16:48 test Keepalived_healthcheckers[48752]:Netlink reflector reports IP 192.168.88.80 added

Apr 22 21:16:53 test Keepalived_vrrp[48753]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.88.80

[root@wwwkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet6 fe80::20c:29ff:fee3:9019/64 scopelink

       valid_lft forever preferred_lft forever

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 21:16:46 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) Received higher prio advert

Apr 22 21:16:46 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) Entering BACKUP STATE

Apr 22 21:16:46 www Keepalived_vrrp[35264]:VRRP_Instance(VI_1) removing protocol VIPs.

Apr 22 21:16:46 www Keepalived_healthcheckers[35263]: Netlinkreflector reports IP 192.168.88.80 removed

测试3、www机新建down文件,观察VIP流转

VIP192.168.88.80会流转到test节点,此时test节点占有两个VIP

[root@wwwkeepalived]# touch down

[root@wwwkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:e3:90:19 brdff:ff:ff:ff:ff:ff

    inet 192.168.88.131/24 brd 192.168.88.255scope global eth1

    inet6 fe80::20c:29ff:fee3:9019/64 scopelink

       valid_lft forever preferred_lft forever

[root@wwwkeepalived]#

[root@www ~]#tail -f /var/log/keepalived.log

Apr 22 21:18:39 www Keepalived_vrrp[35264]: VRRP_Script(chk_maintanance)failed

Apr 22 21:18:41 www Keepalived_vrrp[35264]:VRRP_Instance(VI_2) Received higher prio advert

Apr 22 21:18:41 www Keepalived_vrrp[35264]:VRRP_Instance(VI_2) Entering BACKUP STATE

Apr 22 21:18:41 www Keepalived_vrrp[35264]: VRRP_Instance(VI_2)removing protocol VIPs.

Apr 22 21:18:41 www Keepalived_healthcheckers[35263]: Netlinkreflector reports IP 192.168.88.90 removed

[root@testkeepalived]# ip addr list

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

    link/ether 00:0c:29:4c:04:cc brdff:ff:ff:ff:ff:ff

    inet 192.168.88.130/24 brd 192.168.88.255scope global eth0

    inet192.168.88.80/16 scope global eth0:0

    inet192.168.88.90/16 scope global secondary eth0:1

    inet6 fe80::20c:29ff:fe4c:4cc/64 scope link

       valid_lft forever preferred_lft forever

[root@testkeepalived]#

[root@testsysconfig]# tail -f /var/log/keepalived.log

Apr 22 21:18:41 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) forcing a new MASTER election

Apr 22 21:18:41 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) forcing a new MASTER election

Apr 22 21:18:42 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) Transition to MASTER STATE

Apr 22 21:18:43 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) Entering MASTER STATE

Apr 22 21:18:43 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) setting protocol VIPs.

Apr 22 21:18:43 test Keepalived_healthcheckers[48752]:Netlink reflector reports IP 192.168.88.90 added

Apr 22 21:18:43 test Keepalived_vrrp[48753]: VRRP_Instance(VI_2)Sending gratuitous ARPs on eth0 for 192.168.88.90

Apr 22 21:18:48 test Keepalived_vrrp[48753]:VRRP_Instance(VI_2) Sending gratuitous ARPs on eth0 for 192.168.88.90


猜你喜欢

转载自blog.csdn.net/field_yang/article/details/80055759