ipvs+ldirectord实现高可用ipvs
一、heartbeat准备1、接上文HA集群准备工作
2、 安装heartbeat-ldirectord组件包
1
# yum localinstall heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
3、ldirectord组件简介
ldirectord依赖于自己的配置文件来生成ipvs的规则,因此,定义LVS集群、添加RS都是在ldirectord的配置文件中指定,而无需手动执行ipvsadm命令。ldirectord对LVS集群的director高可用,并对LVS进群的RS提供健康状态监测,若某节点出现故障,则会把它从集群系统中剔除,并在其回复正常后,将它重新加入集群系统。ldirectord还可以调用ipvsadm命令创建LVS路由表信息,只需要在/etc/ha.d/ldirectord.cf配置文件中指明即可。
4、基本信息
二、配置
RS:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
1、准备RS脚本
#!/bin/bash
vip=192.168.0.17
interface="lo:0"
case $1 in
start)
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
ifconfig $interface $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev $interface
;;
stop)
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_announce
ifconfig $interface down
;;
status)
if ifconfig lo:0 | grep $vip &> /dev/null; then
echo "ipvs is running."
else
echo "ipvs is stopped."
fi
;;
*)
echo "please input : `basename $0` {start|stop|status}"
exit 1
esac
# chmod +x rs.sh
2、准备httpd
# yum install httpd
# echo "This is RS" > /var/www/html/index.html
# service httpd start
# curl 192.168.0.20
This is RS
# ./rs.sh start
主备Director测试
1
2
3
4
# ifconfig eth0:0 192.168.0.17 broadcast 192.168.0.17 netmask 255.255.255.255 up
# route add -host 192.168.0.17 dev eth0:0
# ipvsadm -A -t 192.168.0.17:80 -s rr
# ipvsadm -a -t 192.168.0.17:80 -r 192.168.0.20 -g
1
2
3
# ipvsadm -C
# route del -host 192.168.0.17
# ifconfig eth0:0 down
主Director:node1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
1、cp样例配置文件
# cd /usr/share/doc/heartbeat-ldirectord-2.1.4/
# cp ldirectord.cf /etc/ha.d
# cd /etc/ha.d
2、配置文件
##全局配置
# Global Directives
##健康状态检测超时时间间隔
checktimeout=3
##每一秒检查一次
checkinterval=1
#fallback=127.0.0.1:80
##自动装载配置文件
autoreload=yes
##日志文件
logfile="/var/log/ldirectord.log"
##日志文件级别
#logfile="local0"
##邮件通知警告信息
#emailalert="admin@x.y.z"
##邮件通知间隔1小时
#emailalertfreq=3600
##邮件通知所有的状态信息
#emailalertstatus=all
##是否工作于静默模式
quiescent=yes
##虚拟服务配置
# Sample for an http virtual service
##VIP
virtual=192.168.0.17:80
##RS gate为dr类型
real=192.168.0.20:80 gate
#real=192.168.6.3:80 gate
#real=192.168.6.6:80 gate
##backserver
fallback=127.0.0.1:80 gate
##健康状态检查基于http协议
service=http
##请求的页面
request=".health.html"
##检查request=“”页面中的字符串是否一致
receive=""
##对多个虚拟主机进行检查
virtualhost=some.domain.com.au
##调度类型为rr
scheduler=rr
##持久连接时长
#persistent=600
##掩码
#netmask=255.255.255.255
##基于tcp的检查,集群服务类型
protocol=tcp
##检查类型为交互式检查
##checktype:connect是传输层检查,ping是网络层检查,negotlate是应用层检查
##当checktype=negotlate时,ldirectord将基于指定的协议与各RS建立连接,完成应用层检查
checktype=negotia
##检查端口为80
checkport=80
##请求的页面
request="index.html"
##请求的字符串检查
#receive="Test Page"
##对虚拟主机检查
#virtualhost=
3、准备web服务,node1作为back server提供sorry server服务
# vim /var/www/html/index.html
This is sorry server(node1)
# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.15 for ServerName
# curl 192.168.0.15
This is sorry server(node1)
4、将配置文件cp给node2
# scp ldirectord.cf node2:/etc/ha.d/
备Director:node2配置
1
2
3
4
5
6
7
# vim /var/www/html/index.html
This is sorry server(node2)
# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.16 for ServerName
# curl 192.168.0.16
This is sorry server(node2)
RS准备测试页
1
# echo "ok"> /var/www/html/.health.html
启动服务
1
# service heartbeat start; ssh node2 'service heartbeat start'
gui界面配置资源
1、定义资源组ipvs,定义集群ip资源(vip)
2、定义ipvs规则,lsb格式不提供参数,ocf格式的资源代理须提供配置文件
3、启动资源
4、验证node2节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP192.168.0.17:80 rr
-> 192.168.0.20:80 Route 1 0 0
# ip add show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:15:ea:32 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0
inet 192.168.0.17/24 brd 192.168.0.255 scope global secondary eth0
inet6 fe80::20c:29ff:fe15:ea32/64 scope link
valid_lft forever preferred_lft forever
5、验证负载均衡集群效果
6、检测RS下线,director错误页面
1
2
3
4
5
6
7
8
# mv /var/www/html/.health.html /var/www/html/a.html
# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP192.168.0.17:80 rr
-> 127.0.0.1:80 Local 1 0 0
-> 192.168.0.20:80 Route 0 0 0
同理检查node1。
页:
[1]