47 lvs-nat/dr

3台服务器:node1(vs),node2(rs),node3(rs)

lvs-nat

一、环境

1.时间同步

	node1
	tzselect 5 9 1 1
	TZ='Asia/Shanghai'; export TZ
	allow 192.168.146.0/24
	
	node2/3
	vim /etc/chrony.conf
	server 192.168.146.100 iburst
	ntpdate 192.168.146.100

2.vs2个物理网卡

	vs eth1  172.16.60.183/24
	vs eth2  192.168.146.100
	
	nmcli connection modify  eth1  ipv4.gateway 192.168.146.100
	nmcli connection eth 1 up
	
	rs1 192.168.146.101/24
		gw 192.168.146.100 网卡host-only
	rs2 192.168.146.102/24
		gw 192.168.146.100  网卡host-only

3.iptables -nL

		iptables -F
		systemctl stop firewalld
		systemctl disable firewalld

4.vs打开ipforward

	echo net.ipv4.ip_forward> /etc/sysctl.conf
		sysctl -p 

二.rs的服务

开启httpd(rs1,2)

echo “hello rs1” > /var/www/html/index.html
echo “hello rs2” > /var/www/html/index.html

三.lvs配置

   iptables -A -t 172.16.60.183:80 -s rr
   iptables -a -t 172.16.60.183:80 -r 192.168.146.101:80 -m 
   iptables -a -t 172.16.60.183:80-r 192.168.146.102:80  -m 

测试

curl 172.16.60.183
		hello rs2
curl 172.16.60.183
		hello rs1

 修改wrr
    ipvsadm -E -t 172.16.60.183:80  -s wrr
    ipvsadm -e -t 172.16.60.183:80 -r  192.168.146.101 -m -w 3
ipvsadm -ln 查看 
172.16.60.183:80 wrr
  -> 192.168.146.101:80           Masq    3      0          5         
  -> 192.168.146.102:80           Masq    1      0          4   

lvs-dr

在各主机的都需要配置vip,需要解决地址冲突的问题,让vip不可见
 路由器获取vsmac,必须在同一网段广播
解决方案:
    1.网关绑定静态绑定
    2.在各rs上使用arptables
    3.通过修改rs的内核来限制arp的响应和通告
    	arp_ignore
    		0 本地接口任意地址响应
    		1 仅在目标ip网络的接口进行响应
    		
    	arp_announce
    		0 所有地址向所有主机通高
    		1 尽量避免非本地网络通过
		2 总是避免向非本地网络通过

dr模型拓扑:
47 lvs-nat/dr

1.环境

router网卡

  1. ens33-172.16.60.183
  2. ens37-192.168.146.100
  3. ifconfig ens37:1-10.1.1.200/24

vs(ens37:1)

  1. ens37:192.168.146.99
  2. gw 192.168.146.100
  3. ens37:110.1.1.1/24

rs1(ens37:1)

  1. ens37:192.168.146.101
  2. gw 192.168.146.100
  3. ens37:110.1.1.1/24

rs2(ens37:1)

  1. ens37:192.168.146.102

  2. gw 192.168.146.100

  3. ens37:110.1.1.1/24

    rs1,rs2,vs配置虚拟ip
    ifconfig ens37:1 10.1.1.1 netmask 255.255.255.0 broadcast 10.1.1.1

本机客户端测试添加路由
sudo route -n add -net 10.1.1.0 -netmask 255.255.255.0 172.16.60.183

2.修改内核阻止arp响应

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

3.vs配置

   ipvsadm -A -t 10.1.1.1:80 -s rr
   ipvsadm -a -t 10.1.1.1:80 -r 192.168.146.101:80 -g(dr模式)
   ipvsadm -a -t 10.1.1.1:80 -r 192.168.146.102:80 -g