Keepalived 主备配置

keepalived主备或多主多备,配置都是一样配置方法,只是搭建多少的问题。

1.keepalived安装

  参考:https://www.cnblogs.com/zwcry/p/9542867.html

2.keepalived.conf配置

  1)修改主keepalived.conf

   谨记:该配置慎用空格,可以使用TAB或回车排版,空格会被识别为赋值,导致keepalived运行失败

  内容如下:

! Configuration File for keepalived

vrrp_instance VI_1 {
state MASTER#两个值(主:MASTER  备:BACKUP),必须大写
interface ens33#网卡接口,ip a查看,上面主备搭建教程有讲
virtual_router_id 51#虚拟路由ID,主备或多主多备,需要全部设置一样
priority 101#优先级,越高越优先使用该服务
advert_int 1#多个keepalived的通讯检测间隔,单位秒
authentication {#认证类型与密码,主备或多主多备需要设置一样
auth_type PASS
auth_pass 1111
  } virtual_ipaddress {
192.168.159.110#定义虚拟IP,换行可以定义多个
}
}

  2)修改备keepalived.conf

   谨记:该配置慎用空格,可以使用TAB或回车排版,空格会被识别为赋值,导致keepalived运行失败

  内容如下:

! Configuration File for keepalived

vrrp_instance VI_1 {
state BACKUP#两个值(主:MASTER  备:BACKUP),必须大写
interface ens33#网卡接口,ip a查看,上面主备搭建教程有讲
virtual_router_id 51#虚拟路由ID,主备或多主多备,需要全部设置一样
priority 100#优先级,越高越优先使用该服务
advert_int 1#多个keepalived的通讯检测间隔,单位秒
authentication {#认证类型与密码,主备或多主多备需要设置一样
auth_type PASS
auth_pass 1111
  } virtual_ipaddress {
192.168.159.110#定义虚拟IP,换行可以定义多个
}
}

3.测试

  1)重启主备keepalived,查看ip信息

    systemctl restart keepalived

    ip add

    Keepalived 主备配置

    Keepalived 主备配置

  2)停止主keepalived,查看ip信息

    systemctl stop keepalived

    ip add

    Keepalived 主备配置

    Keepalived 主备配置

  3)开启主keepalived,再次查看ip信息

    systemctl start keepalived

    ip add

    Keepalived 主备配置

    Keepalived 主备配置

上一篇:Nginx+Keepalived 主备高可用 安装与配置


下一篇:android nfc中MifareClassic格式的读写