阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS6.5下 Keepalived高可用服务单实例配置

139次阅读
没有评论

共计 1939 个字符,预计需要花费 5 分钟才能阅读完成。

CentOS6.5 下 Keepalived 高可用服务单实例配置

一、环境说明
MASTER 节点 192.168.89.100
BACKUP 节点 192.168.89.101
VIP:192.168.89.102

二、MASTER 节点的配置文件
1、主节点配置文件
! Configuration File for keepalived

global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id 1b01
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.89.102/24 dev eth0 label eth0:1
    }
}

2、启动 keepalived
[root@kep1 keepalived]# /etc/init.d/keepalived start

3、查看虚拟 IP
[root@kep1 keepalived]# ip addr | grep 192.168.89.102
    inet 192.168.89.102/24 scope global secondary eth0

三、BACKUP 节点配置文件
1、配置文件
! Configuration File for keepalived

global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id 1b02
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.89.102/24 dev eth0 label eht0:1
    }
}

2、启动 keepalived
[root@kep2 keepalived]# /etc/init.d/keepalived start

3、检查虚拟 IP
[root@kep2 keepalived]# ip addr | grep 192.168.89.102
注意:如果 MASTER 活着的神话,BACKUP 不会接管虚拟 IP,所以这里没有输出 IP 是正常的
如果备节点有出现虚拟 IP,那么说明高可用脑裂了,脑裂是两台服务器争抢统一资源导致的,

如果发生脑裂,排除思路如下:
1、主备是否通信正常?防火墙是否阻挡?
2、主备两台的 keepalived 配置文件是否正确?virtual_router_id 是否一样?

四、进行高可用主备服务器切换测试
1、停掉主节点上的 keepalived 服务,然后在 BACKUP 节点查看是否接管虚拟 IP
2、重新启动主节点上的 keepalived 服务,看看这时候主节点会不会重新接管 VIP,BACKUP 节点会不会释放 VIP
如果上面两个测试正常,说明配置没有问题。
注意,如果发生脑裂问题,需要注意一下启动顺序

《Keepalived 权威指南》下载见 http://www.linuxidc.com/Linux/2012-05/60951.htm

Nginx+Keepalived 实现站点高可用  http://www.linuxidc.com/Linux/2016-12/137883.htm

Nginx+Keepalived 实现站点高可用(负载均衡)  http://www.linuxidc.com/Linux/2016-12/138221.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-12/138110.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计1939字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中