nat模式
Director分发器配置
配置VIP
[root@tianyun ~]# ip addr add dev eth0 192.168.122.100/24
[root@tianyun ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@tianyun ~]# sysctl -p //确保打开路由转发
[root@tianyun ~]#ln -sv /usr/src/kernels/3.10..... /usr/src/linux
定义LVS分发策略
[root@tianyun ~]# yum -y install ipvsadm //RHEL确保LoadBalancer仓库可用
[root@tianyun ~]# ipvsadm -A -t 192.168.122.100:80 -s rr
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 10.10.10.10 -m //-m masquerading (NAT)
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 10.10.10.20 -m
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 10.10.10.30 -m
[root@tianyun ~]# service ipvsadm save
[root@tianyun ~]# ipvsadm -L
[root@tianyun ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.122.100:80 rr
-> 10.10.10.10:80 Masq 1 0 1
-> 10.10.10.20:80 Masq 1 0 1
-> 10.10.10.30:80 Masq 1 0 1
[root@tianyun ~]# ipvsadm -L -n --stats // 显示统计信息
[root@tianyun ~]# ipvsadm -L -n --rate //看速率
[root@tianyun ~]# ipvsadm -Ln -c //查看LVS的连接条目
[root@tianyun ~]# watch -n.5 'ipvsadm -Ln -c'
测试
[root@client ~]# elinks -dump http://192.168.122.100/
[root@client ~]# ab -c 1000 -n 1000 http://192.168.122.100/
总结
VS/NAT模式的原理是:当Director收到Client请求时,Director将数据包的目标IP由VIP转换为选中的Real Server的RIP来实现分发,
要求RS将网关指向Director的DIP。
特点是:配置简单,所有的入站、出站数据包都经过分发器。当数据量比较大时,分发器可能会出现网络瓶颈!因而支持的RS数量少。
Director必须开启kernel ip_forward
所有RealServer默认网关指向DIP
Director使用DIP和RealServer RIP通信
[root@director1 ~]# watch -n.5 'ipvsadm -Ln -c'
Every 0.5s: ipvsadm -Ln -c Tue Dec 29 06:41:15 2015
IPVS connection entries
pro expire state source virtual destination
TCP 00:32 SYN_RECV 192.168.122.1:55989 192.168.122.100:80 10.10.10.10:80
TCP 00:42 SYN_RECV 192.168.122.1:55991 192.168.122.100:80 10.10.10.20:80
TCP 00:41 SYN_RECV 192.168.122.1:55990 192.168.122.100:80 10.10.10.30:80
TCP 00:29 SYN_RECV 192.168.122.1:55988 192.168.122.100:80 10.10.10.20:80
TCP 00:59 SYN_RECV 192.168.122.1:55993 192.168.122.100:80 10.10.10.30:80
TCP 00:42 SYN_RECV 192.168.122.1:55992 192.168.122.100:80 10.10.10.10:80
LVS/DR
RS
[root@tianyun ~]# yum -y install httpd
[root@tianyun ~]# ip addr add dev lo 192.168.122.100/32 //在lo接口上绑定VIP
[root@tianyun ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore //non-arp
[root@tianyun ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
Director
配置VIP
[root@tianyun ~]# ip addr add dev eth0 192.168.122.100/32 //配置VIP
[root@tianyun ~]# yum -y install ipvsadm //RHEL确保LoadBalancer仓库可用
LVS分发策略
[root@tianyun ~]# ipvsadm -C // 清除内核虚拟服务器表中的所有记录
[root@tianyun ~]# ipvsadm -A -t 192.168.122.100:80 -s rr
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 192.168.122.10 -g
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 192.168.122.20 -g
[root@tianyun ~]# ipvsadm -a -t 192.168.122.100:80 -r 192.168.122.30 -g
[root@tianyun ~]# service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
[root@tianyun ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.122.100:80 rr
-> 192.168.122.10:80 Route 1 0 0
-> 192.168.122.20:80 Route 1 0 0
-> 192.168.122.30:80 Route 1 0 0
[root@tianyun ~]# ipvsadm -L -n
[root@tianyun ~]# ipvsadm -L -n --stats // 显示统计信息
[root@tianyun ~]# ipvsadm -L -n --rate //看速率
[root@tianyun ~]# ipvsadm -Ln -c //查看LVS的连接条目
[root@tianyun ~]# watch -n.5 'ipvsadm -Ln -c'
测试
[root@client ~]# elinks -dump http://192.168.122.100
[root@client ~]# ab -c 1000 -n 1000 http://192.168.122.100/
[root@client ~]# tcpdump -nni eth0 -e host 192.168.122.100
总结
VS/DR模式的原理是: 当一个client发送一个请求到VIP,Di据VIP选rector根择对应的real-server的Pool,根据算法,在Pool中选择一台Real-server,然后将client的求包请发给选择的Real-server,最后选择的Real-server把应答包直接传给client,client接收到应答包之后建立连接形成一个请求应答过程。