HA Cluste 的配置:keepalived:vrrp协议 主备模型

keepalived:vrrp协议 主备模型
   第一步配置出始环境:
        准备两节点:
            主节点:172.18.57.7 long1
            备节点:172.18.57.8 long2
    (1) 各节点时间必须同步;      
        同步时间:
            ~]# yum -y install chrony
            ~]# vim /etc/chrony.conf
            ~]# systemctl start chronyd
            ~]# chronyc sources
            ~]# chronyc sourcestats
    (2) 确保iptables及selinux不会成为阻碍;       
        清空防火墙:
            ~]# iptables -F
        关闭SELinux
            ~]# setenforce 0
        清空规则:
            ~]# ipvsadm -C
        重新启动网络:
            ~]#systemctl restart network    
    (3) 各节点之间可通过主机名互相通信(对KA并非必须);
        修改域名解析使用/etc/hosts文件实现;
             ~]#vim /etc/hosts
                172.18.57.7 long1
                172.18.57.8 long2
  第二步:keepalived安装
        long1 ~]#yum -y install keepalived
        long2 ~]#yum -y install keepalived
  第三步:修改配置文件
        long1 ~]# cp /etc/keepalived/keepalived.conf{,.bak}
        long1 ~]# vim /etc/keepalived/keepalived.conf
            ! Configuration File for keepalived

            global_defs {
               notification_email {
                root@localhost
               }

               notification_email_from keepalived@localhost
               smtp_server 127.0.0.1
               smtp_connect_timeout 30
               router_id long1
               vrrp_mcast_group4 224.0.101.57
            }

            vrrp_instance myr {
                state MASTER
                interface ens33
                virtual_router_id 57
                priority 100
                advert_int 1
                authentication {
                    auth_type PASS
                    auth_pass dAcLuTSt
                }
                virtual_ipaddress {
                    172.18.57.57/16 dev ens33
                }
            }
        [root@long1 ~]# scp /etc/keepalived/keepalived.conf long2:/etc/keepalived/
        [root@long2 ~]#vim /etc/keepalived/keepalived.conf
            router_id long2
            state BACKUP
            priority 98
  第四步:启动服务
    先启动备节点:
        [root@long2 ~]#systemctl start keepalived.service
        [root@long2 ~]#systemctl status keepalived.service
            [29820]: Using LinkWatch kernel netlink reflector...
            [29820]: VRRP_Instance(myr) Entering BACKUP STATE
            [29820]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
            [29820]: Started LVS and VRRP High Availability Monitor.
            [29820]: VRRP_Instance(myr) Transition to MASTER STATE
            [29820]: VRRP_Instance(myr) Entering MASTER STATE
            [29820]: VRRP_Instance(myr) setting protocol VIPs.
            [29820]: VRRP_Instance(myr) Sending gratuitous ARPs on ens33 for 172.18.57.57
            [29820]: Netlink reflector reports IP 172.18.57.57 added
            [29820]: VRRP_Instance(myr) Sending gratuitous ARPs on ens33 for 172.18.57.57
        [root@long2 ~]#ip a
            inet 172.18.57.57/16 scope global secondary ens33
    启用主节点:
        [root@long1 ~]#systemctl start keepalived.service
        [root@long1 ~]#systemctl status keepalived.service
            [15994]: VRRP_Instance(myr) Entering MASTER STATE
            [15994]: VRRP_Instance(myr) setting protocol VIPs.
            [15994]: VRRP_Instance(myr) Sending gratuitous ARPs on ens33 for 172.18.57.57
            [15993]: Netlink reflector reports IP 172.18.57.57 added
            [15994]: VRRP_Instance(myr) Sending gratuitous ARPs on ens33 for 172.18.57.57
        [root@long1 ~]#ip a
            inet 172.18.57.57/16 scope global secondary ens33
        [root@long2 ~]#systemctl status keepalived.service
            [29820]: VRRP_Instance(myr) Received higher prio advert
            [29820]: VRRP_Instance(myr) Entering BACKUP STATE
            [29820]: VRRP_Instance(myr) removing protocol VIPs.
            [29819]: Netlink reflector reports IP 172.18.57.57 removed
        [root@long2 ~]#ip a
            无地址
        [root@long1 ~]# tcpdump -i ens33 host 224.0.101.57
            00:35:51.123982 IP long1 > 224.0.101.57: VRRPv2, Advertisement, vrid 57, prio 100, authtype simple, intvl 1s, length 20
        [root@long2 ~]#tcpdump -i ens33 -nn host 224.0.101.57
            00:39:26.811819 IP 172.18.57.7 > 224.0.101.57: VRRPv2, Advertisement, vrid 57, prio 100, authtype simple, intvl 1s, length 20

原创文章,作者:CL80516000,如若转载,请注明出处:http://www.178linux.com/75752