LVS的NAT模式测试

dir 分别配置ip  eth0 :10.222.138.200   eth0:1 10.222.21.190 

rs1 eth0  :10.222.138.201

rs2 eth0: 10.222.138.202 

 

rs1 安装nginx , 显示 html 内容为  201  

rs2 安装nginx  显示 html 内容为 202

dir : yum install -y ipvsadm
 
[root@dir network-scripts]# vim /usr/local/sbin/lvs_nat.sh 

#! /bin/bash
# director
echo 1 > /proc/sys/net/ipv4/ip_forward
#关闭icmp的重定向
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
# echo 0 > /proc/sys/net/ipv4/conf/eth1/send_redirects

iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -s 10.222.138.0/24 -j MASQUERADE

IPVSADM='/sbin/ipvsadm'
$IPVSADM -C
$IPVSADM -A -t 10.222.21.190:80 -s wrr
$IPVSADM -a -t 10.222.21.190:80 -r 10.222.138.201:80 -m -w 2
$IPVSADM -a -t 10.222.21.190:80 -r 10.222.138.202:80 -m

 

sh /usr/local/sbin/lvs_nat.sh
执行脚本

[root@dir network-scripts]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.222.21.190:80 wrr
-> 10.222.138.201:80 Masq 2 0 0
-> 10.222.138.202:80 Masq 1 0 0

 

rs1,rs2 服务器
vim /etc/sysconfig/network-scripts/ifcfg-eth0
中设定网关为 10.222.138.200
 
dir服务器上

[root@dir network-scripts]# curl 10.222.21.190
202----------------------------
[root@dir network-scripts]# curl 10.222.21.190
201.....................
[root@dir network-scripts]# curl 10.222.21.190
201.....................
[root@dir network-scripts]# curl 10.222.21.190
202----------------------------
[root@dir network-scripts]# curl 10.222.21.190
201.....................
[root@dir network-scripts]# curl 10.222.21.190
201.....................
[root@dir network-scripts]# curl 10.222.21.190
202----------------------------

按权重循环显示rs1,rs2 nginx网页内容

 

 
posted @ 2017-08-21 13:14  Oops!#  阅读(266)  评论(0编辑  收藏  举报