首页 > 其他分享 >keepalived-双主机模式

keepalived-双主机模式

时间:2024-08-29 08:54:26浏览次数:12  
标签:00 lvs 主机 keepalived forever 模式 lft ens33

keepalived-双主机模式:

  说明:仅演示VIP地址流动

  工作模式:主主模式-主/备(虚拟路由器1) 备/主(虚拟路由器2)

拓扑:

 

环境说明:

1、ka1和ka2分别是2台keepalived服务器

2、配置一个2主虚拟路由器,实现两个vrrp实例,互为主备

 

示例:双主机模式实现VIP地址流动

1、ka1 keepalived配置:

[root@lvs-ka1 keepalived]# yum install -y keepalived
[root@lvs-ka1 keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1
   vrrp_mcast_group4 224.100.100.100 
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 66
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        172.16.0.100/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 88
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 654321
    }
    virtual_ipaddress {
        172.16.0.200/24 dev ens33 label ens33:2
    }
}
[root@lvs-ka1 ~]# cat /etc/hosts
10.0.0.125 ka1
10.0.0.126 ka2
[root@lvs-ka1 ~]# ssh-keygen
[root@lvs-ka1 ~]# ssh-copy-id 10.0.0.126

 

2、ka2 keepalived配置:

[root@lvs-ka2 keepalived]# yum install -y keepalived
[root@lvs-ka2 keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1
   vrrp_mcast_group4 224.100.100.100 
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 66
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        172.16.0.100/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 88
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 654321
    }
    virtual_ipaddress {
        172.16.0.200/24 dev ens33 label ens33:2
    }
}
[root@lvs-ka2 ~]# cat /etc/hosts
10.0.0.125 ka1
10.0.0.126 ka2
[root@lvs-ka2 ~]# ssh-keygen
[root@lvs-ka2 ~]# ssh-copy-id 10.0.0.125

 

3、验证:观察VIP的漂移

先启动ka1 keepalived服务:

  此时ka1是VI_1实例的MASTER角色,VI_2实例的BACKUP角色,2个VIP都在ens33端口

[root@lvs-ka1 ~]# systemctl start keepalived
[root@lvs-ka1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 172.16.0.100/24 scope global ens33:1
       valid_lft forever preferred_lft forever
    inet 172.16.0.200/24 scope global secondary ens33:2
       valid_lft forever preferred_lft forever

 

再启动ka2 keepalived服务:

   此时ka2是VI_1实例的BACKUP角色,VI_2实例的MASTER角色,默认抢占模式,ka2从ka1把VI_2实例的VIP抢占过来,绑定到自己ens33端口

[root@lvs-ka2 ~]# systemctl start keepalived
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 172.16.0.200/24 scope global ens33:2
       valid_lft forever preferred_lft forever

[root@lvs-ka1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 172.16.0.100/24 scope global ens33:1
       valid_lft forever preferred_lft forever

 

keepalived vrrp组播宣告情况:

[root@rs2 ~]# tcpdump -i ens33 -nn host 224.100.100.100
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
17:01:51.678446 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 88, prio 100, authtype simple, intvl 1s, length 20
17:01:51.949584 IP 10.0.0.125 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 100, authtype simple, intvl 1s, length 20
17:01:52.680117 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 88, prio 100, authtype simple, intvl 1s, length 20
17:01:52.950496 IP 10.0.0.125 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 100, authtype simple, intvl 1s, length 20

 

标签:00,lvs,主机,keepalived,forever,模式,lft,ens33
From: https://www.cnblogs.com/cnblogsfc/p/14269161.html

相关文章

  • keepalived-单主机模式
    keepalived-单主机模式:说明:仅演示VIP地址流动工作模式:主备模式-单虚拟路由拓扑:   环境说明:1、ka1和ka2分别是2台keepalived服务器2、配置一个单主虚拟路由器,实现一个vrrp实例 示例:单主机模式实现VIP地址流动1、ka1keepalived配置:[root@lvs-ka1keepali......
  • keepalived-状态邮件通知和定向日志输出
    keepalived-状态邮件通知和定向日志输出说明1:当keepalived实例角色切换时,根据自定义邮件脚本,推送本地邮件通知说明2:当keepalived实例角色切换时,根据自定义邮件脚本,推送互联网邮件通知说明3:默认keepalive状态日志写入/var/log/messages文件拓扑: 环境说明:......
  • 直连QEMU虚拟机之网络模式
    要直接连接到QEMU虚拟机,而不通过端口转发的方式,可以采用桥接网络(BridgedNetworking)或创建一个虚拟网络接口卡(TAP)的方式,让虚拟机与宿主机处于同一网络中。这样,虚拟机可以直接获得一个与宿主机相同网段的IP地址,从而使得宿主机可以直接连接到虚拟机。以下是详细的操作步骤:方......
  • keepalived-lvs-DR
    keepalived实现lvs高可用说明:lvs单实例拓扑: 环境说明:1、client网关指向Router,跨网段访问lvs-VIP,需要指定正确网关和路由,如果client和Route之间还有其他路由或防火墙设备,网关设置直连路由IP2、虚拟机模拟路由器,Router需要开启路由转发ip_forward3、实验环境模拟路由器......
  • keepalived简介
    一、keepalived概述官方网站:https://www.keepalived.org/keepalived:vrrp协议:virtualrouterredundancyprotocolvrrp是一种容错协议,它保证当lvs调度器MASTER出现故障时,由另一台lvs调度器BACKUP来代替出现故障的lvs调度器进行工作,从而保持提供服务的连续性和可靠性......
  • 【设计模式】单例模式(线程安全)
     ......
  • Android 常用的性能分析工具详解:GPU呈现模式
    此篇将重点介绍几种常用的Android性能分析工具:一、Logcat日志选取Tag=ActivityManager,可以粗略地知道界面Displaying的时间消耗。当我们打开一个Activity的时候,log会打印一串log如下:I/ActivityManager﹕Displayedxxx.xxx.xxx/TestActivity:+1s272ms(total+3s843ms)第一......
  • 命令模式与事件驱动编程:如何将两者结合以优化系统设计
    引言在现代软件系统设计中,命令模式(CommandPattern)与事件驱动编程(Event-DrivenProgramming)是两种常见的设计范式。它们分别解决了不同的设计问题,然而在实际开发中,如何将两者结合以优化系统设计,是一个值得深入探讨的话题。本文将详细介绍命令模式与事件驱动编程的基本概念......
  • 命令模式的实际应用案例:从电梯控制系统到文本编辑器
    命令模式的实际应用案例:从电梯控制系统到文本编辑器引言设计模式是软件工程中解决特定问题的经典方案,它们提供了灵活、可扩展的代码结构,能够在应对复杂系统设计时发挥重要作用。命令模式(CommandPattern)作为行为型设计模式之一,通过将请求封装为对象,使得请求的调用者与执行......
  • 【Linux网络编程】Reactor模式与Proactor模式
    【Linux网络编程】Reactor模式与Proactor模式Reactor模式Reactor模式是指主线程即IO处理单元只负责监听文件描述符上是否有事件发生,有则立刻将该事件通知给工作线程即逻辑单元,除此之外,主线程不做任何其它实质性的动作。读写数据,接受新的连接,以及处理客户请求均在工作线程中完......