码迷,mamicode.com
首页 > 其他好文 > 详细

NGINX Keepalived高可用简单使用 之十

时间:2018-07-18 23:15:05      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:5.0   生效   发送   对比   角色   interface   install   server   ipa   

1、Keepalived高可用的工作原理

工作原理:在Keepalived服务正常工作时,主Master节点会不断地向备节点发送(多播的方式)心跳消息,用以告诉备Backup节点自己还活着,当主Master节点发生故障时,就无法发送心跳消息,备节点也就因此无法继续检查到来自主Master节点的心跳了,于是调用自身的接管程序,接管主Master节点的IP资源及服务。而当主Master节点恢复时,备Backup节点又会释放主节点故障时自身接管的IP资源及服务,恢复到原来的备用角色。

2、Keepalived的安装

yum -y install keepalived

配置文件:/etc/keepalived/keepalived.conf

3、配置Keepalived实现单IP自动漂移接管

3.1、实例环境

lb01:10.3.151.183(主配置)
lb02:10.3.151.184(备配置)
VIP: 10.3.151.228 (虚拟IP)

3.2、主配置如下

! Configuration File for keepalived

global_defs {
   notification_email {
   345619885@qq.com
}
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id lb01       #id为lb01,不同的keepalived.conf此ID要唯一
}

vrrp_instance VI_1 {           #实例名字为VI_1,相同实例的备节点名字要和这个相同
    state MASTER                #主状态为MASTER(必须大写),备节点为BACKUP
    interface eth2                  #通信接口网卡
    virtual_router_id 51         #实例ID为51,keepalived.conf里唯一
    priority 150                      #优先级为150,数值越大,优先级越高,与BACKUP对比
    advert_int 1                     #通信检查间隔为1秒
    authentication {
        auth_type PASS         #PASS认证类型
        auth_pass 2222          #密码为2222
    }
    virtual_ipaddress {
        10.3.151.228/24 dev eth2 label eth2:1     #虚拟IP地址
    }
}

3.3、备节点配置文件

! Configuration File for keepalived

global_defs {
   notification_email {
   345619885@qq.com
}
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth2
    virtual_router_id 51
    priority 140
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        10.3.151.228/24 dev eth2 label eth2:1
    }
}

4、检查keepalived是否生效

[root@yewu-app1 nginx]# ifconfig | grep "inet addr"
          inet addr:10.3.151.183  Bcast:10.3.151.255  Mask:255.255.255.0
          inet addr:10.3.151.228  Bcast:0.0.0.0  Mask:255.255.255.0   
                    #在主节点,检查VIP是否生效
          inet addr:127.0.0.1  Mask:255.0.0.0
[root@yewu-app1 nginx]# /etc/init.d/keepalived stop      #停止主节点的keepalived
Stopping keepalived: [  OK  ]
[root@yewu-app1 nginx]# ifconfig | grep "inet addr"        #VIP已飘走
          inet addr:10.3.151.183  Bcast:10.3.151.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
[root@yewu-app2 nginx]# ifconfig | grep "inet addr"       #在备节点上查看VIP是否存在
          inet addr:10.3.151.184  Bcast:10.3.151.255  Mask:255.255.255.0
          inet addr:10.3.151.228  Bcast:0.0.0.0  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0

NGINX Keepalived高可用简单使用 之十

标签:5.0   生效   发送   对比   角色   interface   install   server   ipa   

原文地址:http://blog.51cto.com/12965094/2146956

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!