lvs健康检查,更新策略(ldirectord)

lvs健康检查,更新策略(ldirectord)
2018年06月20日 23:39:34
阅读数:5

当lvs负载均衡中,有一台rs不能使用时,访问vip,还会去访问down掉的这台rs,并返回一个错误的页面。这种情况是不合理的,所以我们需要一个lvs的健康检查,更新策略ldirectord

[root@foundation77 ~]# curl 172.25.254.100
curl: (7) Failed connect to 172.25.254.100:80; Connection refused
[root@foundation77 ~]# curl 172.25.254.100

server2

[root@foundation77 ~]# curl 172.25.254.100
curl: (7) Failed connect to 172.25.254.100:80; Connection refused
[root@foundation77 ~]# curl 172.25.254.100

server2

1
2
3
4
5
6
7
8

一、ldirectord
server1(vs)
1、下载并安装ldirectord

[root@server1 ~]# ls
ldirectord-3.9.5-3.1.x86_64.rpm
[root@server1 ~]# yum install ldirectord-3.9.5-3.1.x86_64.rpm

1
2
3

2、ldirectord配置

1、设置配置文件

[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
[root@server1 ~]# cd /etc/ha.d/
[root@server1 ha.d]# ld
ld: no input files
[root@server1 ha.d]# ls
resource.d shellfuncs
[root@server1 ha.d]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf . #将正确的配置文件复制到当前目录
[root@server1 ha.d]# ls
ldirectord.cf resource.d shellfuncs
[root@server1 ha.d]# vim ldirectord.cf ##修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

这里写图片描述

Sample for an http virtual service

virtual=172.25.254.100:80
real=172.25.254.2:80 gate
real=172.25.254.3:80 gate
fallback=127.0.0.1:80 gate ##server2、3服务down后,访问本机80端口
service=http
scheduler=rr ##调度模式:轮询
#persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80 ##端口
request=”index.html” ##文件

receive=”Test Page”

virtualhost=www.x.y.z

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

[root@server1 ha.d]# /etc/init.d/ldirectord start ##运行
Starting ldirectord… success
[root@server1 ha.d]# ipvsadm -C ##清除规则
[root@server1 ha.d]# vim /var/www/html/index.html
[root@server1 ha.d]# cat /var/www/html/index.html

此网站正在维护中。。。。。

[root@server1 ha.d]# /etc/init.d/httpd start
Starting httpd:
[root@server1 ha.d]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 172.25.254.1 for ServerName
[ OK ]
[root@server1 ha.d]# /etc/init.d/ldirectord restart
Restarting ldirectord… success
[root@server1 ha.d]# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.254.100:http rr
-> server2:http Route 1 0 0
-> server3:http Route 1 0 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

server2和server3(RS)

配置文件和lvs相同
测试:

当server2出问题server3正常后,访问
这里写图片描述
当server3出问题,server2正常时:
这里写图片描述
当server2和server3同时出问题:
则访问本机:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值