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
#! /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
[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
[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----------------------------