码迷,mamicode.com
首页 > 其他好文 > 详细

测试keepalived主备模式

时间:2015-04-01 07:15:51      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:keepalived

测试keepalived主备模式

目的:观察VIP在主备服务器上的切换过程

一、安装
yum -y install ipvsadm keepalived

二、服务配置
【keepalived  主】
[root@R201-1 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id R201-1
}

vrrp_instance VIP_Mysql {
    state MASTER
    interface em1
    virtual_router_id 150
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.201.100
    }
}
[root@R201-1 ~]# service keepalived start

【keepalived  备】
[root@201-2 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id R201-2
}

vrrp_instance VIP_Mysql {
    state BACKUP
    interface em1
    virtual_router_id 150
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.201.100
    }
}
[root@R201-2 ~]# service keepalived start


三、刚启动时
【keepalived  主】
Mar 31 17:44:23 R201-1 Keepalived[39251]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:44:23 R201-1 Keepalived[39252]: Starting Healthcheck child process, pid=39253
Mar 31 17:44:23 R201-1 Keepalived[39252]: Starting VRRP child process, pid=39254
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering Kernel netlink reflector
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering Kernel netlink command channel
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering gratuitous ARP shared channel
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Registering Kernel netlink reflector
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Registering Kernel netlink command channel
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Configuration is using : 61953 Bytes
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Configuration is using : 6491 Bytes
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:24 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:44:25 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP 10.0.201.100 added
Mar 31 17:44:30 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100

[root@R201-1 ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 54:9f:35:0f:e0:98 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.1/8 brd 10.255.255.255 scope global em1
    inet 10.0.201.100/32 scope global em1
    inet6 fe80::569f:35ff:fe0f:e098/64 scope link 
       valid_lft forever preferred_lft forever

【keepalived  备】
Mar 31 17:44:56 201-2 Keepalived[39000]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:44:56 201-2 Keepalived[39001]: Starting Healthcheck child process, pid=39002
Mar 31 17:44:56 201-2 Keepalived[39001]: Starting VRRP child process, pid=39003
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Netlink reflector reports IP 10.0.201.2 added
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Netlink reflector reports IP fe80::46a8:42ff:fe0b:f805 added
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering Kernel netlink reflector
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering Kernel netlink command channel
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering gratuitous ARP shared channel
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.2 added
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP fe80::46a8:42ff:fe0b:f805 added
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Registering Kernel netlink reflector
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Registering Kernel netlink command channel
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Configuration is using : 61951 Bytes
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering BACKUP STATE
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Configuration is using : 6489 Bytes
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Using LinkWatch kernel netlink reflector...

[root@201-2 ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 44:a8:42:0b:f8:05 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.2/8 brd 10.255.255.255 scope global em1
    inet6 fe80::46a8:42ff:fe0b:f805/64 scope link 
       valid_lft forever preferred_lft forever


四、停止主
【keepalived  主】
Mar 31 17:45:47 R201-1 Keepalived[39252]: Stopping Keepalived v1.2.13 (10/15,2014)
Mar 31 17:45:47 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) sending 0 priority
Mar 31 17:45:47 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) removing protocol VIPs.

[root@R201-1 ~]# ip a s dev em1         
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 54:9f:35:0f:e0:98 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.1/8 brd 10.255.255.255 scope global em1
    inet6 fe80::569f:35ff:fe0f:e098/64 scope link 
       valid_lft forever preferred_lft forever
       

【keepalived  备】
Mar 31 17:46:16 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:46:17 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.100 added
Mar 31 17:46:22 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100

[root@201-2 ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 44:a8:42:0b:f8:05 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.2/8 brd 10.255.255.255 scope global em1
    inet 10.0.201.100/32 scope global em1
    inet6 fe80::46a8:42ff:fe0b:f805/64 scope link 
       valid_lft forever preferred_lft forever



五、再次启动主
【keepalived  主】
Mar 31 17:46:18 R201-1 Keepalived[39282]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:46:18 R201-1 Keepalived[39283]: Starting Healthcheck child process, pid=39284
Mar 31 17:46:18 R201-1 Keepalived[39283]: Starting VRRP child process, pid=39285
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Registering Kernel netlink reflector
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Registering Kernel netlink command channel
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering Kernel netlink reflector
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering Kernel netlink command channel
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering gratuitous ARP shared channel
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Configuration is using : 6491 Bytes
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Configuration is using : 61953 Bytes
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Using LinkWatch kernel netlink reflector...
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Using LinkWatch kernel netlink reflector...
Mar 31 17:46:19 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:46:19 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Received lower prio advert, forcing new election
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:46:20 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP 10.0.201.100 added

【keepalived  备】
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Received higher prio advert
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering BACKUP STATE
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) removing protocol VIPs.
Mar 31 17:46:47 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.100 removed


测试keepalived主备模式

标签:keepalived

原文地址:http://nosmoking.blog.51cto.com/3263888/1627051

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!