LVS—使用DR模式+ldirectord实现自动检测服务器健康状态

本文详细介绍了如何在DR模式下配置服务器的健康监测,包括配置环境、安装软件ldirectord、设置高可用的软件包源、配置文件ldirectord.cf以及测试过程。当服务器正常或故障时,能实现轮循负载均衡及故障切换。

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

一、配置环境:

DR模式配置:配置教程

二、健康监测

如果一个服务器宕机,访问的链接将时好时坏,这时就需要对后端进行健康检查

1.server1:配置yum源,安装软件ldirectord

vim /etc/yum.repos.d/rhel-source.repo   ##添加高可用的软件包
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.60.250/iso/HighAvailability
enabled=1  
gpgcheck=0


yum clean all
yum repolist   
##此时有高可用的56个包,但是安装还需要依赖性,再额外下载一个安装包ldirectord-.9.5-3.1.x86_64.rpm

安装:

vim /var/www/html/index.html

系统维护中……

/etc/init.d/httpd restart

2.配置文件

rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf cd /etc/ha.d  
vim /etc/ha.d/ldirectord.cf
 24 # Sample for an http virtual service
 25 virtual=172.25.60.100:80
 26         real=172.25.60.2:80 gate
 27         real=172.25.60.3:80 gate
 28         fallback=127.0.0.1:80 gate
 29         service=http
 30         scheduler=rr
 31         #persistent=600
 32         #netmask=255.255.255.255
 33         protocol=tcp
 34         checktype=negotiate
 35         checkport=80
 36         request="index.html"
 37         #receive="Test Page"
 38         #virtualhost=www.x.y.z

/etc/init.d/ldirectord start

3.测试:

在物理机上:

两台真机都正常工作时,轮循

[root@foundation60 ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[root@foundation60 ~]# curl 172.25.60.100
<h1>server2,example.com</h1>
[root@foundation60 ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[root@foundation60 ~]# curl 172.25.60.100
<h1>server2,example.com</h1>

当其中一台宕机时,只显示正常真机的网页信息

[root@foundation60 ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[root@foundation60 ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[root@foundation60 ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[root@foundation60 ~]# 

当两台都宕机时,显示‘系统维护中……’:

[root@foundation60 ~]# curl 172.25.60.100
系统维护中……
[root@foundation60 ~]# curl 172.25.60.100
系统维护中……
[root@foundation60 ~]# curl 172.25.60.100
系统维护中……

健康检查实现!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马克图布s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值