RHEL5/Cluster(TUN 部分)
RHEL5中的Cluster组件是基于章文嵩先生创立的LVS(Linux Virtual Server) 制作而成,
关于lvs的工作原理请参照《Linux 服务器集群系统》
Virtual Server via IP Tunneling(VS/TUN)
采 用NAT技术时,由于请求和响应报文都必须经过调度器地址重写,当客户请求越来越多时,调度器的处理能力将成为瓶颈。为了解决这个问题,调度器把请求报文 通过IP隧道转发至真实服务器,而真实服务器将响应直接返回给客户,所以调度器只处理请求报文。由于一般网络服务应答比请求报文大许多,采用VS/TUN 技术后,集群系统的最大吞吐量可以提高10倍。
Cluster(TUN部分)实验
TUN类型的httpd负载均衡集群.网络拓扑为
eth0 192.168.1.100 eth0 192.168.1.200
tunl0 10.0.0.50 tunl0 10.0.0.50
gw 192.168.1.10 gw 192.168.1.10
______________ ______________
| | | |
| realserver 1 | | realserver 2 |
|______________| |______________|
| |
|___________________|
|
eth0 192.168.1.10
________
| |
| gw |
|________|
eth1 10.0.0.10
|
|
|
VIP(eth0:1)=10.0.0.50
_ _ _ _ _
| |
director
|_ _ _ _ _ |
|
|
|
----------------------------------------
| | |
| | |
eth0 10.0.0.1 eth0 10.0.0.2 eth0 10.0.0.3
gw 10.0.0.10 gw 10.0.0.10 gw 10.0.0.10
______________ ______________ ______________
| | | | | |
| router | | router backup| | clinet |
|______________| |______________| |______________|
[client]
os:windwows xp
[gw]
os:rhel5
hostname:gw
[router/router backup]
os:rhel5
hostname:vs/vs_bk
software: ipvsadm piranha httpd php
[realserver1/realserver2]
os:rhel5
hostname:rs1/rs2
software:httpd
[director]
为router或者router backup中的一台虚拟出来
配置如下
[gw]
#打开路由转发
[root@gw ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[router]
#设置piranha密码
piranha-passwd
#开启服务
service piranha-gui start
#访问配置页面
http://10.0.0.1:3636/
#配置以后的文件
[root@vs ~]# cat /etc/sysconfig/ha/lvs.cf
serial_no = 53
primary = 10.0.0.1
service = lvs
backup_active = 1
backup = 10.0.0.2
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = tunnel
nat_nmask = 255.255.255.0
debug_level = NONE
monitor_links = 0
virtual HTTP {
active = 1
address = 10.0.0.50 eth0:1
vip_nmask = 255.255.0.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wlc
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server rs1.yubo.com {
address = 192.168.1.100
active = 1
weight = 1
}
server rs2.yubo.com {
address = 192.168.1.200
active = 1
weight = 1
}
}
#重启服务
service pulse restart
[router backup]
#设置piranha密码
piranha-passwd
#开启服务
service piranha-gui start
#访问配置页面
http://10.0.0.2:3636/
#配置以后的文件
[root@vs_bk ~]# cat /etc/sysconfig/ha/lvs.cf
serial_no = 48
primary = 10.0.0.2
service = lvs
backup_active = 1
backup = 10.0.0.1
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = tunnel
nat_nmask = 255.255.0.0
debug_level = NONE
monitor_links = 0
virtual HTTP {
active = 1
address = 10.0.0.50 eth0:1
vip_nmask = 255.255.0.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wlc
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server rs1.yubo.com {
address = 192.168.1.100
active = 1
weight = 1
}
server rs2.yubo.com {
address = 192.168.1.200
active = 1
weight = 1
}
}
#重启服务
service pulse restart
[realserver1/realserver2]
封装到达realserver的包,目的地址是vip的地址,而不是rs的ip地址,如果不做处理,会被拒绝,加上一个虚拟设备就解决问题了tunl0
ifconfig tunl0 10.0.0.50 netmask 255.255.255.255
之后开启rs1,rs2的httpd服务,为了使得便于观察
[root@rs1 ~]# echo "rs1.yubo.org" > /var/www/html/index.html
[root@rs2 ~]# echo "rs2.yubo.org" > /var/www/html/index.html
client频繁访问http://10.0.0.50时,会发现显示内容在”rs2.yubo.org”和”rs1.yubo.org”之间切换
试验完成以后,不要忘记保存配置,以免启动以后无法使用
[vs/vs_bk]
chkconfig --level 2345 piranha-gui on
chkconfig --level 2345 pulse on
[rs1/rs2]
echo "ifconfig tunl0 10.0.0.50 netmask 255.255.255.255" >> /etc/rc.local
[注意]
route 和 route backup 互为备份,没有主次之分(注意每个配置文件的backup和backup_private)
route backup 是route的备份
route 是route backup的备份
10.0.0.50个虚拟ip地址同一时刻只出现在1个router上,当前router当机以后,这个ip地址会被另一台备份机器接管
[其他]
[root@vs_bk ~]# ipvsadm --save -n
-A -t 10.0.0.50:80 -s wlc
-a -t 10.0.0.50:80 -r 192.168.1.200:80 -i -w 1
-a -t 10.0.0.50:80 -r 192.168.1.100:80 -i -w 1