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

keepalived 非抢占模式

时间:2019-06-10 15:55:01      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:head   ons   out   实现   root   table   ram   cat   节点   

keepalived 非抢占模式

抢占模式为当keepalived的某台机器挂了之后VIP漂移到了备节点,当主节点恢复后主动将VIP再次抢回,keepalived默认工作在抢占模式下,而非抢占模式则是当主节挂了再次起来后不再抢回VIP。此处需要注意非抢占模式的keepalived其工作机制必须都为BACKUP,并且开启nopreempt选项.

实现keepalived 非抢占模式

准备主机2台

server host ip
keepalived s1 172.20.27.10
keepalived s2 172.20.27.11

s1节点配置

修改配置文件

[root@s1 ~]# vim /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
        root@mylinuxops.com
   }
   notification_email_from root@mylinuxops.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id s1.mylinuxops.com
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_iptables
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 27
    priority 100
    advert_int 2
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.27.100 dev ens33 label ens33:0
    }
}

重启服务

[root@s1 ~]# systemctl restart keepalived

s2 节点操作

修改配置文件

[root@s2 ~]# vim /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
        root@mylinuxops.com
   }
   notification_email_from root@mylinuxops.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id s2.mylinuxops.com
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_iptables
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 27
    priority 80
    advert_int 2
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.20.27.100 dev ens33 label ens33:0
    }

重启服务

[root@s2 ~]# systemctl restart keepalived

测试

查看当前vip所在位置

[root@s1 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.10  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::20c:29ff:fec5:123c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c5:12:3c  txqueuelen 1000  (Ethernet)
        RX packets 71851  bytes 5769380 (5.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30175  bytes 7417306 (7.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.100  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 00:0c:29:c5:12:3c  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 140 (140.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 140 (140.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

当前VIP在s1节点上,当s1节点挂了之后再次查看

[root@s1 ~]# systemctl stop keepalived

VIP已经迁移至s2节点

[root@s2 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.11  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::20c:29ff:fe4d:1ce3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4d:1c:e3  txqueuelen 1000  (Ethernet)
        RX packets 61298  bytes 5145141 (4.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 793  bytes 69325 (67.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.100  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 00:0c:29:4d:1c:e3  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 6  bytes 482 (482.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6  bytes 482 (482.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此时再次启动s1节点查看vip是否抢回

[root@s1 ~]# systemctl start keepalived
[root@s1 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.10  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::20c:29ff:fec5:123c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c5:12:3c  txqueuelen 1000  (Ethernet)
        RX packets 76211  bytes 6139923 (5.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30392  bytes 7436214 (7.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 140 (140.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 140 (140.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
#没有VIP

查看s2节点

[root@s2 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.11  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::20c:29ff:fe4d:1ce3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4d:1c:e3  txqueuelen 1000  (Ethernet)
        RX packets 63311  bytes 5316040 (5.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 877  bytes 75815 (74.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.27.100  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 00:0c:29:4d:1c:e3  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 6  bytes 482 (482.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6  bytes 482 (482.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vip依旧在s2节点上。

keepalived 非抢占模式

标签:head   ons   out   实现   root   table   ram   cat   节点   

原文地址:https://blog.51cto.com/11886307/2406620

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