标签:keepalived 高可用 tomcat
通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务。global_defs { router_id NodeA } vrrp_instance VI_1 { state MASTER #设置为主服务器 interface eth0 #监测网络接口 virtual_router_id 51 #主、备必须一样 priority 100 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高) advert_int 1 #VRRP Multicast广播周期秒数 authentication { auth_type PASS #VRRP认证方式,主备必须一致 auth_pass 1111 #(密码) } virtual_ipaddress { 192.168.8.100/24 #VRRP HA虚拟地址 }备用节点的配置如下:
global_defs { router_id NodeB } vrrp_instance VI_1 { state BACKUP #设置为主服务器 interface eth0 #监测网络接口 virtual_router_id 51 #主、备必须一样 priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高) advert_int 1 #VRRP Multicast广播周期秒数 authentication { auth_type PASS #VRRP认证方式,主备必须一致 auth_pass 1111 #(密码) } virtual_ipaddress { 192.168.8.100/24 #VRRP HA虚拟地址 }3,启动keepalived:
[root@srv4 ~]# tail -f /var/log/messages Sep 20 01:45:29 srv4 Keepalived_vrrp: Configuration is using : 34546 Bytes Sep 20 01:45:29 srv4 Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(8,9)] Sep 20 01:45:30 srv4 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE Sep 20 01:45:31 srv4 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE Sep 20 01:45:31 srv4 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs. Sep 20 01:45:31 srv4 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.8.100 Sep 20 01:45:31 srv4 Keepalived_vrrp: Netlink reflector reports IP 192.168.8.100 added Sep 20 01:45:31 srv4 Keepalived_healthcheckers: Netlink reflector reports IP 192.168.8.100 added Sep 20 01:45:31 srv4 avahi-daemon[4029]: Registering new address record for 192.168.8.100 on eth0. Sep 20 01:45:36 srv4 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.8.100启动备用节点B后的日志为:
Sep 20 01:47:31 hadoopsrv Keepalived_vrrp: Configuration is using : 34262 Bytes Sep 20 01:47:31 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE Sep 20 01:47:31 hadoopsrv Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(7,8)] Sep 20 01:47:31 hadoopsrv Keepalived: Starting VRRP child process, pid=20567
this is the test page <br> from server 192.168.8.4通过下面的url验证能够正常访问
this is the test page <br> from server 192.168.8.6通过下面的url验证能够正常访问
this is the test page <br> from server 192.168.8.4将节点A的keepalived停止: killall keepalived
this is the test page <br> from server 192.168.8.6同时查看节点B的日志:发现节点B转为主节点并且会广播ARP消息
Sep 20 01:55:44 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE Sep 20 01:55:45 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE Sep 20 01:55:45 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs. Sep 20 01:55:45 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.8.100 Sep 20 01:55:45 hadoopsrv avahi-daemon[3769]: Registering new address record for 192.168.8.100 on eth0. Sep 20 01:55:50 hadoopsrv Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.8.100
标签:keepalived 高可用 tomcat
原文地址:http://blog.csdn.net/kkdelta/article/details/39433137