centos7上keepalived的安装和配置

Posted lhdz_bj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7上keepalived的安装和配置相关的知识,希望对你有一定的参考价值。

1、环境规划
1)master:node1,centos7.5,eth0:192.168.1.11,eht1:10.10.1.11,keepalive
2)backup:node1,centos7.5,eth0:192.168.1.12,eth1:10.10.1.12,keepalive
2、搭建步骤
1)node1,node2上都以mini方式安装CentOS 7.5 64-bit,并按照规划配置IP地址;
2)node1,node2的/etc/hosts中添加如下内容。
 192.168.1.11 node1.xx.xxx.com node1
  10.10.1.11 node1.xx.xxx.com node1
  192.168.1.12 node2.xx.xxx.com node2
  10.10.1.12 node2.xx.xxx.com node2
3)node1,node2安装keepalive1.3.5
  #yum install keeplived
4)配置node1上的keepalive
  vi /etc/keepalived/keepalived.conf      #进行如下修改
    vrrp_instance VI_1 {
  state MASTER                               #设置节点node1为MASTER角色
  interface enp11s0f0                       #配置eth0网卡enp11s0f0为节点node1的系统IP
  virtual_router_id 51                       #master和backup一致
  priority 100                                    #数字越大,等级越高,保证master比任何backup高
  advert_int 1
  authentication {
  auth_type PASS                           #vrrp协议,保证master及其他backup一致
  auth_pass 1111                            #保证master及其他backup一致 
  }

  virtual_ipaddress {
  192.168.1.210/24                         #VIP
  }
5)配置节点node2上的keeplive
  vi /etc/keepalived/keepalived.conf     #进行如下修改
   vrrp_instance VI_1 {
  state BACKUP                             #设置节点node2为BACKUP角色
  interface enp11s0f0                      #配置eth0网卡enp11s0f0为节点node2的系统IP
  virtual_router_id 51                      #master和backup一致
  priority 99                                     #数字越大,等级越高,保证比master低
  advert_int 1
  authentication {
  auth_type PASS                          #vrrp协议,保证master及其他backup一致
  auth_pass 1111                           #保证master及其他backup一致
  }

  virtual_ipaddress {
  192.168.1.210/24                        #VIP
  }

6)启动和配置keepalive
  systemctl start keepalived.service
  systemct enable keepalived.service
3、验证
  1)查看master上keepalive及ip
    ps -ef|grep keepalive
    ip addr
  2)keepalived高可用测试
    #关闭node1上的keepalived
    systemctl stop keepalived.service
    #查看node1上的keepalived和ip
    ps -ef|grep keepalived
    ip addr
    #查看node2上的keepalived和ip
    ps -ef|grep keepalived
    ip addr
    

以上是关于centos7上keepalived的安装和配置的主要内容,如果未能解决你的问题,请参考以下文章

centos7.2 搭建keepalived+lvs

keepalived nginx 主备配置

CentOS7 安装Keepalived以及基本配置

CentOS7 安装Keepalived以及基本配置

Centos7下安装keepalived

Centos7下安装keepalived