LVS模式一:DR模式下LVS的健康检查(ldirectord)

为什么需要健康检查?

  • 如果后端真实服务器出现问题,那么在测试端测试的时候,会返回给我们一个错误的页面,那么我们需要对后端服务器做健康检查,保证只返回正确的页面提供给用户。

主机环境:

主机名IP
server1172.25.64.1
server2172.25.64.2
server3172.25.64.3
  • rhel6.5 selinux and iptables disabled
  • Load Balance: 172.25.64.1(server1)
  • Virtual IP:172.25.64.100
  • RealRerver1:172.25.64.2 (server2)
  • RealRerver2:172.25.64.3(server3)
  • 物理机内网 : 172.25.64.250
  • server2
    1.安装apache
[root@server2 ~]# yum install httpd -y
  1. 编写前端文件
[root@server2 ~]# cd /var/www/html
[root@server2 html]# vim index.html
<h1>www.westos.org - server2</h1>
  • server3:同上
[root@server3 ~]# cd /var/www/html
[root@server3 html]# vim index.html
<h1>www.westos.org - server3</h1>

实现健康检查的配置步骤:

  1. 安装软件ldirectord-3.9.5-3.1.x86_64.rpm用来对后端服务器做健康检查
[root@server1 ~]# yum install -y ldirectord-3.9.5-3.1.x86_64.rpm

##查看配置文件
[root@server1 ~]# rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
warning: ldirectord-3.9.5-3.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 7b709911: NOKEY
/etc/ha.d
/etc/ha.d/resource.d
/etc/ha.d/resource.d/ldirectord
/etc/init.d/ldirectord
/etc/logrotate.d/ldirectord
/usr/lib/ocf/resource.d/heartbeat/ldirectord
/usr/sbin/ldirectord
/usr/share/doc/ldirectord-3.9.5
/usr/share/doc/ldirectord-3.9.5/COPYING
/usr/share/doc/ldirectord-3.9.5/ldirectord.cf
/usr/share/man/man8/ldirectord.8.gz
  1. 配置文件的母板拷到/etc/ha.d/
[root@server1 ~]# cd /etc/ha.d/ 
[root@server1 ha.d]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf . 
[root@server1 ha.d]# ls
ldirectord.cf  resource.d  shellfuncs
  1. 编辑 ldirectord的配置文件
[root@server1 ha.d]# vim ldirectord.cf 
# Global Directives                 #“ 全局 ” 设置
checktimeout=3                      #指定定real server出错的时间间隔
checkinterval=1                     #指定ldirectord在两次检查之间的时间间隔
autoreload=yes                      #自动重载配置文件,选yes时,当配置文件发生变化,自动载入配置信息
quiescent=no                        
#当一个节点在 checktimeout 设置的时间周期内没有响应是它是 “ 静止的  (它的权重为0),当你设置了这个选项后,ldirectord 将 会从 IPVS 表中移除真实服务器而不是 “ 停止 ” 它,IPVS 表移除节点将中断现有的客户端连接,并使 LVS 丢掉所有的连接跟踪记录和持续连接模板,如果 你不将这个选项设置为 no,当某个节点崩溃时,对某些客户端计算机而言可能会显示为集群关闭了,因为在这个节点崩溃前这些客户端计算机被分配给它了,而连接跟踪记录和程序连接模板仍然保留在Director上。
logfile="/var/log/ldirectord.log"   #设定ldirectord日志输出文件路径
# Sample for an http virtual service
virtual=172.25.64.100:80              #VIP 地址和端口号
        real=172.25.64.2:80 gate      #指定RealServer地址和端口,同时设定LVS工作模式,gate表示DR模式,ipip表示TUNL模式,masq表示NAT模式。
        real=172.25.64.3:80 gate      #当所有的real server节点不能工作时,web服务重定向的地址
        fallback=127.0.0.1:80 gate     #当所有的real server节点不能工作时,web服务重定向的地址
        service=http            #指定服务类型,对http服务做负载均衡
        scheduler=rr           #指定调度算法,这里是rr(轮叫)算法
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp                       #指出该服务使用的协议:tcp、udp 或 fwm
        checktype=negotiate                 #指定Ldirectord的检测类型,默认为negotiate
        checkport=80                       #健康检查使用的端口是 80
        request="index.html"
        #receive="Test Page"              #指定请求和应答字串
        #virtualhost=www.x.y.z            #虚拟服务器的名称

##开启服务
[root@server1 ha.d]# /etc/init.d/ldirectord start
Starting ldirectord... success

4.物理机 测试:

  • 后端真实服务器都正常时(RealServer 无宕机 ):实行轮叫
    在这里插入图片描述
  • 将server3关掉(RealServer 有一台宕机)
 [root@server3 html]# /etc/init.d/httpd stop

则显示只调度server2服务器
在这里插入图片描述

  • RealServer 全部宕机
  1. 将server2,和server3的httpd服务都关掉
[root@server2 html]# /etc/init.d/httpd stop
[root@server3 html]# /etc/init.d/httpd stop
  1. 在调度器server1上编写前端文件
[root@server1 html]# cd /var/www/html
[root@server1 html]# vim index.html
<h1>网站维护中..</h1>
  1. server1的httpd服务端口改成80
[root@server1 html]# vim /etc/httpd/conf/httpd.conf  
Listen 80
[root@server1 html]# /etc/init.d/httpd restart 
  1. 重启ldirectord 服务
[root@server1 ha.d]# /etc/init.d/ldirectord restart
Restarting ldirectord... success
  1. 物理机测试
    在这里插入图片描述
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值