lvs+keepalived高可用集群

本文详细介绍了如何搭建LVS-DR模式的负载均衡集群,包括配置keepalived实现虚拟IP的动态分配,以及通过elinks进行测试验证。文章提供了具体的配置步骤和命令,展示了在主备模式下,当主分发器停止工作时,服务如何无缝切换到备用分发器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备两台web服务器50 & 60,两台分发器80 & 90,测试机10

先搭建好lvs-dr 模式集群( https://blog.youkuaiyun.com/weixin_42182501/article/details/85109723)

这里要注意的是80和90两台机子上不需要绑定虚拟IP,只需要安装keepalived,由keepalived来分配虚拟IP.

两台都装好keepalived,关闭firewalld和selinux.

[root@lvs90 ~]# yum -y install keepalived

在80上打开keepalived配置文件,将内容修改成如下:

[root@lvs80 ~]# vim /etc/keepalived/keepalived.conf

  1 ! Configuration File for keepalived
  2 
  3 global_defs {
  4    notification_email {
  5      acassen@firewall.loc
  6      failover@firewall.loc
  7      sysadmin@firewall.loc
  8    }
  9    notification_email_from Alexandre.Cassen@firewall.loc
 10    smtp_server 192.168.200.1
 11    smtp_connect_timeout 30
 12    router_id LVS_DEVEL
 13 }
 14 
 15 vrrp_instance lvsha {
 16     state MASTER
 17     interface eth0
 18     virtual_router_id 51
 19     priority 150
 20     advert_int 1
 21     authentication {
 22         auth_type PASS
 23         auth_pass 1111
 24     }
 25     virtual_ipaddress {
 26         192.168.4.200
 27     }
 28 }
 29 
 30 virtual_server 192.168.4.200 80 {
 31     delay_loop 6
 32     lb_algo rr
 33     lb_kind DR
 34     nat_mask 255.255.255.0
 35     #persistence_timeout 50
 36     protocol TCP
 37     connect_timeout 3
 38     nb_get_retry 3
 39     delay_before_retry 3
 40     real_server 192.168.4.50 80 {
 41         weight 1
 42     }
 43     real_server 192.168.4.60 80 {
 44         weight 1
 45     }
 46 }

90上也要同样的配置,但是90的配置有点区别,因为90是作为备份的分发器。

区别在于

16行的描叙要改成

 16     state BACKUP
19行的权重值要改成100

19     priority 100
 

接下来就是开启keepalived服务。

先启动80再启动90

[root@lvs80 ~]# systemctl start keepalived

[root@lvs90 ~]# systemctl start keepalived

[root@lvs80 ~]# ip addr show |grep 192.168.4.
    inet 192.168.4.80/24 brd 192.168.4.255 scope global eth0
    inet 192.168.4.200/32 scope global eth0
 

使用10测试

[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web60
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web60

关掉80上的keepalived,虚拟IP就自动转到90上了,分发服务并不会中断.

[root@lvs80 ~]# systemctl stop keepalived.service

[root@lvs90 ~]# ip addr show |grep 192.168.4
    inet 192.168.4.90/24 brd 192.168.4.255 scope global eth0
   

[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web50
[root@pc10 ~]# elinks --dump http://192.168.4.200/test.html
   web60
[root@pc10 ~]# 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值