NAT:
director:
1)、在 director 机子上 (两个网卡 192.168.21.190)
yum -y install ipvsadm
2)、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
# director 设置 nat 防火墙
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -s 192.168.11.0/24 -j MASQUERADE
#director 设置 ipvsadm
IPVSADM='/sbin/ipvsadm'
$IPVSADM -C
$IPVSADM -A -t 192.168.21.190:80 -s rr
$IPVSADM -a -t 192.168.21.190:80 -r 192.168.11.160:80 -m(NAT 必须是 -m)
$IPVSADM -a -t 192.168.21.190:80 -r 192.168.11.20:80 -m
或者:
$IPVSADM -A -t 192.168.21.190:80 -s wrr
$IPVSADM -a -t 192.168.21.190:80 -r 192.168.11.160:80 -m(NAT 必须是 -m) -w 2
$IPVSADM -a -t 192.168.21.190:80 -r 192.168.11.20:80 -m -w 1
3)、 sh /usr/local/sbin/lvs_nat.sh
4)、 查看一下 路由转发列表 : ipvsadm -ln
rs1 2 :
1)、 设置 GATEWAY=192.168.11.190
2)、/etc/init.d/nginx start
3)、curl 192.168.21.190
清空:(director)
ipvsadm -ln
ipvsadm -C
iptables -t nat -F
修改网关 (rs 1 2:GATEWAY):vim /etc/sysconfig/network-scripts/ifcfg-eth0
DR:
每个 rs 都要有一个公网 IP
director:
1)、vim /usr/local/sbin/lvs_dr.sh
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=192.168.11.100
rs1=192.168.11.160
rs2=192.168.11.20
(ifconfig eth0:0 down)
ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:0
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1
rs:
1)、vim /usr/local/sbin/lvs_rs.sh
#!/bin/bash
vip=192.168.11.100
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
2)、两个 rs 运行一下脚本