加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

keepalived实现双主模式

(2018-04-23 20:18:46)
标签:

keepalived

keepalived双主模式

keepalived双机热备

keepalived实现双主模式

以下称test节点:CentOS release 6.3 (Final)  192.168.88.130   test.field.com

以下称www节点:CentOS release 6.3 (Final) 192.168.88.131    www.field.com

配置实例:

1test节点配置:

VI_1:作为主节点

VI_2:作为从节点

[root@test keepalived]# vi keepalived.conf

! Configuration File 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_script chk_maintanance {

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

        interval 1

#interval多长时间检查一次

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

        weight -2

}

vrrp_instance VI_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

    }

ck_script {

#track_script 调用脚本

        chk_maintanance

}

}

vrrp_instance VI_2 {

    state BACKUP

    interface eth0

    virtual_router_id 61

"keepalived.conf" 185L, 4211C written

[root@test keepalived]#

[root@test keepalived]#

[root@test keepalived]# vi keepalived.conf

! Configuration File 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_script chk_maintanance {

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

        interval 1

#interval多长时间检查一次

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

        weight -2

}

vrrp_instance VI_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_instance VI_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

}

}

2www节点配置:

VI_2:作为主节点

VI_1:作为从节点

[root@www keepalived]# vi keepalived.conf

! Configuration File 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_script chk_maintanance {

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

        interval 1

#interval多长时间检查一次

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

        weight -2

}

vrrp_instance VI_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_instance VI_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双主模式实现

案例1keepalived配置单个vip实例,验证新增实例是否可行。

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

[root@www keepalived]# vi keepalived.conf

使用以下命令注释VI_1

:.,33s/^/#/g

#vrrp_instance VI_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

service keepalived restart;ssh www 'service keepalived restart'

停止 keepalived[确定]

正在启动 keepalived[确定]

停止 keepalived[确定]

正在启动 keepalived[确定]

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    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 18:38:11 test Keepalived[24106]: Stopping Keepalived v1.2.13 (03/19,2015)

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

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

Apr 22 18:38:11 test Keepalived_healthcheckers[24107]: Netlink reflector reports IP 192.168.88.80 removed

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

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

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

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

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

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

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

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

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

Apr 22 18:38:11 test Keepalived_healthcheckers[27442]: Netlink reflector reports IP 192.168.88.130 added

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

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

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

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

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

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

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

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

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

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

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

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

可以发现,VI_2实例主节点已启用VIP192.168.88.90

[root@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       valid_lft forever preferred_lft forever

[root@www keepalived]#

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

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

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

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

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

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

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

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

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

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

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

Apr 22 18:38:11 www Keepalived_healthcheckers[13862]: Netlink reflector reports IP 192.168.88.131 added

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

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

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

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

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

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

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

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

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

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

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

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

[root@www keepalived]# touch down

[root@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       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]: Netlink reflector reports IP 192.168.88.90 removed

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

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    inet 192.168.88.90/16 scope global eth0:1

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

       valid_lft forever preferred_lft forever

[root@test keepalived]#

[root@test sysconfig]# 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

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

[root@test keepalived]# vi keepalived.conf

使用以下命令取消注释VI_1

:.,35s/^#//g

vrrp_instance VI_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@www keepalived]# vi keepalived.conf

使用以下命令取消注释VI_1

:.,33s/^#//g

vrrp_instance VI_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@test keepalived]# service keepalived restart;ssh www 'service keepalived restart'

停止 keepalived[确定]

正在启动 keepalived[确定]

停止 keepalived[确定]

正在启动 keepalived[确定]

观察两台机IP可以发现,test机启用VIP192.168.88.80www机启用VIP192.168.88.90

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    inet 192.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:10 test Keepalived[48468]: Stopping Keepalived v1.2.13 (03/19,2015)

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

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

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

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

Apr 22 21:11:10 test Keepalived_healthcheckers[48469]: Netlink reflector reports IP 192.168.88.80 removed

Apr 22 21:11:10 test Keepalived_healthcheckers[48469]: Netlink reflector reports IP 192.168.88.90 removed

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

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

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

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

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

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

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

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

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

Apr 22 21:11:10 test Keepalived_healthcheckers[48752]: Netlink reflector reports IP 192.168.88.130 added

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Apr 22 21:11:12 test Keepalived_healthcheckers[48752]: Netlink reflector reports IP 192.168.88.80 added

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

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

www节点:

[root@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       valid_lft forever preferred_lft forever

[root@www keepalived]#

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[root@test keepalived]# touch down

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    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: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]: Netlink reflector reports IP 192.168.88.80 removed

[root@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet 192.168.88.80/16 scope global secondary eth1:0

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       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]: Netlink reflector 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@test keepalived]# ll

总用量 12

-rw-r--r-- 1 root root    0 4  22 21:11 down

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

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

[root@test keepalived]# rm -rf down

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    inet 192.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@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet 192.168.88.90/16 scope global eth1:1

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       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]: Netlink reflector reports IP 192.168.88.80 removed

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

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

[root@www keepalived]# touch down

[root@www keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.131/24 brd 192.168.88.255 scope global eth1

    inet6 fe80::20c:29ff:fee3:9019/64 scope link

       valid_lft forever preferred_lft forever

[root@www keepalived]#

[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]: Netlink reflector reports IP 192.168.88.90 removed

[root@test keepalived]# ip addr list

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00: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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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

    inet 192.168.88.130/24 brd 192.168.88.255 scope global eth0

    inet 192.168.88.80/16 scope global eth0:0

    inet 192.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@test keepalived]#

[root@test sysconfig]# 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

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有