keepalived 非抢占模式

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节点配置

修改配置文件

[[email protected] ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   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
    }
}

重启服务

[[email protected] ~]# systemctl restart keepalived

s2 节点操作

修改配置文件

[[email protected] ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   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
    }

重启服务

[[email protected] ~]# systemctl restart keepalived

测试

查看当前vip所在位置

[[email protected] ~]# 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节点挂了之后再次查看

[[email protected] ~]# systemctl stop keepalived

VIP已经迁移至s2节点

[[email protected] ~]# 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是否抢回

[[email protected] ~]# systemctl start keepalived
[[email protected] ~]# 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节点

[[email protected] ~]# 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节点上。

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

时间: 2024-10-14 05:17:37

keepalived 非抢占模式的相关文章

keepalived 非抢占模式 以及nginx状态监控

global_defs {    notification_email {      [email protected]      [email protected]      [email protected]    }    notification_email_from [email protected]    smtp_server 192.168.200.1    smtp_connect_timeout 30    router_id f6    vrrp_mcast_group4 

haproxy高可用之非抢占keepalived(二)

1.安装keepalived yum install keepalived 2.编辑配置文件 /etc/keepalived/keepalived.conf 主: global_defs {     notification_email {         [email protected]  #可以添加多个邮箱接收报警     }     notification_email_from [email protected]     smtp_server smtp.qiye.163.com   

抢占式内核与非抢占式内核中的自旋锁(spinlock)的区别

一.概括 (1)自旋锁适用于SMP系统,UP系统用spinlock是作死. (2)保护模式下禁止内核抢占的方法:1.执行终端服务例程时2.执行软中断和tasklet时3.设置本地CPU计数器preempt_count (3)自旋锁的忙等待的实际意义是:尝试获取自旋锁的另一个进程不断尝试获取被占用的自旋锁,中间只pause一下! (4)在抢占式内核的spin_lock宏中,第一次关抢占,目的是防止死锁(防止一个已经获取自旋锁而未释放的进程被抢占!!).而后又开抢占,目的是让已经释放自旋锁的进程可以

测试keepalived备备模式的主从切换过程

继续上次"测试keepalived备备模式"的配置后,测试运行状态中主从的切换过程 主要是分析优先级的改变过程.(目前的分析不一定正确,且可能片面,后续会更新,仅供参考) 优先级priority用P来代替 1.首先: Pa = 85 Pb = 75 此时 Pa > Pb 主 = Pa 从 = Pb weight = -20 检测脚本(retval)返回0,表示成功,其他(例如1),则表示失败 weight>0时, retval=0,则P = P + weight retva

非阻塞模式(ioctlsocket)

1 //Server.cpp 2 #include <stdio.h> 3 #include <winsock2.h> //winsock.h (2种套接字版本) 4 #pragma comment(lib,"ws2_32.lib") //wsock32.lib 5 6 #define MAXSIZE 100 // 7 8 int main() 9 { 10 // 11 int retVal; 12 13 char buf[MAXSIZE]; 14 15 //初

oracle archivelog模式与非archivelog模式转换

最近集成环境出现归档日志写满后,数据库无法登录情况,询问DBA后查明情况,私下根据DBA的查找方案,拿开发环境做了一下数据库模式的切换,以便做同步监控分析问题,这里给出了数据路 首先使用dba登录,链接到数据库之后使用 sqlplus / as sysdba; archive log list 查看当前数据库归档模式,确实为归档或非归档模式之后.使用 shutdwon immediate 将数据库关闭,然后使用 startup mount 命令将数据开启处于mount状态使用 1 alter d

黄聪:如何用代码设置控制自己网站的网页在360浏览器打开时强制优先使用极速模式,而非兼容模式

最近用360浏览器访问自己的网站,发现都是被优先选用兼容模式打开,这使得网站很难看.为了让360浏览器打开网站的时候优先试用极速模式,找了一下官方论坛,发现了解决方案. 在head标签中添加一行代码: <html> <head> <meta name="renderer" content="webkit|ie-comp|ie-stand"> </head> <body> </body> <

oracle非归档模式下的冷备份和恢复

查看归档的相关信息 SQL> archive log list数据库日志模式             非存档模式自动存档             禁用存档终点            USE_DB_RECOVERY_FILE_DEST最早的联机日志序列     72当前日志序列           74 备份中常用的术语解释: 冷备份(脱机备份): 数据库处于关闭状态下所做的物理拷贝.数据库处于非归档模式下只能使用这种方法备份. 数据库全备份:备份所有数据文件和控制文件,在全备份时,数据库可以处在

正则表达式中的贪婪模式与非贪婪模式详解

1 概述 贪婪与非贪婪模式影响的是被量词修饰的子表达式的匹配行为,贪婪模式在整个表达式匹配成功的前提下,尽可能多的匹配,而非贪婪模式在整个表达式匹配成功的前提下,尽可能少的匹配.非贪婪模式只被部分NFA引擎所支持. 属于贪婪模式的量词,也叫做匹配优先量词,包括: “{m,n}”.“{m,}”.“?”.“*”和“+”. 在一些使用NFA引擎的语言中,在匹配优先量词后加上“?”,即变成属于非贪婪模式的量词,也叫做忽略优先量词,包括: “{m,n}?”.“{m,}?”.“??”.“*?”和“+?”.