赞
踩
lvs-nat模式的优点配置简单,缺点是请求和响应都必须经过ds,容易称为性能瓶颈
希望有这样的模式,请求的时候使用input链进行负载均衡,响应的时候就不要经过ds,直接由rs响应给客户端
在nat模式的时候,请求vip,接收vip的响应构想 请求vip,接受rip响应,这是不允许lvs-dr模式
- # ds脚本
- #!/bin/bash
- #配置网卡
- echo TYPE="Ethernet" >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
- echo BOOTPROTO="none" >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
- read -p "router name:" router_name
- echo NAME='"$rount_name"' >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
-
- uuidkey=$( uuidgen )
-
- echo UUID='"$uuidkey"' >> /etc/sysconfig/network-
- scripts/ifcfg-ens36 >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
- echo DEVICE='"$rount_name"' >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
- echo ONBOOT="yes" >> /etc/sysconfig/network-scripts/ifcfg-
- ens36
- echo IPADDR=192.168.10.100 >> /etc/sysconfig/network-
- scripts/ifcfg-ens36
-
- systemctl restart network
-
- #安装ipvsadm
- yum list installed|grep ipvsadm
- if[ $? -ne 0 ];then
- yum -y install ipvsadm
- fi
- #配置规则
- read -p "vip:" vip
- read -p "port:" port
- read -p "rule:" s
- ipvsadm -A -t $vip:$port -s $s
- # ip forward
- echo "net.ipv4.ip_forward=1" >/etc/sysctl.conf
- sysctl -p
- # rs脚本
- #!/bin/bash
- read -p "dip:" dip
- # 设置网关
- route del default
- route add defualt gw $dip
1.性能更优,回路不再经过ds
2.ds和rs为了保证用户响应,都要求配置统一的vip
3.由于rs是直接响应client,网关一定不能设置为ds的dip
4.对rs的vip进行抑制,让ds的vip接收请求,rs的vip不接受请求
5.rs的vip绑定点lo回路网卡上
- [root@dr03 ~]# ifconfig
- ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 10.1.1.101 netmask 255.255.255.0 broadcast 10.1.1.255
-
- [root@dr03 ~]# ifconfig ens33:0 10.1.1.102 broadcast
- 10.1.1.102 netmask 255.255.255.255 up
-
- [root@dr03 ~]# route add -host 10.1.1.102 dev ens33:0
- # 10.1.1.101 dip
- # 10.1.1.102 vip 在rs上的vip和这个vip相同
- # 安装ipvsadm
- yum -y install ipvsadm
- $ 设置规则
- ipvsadm -A -t 10.1.1.102:80 -s rr
- ipvsadm -a -t 10.1.1.102:80 -r 10.1.1.200 -g
- ipvsadm -a -t 10.1.1.102:80 -r 10.1.1.201 -g
- # rs不在需要指定端口,dr不支持端口映射,vip上是80端口,最终就是80端
- 口
- # -m nat -g gateway
- [root@web01 ~]# ifconfig lo:0 10.1.1.102 broadcast
- 10.1.1.102 netmask 255.255.255.255 up
[root@web01 ~]# route add -host 10.1.1.102 dev 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
- ifconfig lo:0 10.1.1.102 broadcast 10.1.1.102 netmask
- 255.255.255.255 up
- route add -host 10.1.1.102 dev 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
[root@dr03 ~]# ipvsadm -Ln --stats
- #! /bin/bash
- #在ens33上挂载一个ip地址
- read -p "vip:" vip
- read -p "mac:" mac
- read -p "num" num
- ifconfig $mac: $num $vip broadcast $vip netmask
- 255.255.255.255
- # 主机路由
- route add -host $vip dev $mac:$num
-
- #安装ipvsadm
- yum list installed|grep ipvsadm
- if [ $? -ne 0 ] ; then
- yum -y install ipvsadm
-
- fi
-
- #配置规则(不需要设置ip_forword)
-
- ipvsadm -C
- read -p "rule:" rule
- read -p "port:" port
-
- ipvsadm -A -t $vip:$port -s $rule
-
- read -p "rip1:" rip1
- ipvsadm -a -t $vip:$port -r $rip1 -g
-
- read -p "rip2:" rip2
- ipvsadm -a -t $vip:$port -r $rip2 -g
- #!/bin/bash
- #在ens33上挂载一个ip地址
- read -p "vip:" vip
- read -p "mac:" mac
- read -p "num" num
- ifconfig $mac:$num $vip broadcast $vip netmask
- 255.255.255.255
- # 主机路由
- route add -host $vip dev $mac:$num
- 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。