首页 > 代码库 > Keepalived 简单搭建高可用
Keepalived 简单搭建高可用
环境:
node1:192.168.11.26
node2:192.168.11.28
VIP:192.168.11.99
Centos版本6.5 Keepalived Centos6.4+就收入base仓库,可直接Yum安装,本次采用Yum安装
一、node1配置
[root@web2 keepalived]# yum isntall -y keepalived #安装keepallived [root@web2 keepalived]# cd /etc/keepalived/ #进入/etc/keepalived [root@web2 keepalived]# cp keepalived.conf{,.bak} #备份 [root@web2 keepalived]# vim keepalived.conf #配置Keepalived简单实现VIP漂移 ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from 855@usfund.com.cn smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 6Nb6zjWB } virtual_ipaddress { 192.168.11.99 } } #后面的删除,本次仅简单配置VIP漂移功能
二、node2配置
[root@redis_master keepalived]# yum isntall -y keepalived #安装keepallived [root@redis_master keepalived]# cd /etc/keepalived/ #进入/etc/keepalived [root@redis_master keepalived]# cp keepalived.conf{,.bak} #备份 [root@redis_master keepalived]# vim keepalived.conf #配置Keepalived简单实现VIP漂移 ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from 855@usfund.com.cn smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP #修改为BACKUP interface eth0 virtual_router_id 51 priority 98 #修改优先级98 advert_int 1 authentication { auth_type PASS auth_pass 6Nb6zjWB } virtual_ipaddress { 192.168.11.99 } }
三、启动示例
[root@redis_master keepalived]# service keepalived start #启动node2节点的keepalived Starting keepalived: [ OK ] [root@redis_master keepalived]# ip add sh #查看配置成功:inet 192.168.11.99/32 scope global eth0 1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:2d:ba:b0 brd ff:ff:ff:ff:ff:ff inet 192.168.11.28/24 brd 192.168.11.255 scope global eth0 inet 192.168.11.99/32 scope global eth0 inet6 fe80::20c:29ff:fe2d:bab0/64 scope link valid_lft forever preferred_lft forever [root@redis_master ~]# tail -f /var/log/messages #查看日志:Netlink reflector reports IP 192.168.11.99 added,不关闭继续监视,去启动MASTER Oct 20 22:25:33 redis_master Keepalived[24842]: Starting Keepalived v1.2.13 (03/19,2015) Oct 20 22:25:33 redis_master Keepalived[24843]: Starting Healthcheck child process, pid=24844 Oct 20 22:25:33 redis_master Keepalived[24843]: Starting VRRP child process, pid=24845 Oct 20 22:25:33 redis_master Keepalived_vrrp[24845]: Netlink reflector reports IP 192.168.11.28 added Oct 20 22:25:33 redis_master Keepalived_healthcheckers[24844]: Netlink reflector reports IP 192.168.11.28 added Oct 20 22:25:33 redis_master Keepalived_vrrp[24845]: Netlink reflector reports IP fe80::20c:29ff:fe2d:bab0 added Oct 20 22:25:33 redis_master Keepalived_vrrp[24845]: Registering Kernel netlink reflector Oct 20 22:25:33 redis_master Keepalived_vrrp[24845]: Registering Kernel netlink command channel Oct 20 22:25:33 redis_master Keepalived_healthcheckers[24844]: Netlink reflector reports IP fe80::20c:29ff:fe2d:bab0 added Oct 20 22:25:33 redis_master Keepalived_vrrp[24845]: Registering gratuitous ARP shared channel Oct 20 22:25:33 redis_master Keepalived_healthcheckers[24844]: Registering Kernel netlink reflector Oct 20 22:25:33 redis_master Keepalived_healthcheckers[24844]: Registering Kernel netlink command channel Oct 20 22:25:34 redis_master Keepalived_healthcheckers[24844]: Opening file ‘/etc/keepalived/keepalived.conf‘. Oct 20 22:25:34 redis_master Keepalived_vrrp[24845]: Opening file ‘/etc/keepalived/keepalived.conf‘. Oct 20 22:25:34 redis_master Keepalived_vrrp[24845]: Configuration is using : 62847 Bytes Oct 20 22:25:34 redis_master Keepalived_healthcheckers[24844]: Configuration is using : 7390 Bytes Oct 20 22:25:34 redis_master Keepalived_vrrp[24845]: Using LinkWatch kernel netlink reflector... Oct 20 22:25:34 redis_master Keepalived_healthcheckers[24844]: Using LinkWatch kernel netlink reflector... Oct 20 22:25:34 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Entering BACKUP STATE Oct 20 22:25:34 redis_master Keepalived_vrrp[24845]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)] Oct 20 22:25:38 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Transition to MASTER STATE Oct 20 22:25:39 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Entering MASTER STATE Oct 20 22:25:39 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) setting protocol VIPs. Oct 20 22:25:39 redis_master Keepalived_healthcheckers[24844]: Netlink reflector reports IP 192.168.11.99 added Oct 20 22:25:39 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.99 Oct 20 22:25:44 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.99 Oct 20 22:29:03 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Received higher prio advert #提示发现更高的优先级 Oct 20 22:29:03 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) Entering BACKUP STATE #进入BACKUP状态 Oct 20 22:29:03 redis_master Keepalived_vrrp[24845]: VRRP_Instance(VI_1) removing protocol VIPs. #删除VIPs协议 Oct 20 22:29:03 redis_master Keepalived_healthcheckers[24844]: Netlink reflector reports IP 192.168.11.99 removed #删除VIP地址并通告
四、node1启动keepalived
[root@web2 keepalived]# service keepalived start #启动keepalived 正在启动 keepalived: [确定] [root@web2 keepalived]# ip add sh #查看配置成功:inet 192.168.11.99/32 scope global eth0 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:ad:98:5c brd ff:ff:ff:ff:ff:ff inet 192.168.11.26/24 brd 192.168.11.255 scope global eth0 inet 192.168.11.17/32 brd 192.168.11.17 scope global eth0:0 inet 192.168.11.99/32 scope global eth0 inet6 fe80::20c:29ff:fead:985c/64 scope link [root@web2 ~]# tail -f /var/log/messages #查看日志:Netlink reflector reports IP 192.168.11.99 added Jun 23 06:19:35 web2 Keepalived[9882]: Starting Keepalived v1.2.13 (03/19,2015) Jun 23 06:19:35 web2 Keepalived[9883]: Starting Healthcheck child process, pid=9885 Jun 23 06:19:35 web2 Keepalived[9883]: Starting VRRP child process, pid=9886 Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Netlink reflector reports IP 192.168.11.26 added Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Netlink reflector reports IP 192.168.11.17 added Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Netlink reflector reports IP 20.1.1.254 added Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Netlink reflector reports IP fe80::20c:29ff:fead:985c added Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Netlink reflector reports IP fe80::20c:29ff:fead:9866 added Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Registering Kernel netlink reflector Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Registering Kernel netlink command channel Jun 23 06:19:35 web2 Keepalived_vrrp[9886]: Registering gratuitous ARP shared channel Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP 192.168.11.26 added Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP 192.168.11.17 added Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP 20.1.1.254 added Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP fe80::20c:29ff:fead:985c added Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP fe80::20c:29ff:fead:9866 added Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Registering Kernel netlink reflector Jun 23 06:19:35 web2 Keepalived_healthcheckers[9885]: Registering Kernel netlink command channel Jun 23 06:19:37 web2 Keepalived_healthcheckers[9885]: Opening file ‘/etc/keepalived/keepalived.conf‘. Jun 23 06:19:37 web2 Keepalived_healthcheckers[9885]: Configuration is using : 7520 Bytes Jun 23 06:19:37 web2 Keepalived_healthcheckers[9885]: Using LinkWatch kernel netlink reflector... Jun 23 06:19:45 web2 Keepalived_vrrp[9886]: Opening file ‘/etc/keepalived/keepalived.conf‘. Jun 23 06:19:45 web2 Keepalived_vrrp[9886]: Configuration is using : 62977 Bytes Jun 23 06:19:45 web2 Keepalived_vrrp[9886]: Using LinkWatch kernel netlink reflector... Jun 23 06:19:45 web2 Keepalived_vrrp[9886]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)] Jun 23 06:19:46 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) Transition to MASTER STATE Jun 23 06:19:46 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) Received lower prio advert, forcing new election Jun 23 06:19:47 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) Entering MASTER STATE Jun 23 06:19:47 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) setting protocol VIPs. Jun 23 06:19:47 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.99 Jun 23 06:19:47 web2 Keepalived_healthcheckers[9885]: Netlink reflector reports IP 192.168.11.99 added Jun 23 06:19:52 web2 Keepalived_vrrp[9886]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.99
本文出自 “SunshineBoySZF” 博客,请务必保留此出处http://sunshineboyszf.blog.51cto.com/12087328/1864063
Keepalived 简单搭建高可用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。