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

keepalived-单主机模式

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

keepalived-单主机模式:

  说明:仅演示VIP地址流动

  工作模式:主备模式-单虚拟路由

拓扑:

 

 

 环境说明:

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

2、配置一个单主虚拟路由器,实现一个vrrp实例

 

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

1、ka1 keepalived配置:

[root@lvs-ka1 keepalived]# yum install -y keepalived             #centos6.4 + base源
[root@lvs-ka1 keepalived]# cat /etc/keepalived/keepalived.conf 
[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                                         #依赖本机的postfix提供的邮箱服务
   smtp_connect_timeout 30                                       #服务器连接超时时间
   router_id ka1                                                 #本地主机名标识
   vrrp_mcast_group4 224.100.100.100                             #ipv4组播地址,宣告优先级

vrrp_instance VI_1 {                                             #虚拟路由器实例
    state MASTER                                                 #主
    interface ens33                                              #绑定为当前虚拟路由使用的物理接口
    virtual_router_id 66                                         #当前虚拟路由器唯一标识:0-255
    priority 100                                                 #作为master的优先级
    advert_int 1                                                 #vrrp通告的时间间隔,1s
    authentication {                                             #同一个虚拟路由器成员间的认证
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {                                          #VIP设置
        172.16.0.100/24 dev ens33 label ens33:1                  #VIP绑定接口
    }
}
[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-ka1 keepalived]# yum install -y keepalived             #centos6.4 + base源
[root@lvs-ka1 keepalived]# cat /etc/keepalived/keepalived.conf 
[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                                         #依赖本机的postfix提供的邮箱服务
   smtp_connect_timeout 30                                       #服务器连接超时时间
   router_id ka1                                                 #本地主机名标识
   vrrp_mcast_group4 224.100.100.100                             #ipv4组播地址,宣告优先级

vrrp_instance VI_1 {                                             #虚拟路由器实例
    state BACKUP                                                 #从
interface ens33 #绑定为当前虚拟路由使用的物理接口 virtual_router_id 66 #当前虚拟路由器唯一标识:0-255 priority 80 #作为backup优先级 advert_int 1 #vrrp通告的时间间隔,1s authentication { #同一个虚拟路由器成员间的认证 auth_type PASS auth_pass 123456 } virtual_ipaddress { #VIP设置 172.16.0.100/24 dev ens33 label ens33:1 #VIP绑定接口 } } [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.125

 

3、验证:观察VIP的漂移

先启动ka2 keepalived服务:

     ka2是BACKUP角色,此时VIP绑定在ka2的ens33端口

[root@lvs-ka2 keepalived]# systemctl start keepalived
[root@lvs-ka2 keepalived]# 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: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.100/24 scope global ens33:1
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe34:710/64 scope link 
       valid_lft forever preferred_lft forever

[root@lvs-ka2 keepalived]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.122      0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
172.16.0.0      0.0.0.0         255.255.255.0   U     0      0        0 ens33

[root@rs2 ~]# tcpdump -i ens33 -nn host 224.100.100.100                            #vrrp宣告
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
21:24:04.205830 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:24:05.210191 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:24:06.211423 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:24:07.215022 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20

再启动ka1 keepalived服务:

  ka1是MASTER角色,默认抢占式,优先级比BACKUP角色高,VIP飘逸到ka1的ens33端口

[root@lvs-ka1 keepalived]# 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
    inet6 fe80::250:56ff:fe31:8a01/64 scope link 
       valid_lft forever preferred_lft forever

[root@lvs-ka1 keepalived]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.122      0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
172.16.0.0      0.0.0.0         255.255.255.0   U     0      0        0 ens33
[root@rs2 ~]# tcpdump -i ens33 -nn host 224.100.100.100                            #vrrp宣告
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
21:27:51.604517 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:27:52.607219 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:27:53.608804 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:27:54.609974 IP 10.0.0.126 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 90, authtype simple, intvl 1s, length 20
21:27:54.610469 IP 10.0.0.125 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 100, authtype simple, intvl 1s, length 20
21:27:55.620706 IP 10.0.0.125 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 100, authtype simple, intvl 1s, length 20
21:27:56.632074 IP 10.0.0.125 > 224.100.100.100: VRRPv2, Advertisement, vrid 66, prio 100, authtype simple, intvl 1s, length 20
[root@lvs-ka2 keepalived]# 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: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
    inet6 fe80::250:56ff:fe34:710/64 scope link 
       valid_lft forever preferred_lft forever

 

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

相关文章

  • 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处理单元只负责监听文件描述符上是否有事件发生,有则立刻将该事件通知给工作线程即逻辑单元,除此之外,主线程不做任何其它实质性的动作。读写数据,接受新的连接,以及处理客户请求均在工作线程中完......
  • 单例模式 lock 多线程 双重检查锁定机制
    单例模式单例模式publicclassSingleton{//定义一个静态变量来保存类的实例privatestaticSingletonuniqueInstance;//定义一个标识确保线程同步privatestaticreadonlyobjectlocker=newobject();//定义私有构造函数,使外界不能创建该类......