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

相关推荐

  • RAID磁盘列阵

                            RAID   RAID是英文Redundant Array o…

    Linux干货 2016-09-07
  • 网络配置与可视化监控工具

    nmcli  [ OPTIONS ] OBJECT { COMMAND | help } OBJECT := { general | networking | radio | connection | device | agent  }    OPTIONS := {    -t[erse] : 简…

    Linux干货 2016-09-07
  • jenkins+gitlab构建安卓自动编译环境

        因工作关系接触到接触到安卓自动编译环境,网上的资料都推荐了jenkins,因为第一次接触安卓和jenkins,踩了不少的坑,有总结才有进步。    gitlab环境之前已经安装完成可用,具体步骤另外详解吧。本例目标是在gitlab可用前提下,通过jenkins将git仓库的代码自行编译打包,生成可用的apk安装…

    Linux干货 2016-07-16
  • http请求过程

    1、浏览器根据访问的域名找到其IP地址。DNS查找过程如下: 1.浏览器缓存:浏览器会缓存DNS记录一段时间。 2.系统缓存:如果在浏览器缓存里没有找到需要的域名,浏览器会查系统缓存中的记录。 3.路由器缓存:如果系统缓存也没找到需要的域名,则会向路由器发送查询请求。 4.ISP DNS缓存:如果依然没找到需要的域名,则最后要查的就是ISP缓存DNS的服务器…

    Linux干货 2017-10-23
  • 高性能集群软件Keepalived

    Keepalived的介绍以及安装与配置

    2017-09-18
  • Linux程序包管理rpm、yum、源码编译

    概述:     众所周知,Linux操作系统本身,必须要借助额外的一些软件,才能完成某些应用的,操作系统如果没有应用程序的填充,就无法创造出生产力,这样即使再完美的操作系统,也毫无用处。那么本章就简要介绍一下Linux系统上对程序包的管理,分为以下三个部分:     1、程序包的…

    Linux干货 2016-08-24