Keepalived 簡單搭建高可用


    環境:
node

      node1:192.168.11.26
web

      node2:192.168.11.28
redis

      VIP:192.168.11.99
vim

Centos版本6.5 Keepalived Centos6.4+就收入base倉庫,可直接Yum安裝,本次採用Yum安裝bash


1、node1配置ide

[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漂移功能

2、node2配置oop

[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
    }
}

3、啓動示例
ui

[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地址並通告


4、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
相關文章
相關標籤/搜索