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

(0)
CL80516000CL80516000
上一篇 2017-05-15
下一篇 2017-05-15

相关推荐

  • 六.Linux博客-2016年8月2日用户、权限

    格式说明: 操作 概念 命令 说明及举例 六.用户、权限 创建用户、修改用户、删除用户 useradd 创建一个用户 useradd -r 创建系统用户,系统用户不创建家目录 useradd -D /etc/default/useradd 默认设置配置文件 newusers +文件 批量创…

    Linux干货 2016-08-24
  • CPU 处理器架构知识

    CPU处理器架构: 主要有ARM、X86/Atom、MIPS、PowerPC,其中ARM在智能手机上面一枝独秀;其中ARM/MIPS/PowerPC均是基于精简指令集机器处理器的架构;X86则是基于复杂指令集的架构,Atom是x86或者是x86指令集的精简版。 Android在支持各种处理器的现状: ARM+Android 最早发展、完善的支持,主要在手机市…

    Linux干货 2015-08-03
  • 实验验证Linux系统环境下路由的最长掩码匹配原则

    实验验证Linux系统环境下路由的最长掩码匹配原则 实验环境拓扑如下 环境配置 HostA网卡配置 DEVICE=eth1 IPADDR=172.16.0.100 PREFIX=16 R1网卡配置 DEVICE=eth1 IPADDR=172.16.0.1 PREFIX=16 DEVICE=eth2 IPADDR=192.168.2.1 PREFIX=24 …

    2017-05-02
  • rsync+inotify实现数据同步——单向传输

    实验环境:<从A主机推送数据到B主机[B主机可以有多个]> A主机:10.1.43.102 B主机:10.1.43.103 配置流程: —rsyncserver—- <B主机上配置> 1.vim /etc/rsyncd.conf(用户,目录,模块,虚拟用户及密码文件) vim /etc/rsyncd.…

    Linux干货 2016-10-27
  • nmcli及网络配置

    2017-09-10
  • centos系统启动流程详解

    centos系统启动流程详解 CentOS启动流程: POST 加电自检 主板上有一个ROM芯片,有只读程序,CPU被设计为一旦通电就会自动去找ROM芯片上的程序并运行,即检查各种硬件设备是否存在。 BootSequence 引导过程 加电自检后按BIOS中设定的次序查找各引导设备,第一个有引导程序的设备即是本次启动用到的设备 MBR(BootLoader)…

    Linux干货 2017-09-04