yungame 2019-12-28
VS根据请求报文的目标IP和目标协议及端口将其调度转发至某RS,根据调度算法来挑选RS。LVS是内核级功能,工作在INPUT链的位置,将发往INPUT的流量进行“处理
#设备: client : 172.20.0.20 LVS : 172.20.0.10、192.168.20.10 Real Server : 192.168.20.20 、192.168.20.30、192.168.20.40 三台设备 # 环境 设置client 网关 :172.20.0.10 设置Read Server 网关 :192.168.20.10 #------------------------------------------------------- # lvs 配置 # 1 开启端口转发内核参数,默认为0 ,到此已经实现完成了端口转发功能: /etc/sysctl.conf net.ipv4.ip_forward=1 sysctl -p # 2 安装 ipvsadm 实现负载均衡: yum install ipvsadm -y 创建规则应用基础轮询模式: ipvsadm -A -t 172.20.0.10 -s rr # 3 在轮询模式下添加轮询的地址,查询配置情况 ipvsadm -a -t 172.20.0.10 -r 192.168.20.{20,30,40} ipvsadm -Ln #------------------------------------------------------- #client 访问测试,即可完成基于轮询的负载均衡调度功能 for(( i=1;i<1000;i++ )); do curl 172.20.0.10 ;sleep 1 ; done
# 设备 client 10.20.0.20 route 10.20.0.10 ,192.168.20.10 LVS 192.168.20.40 read Server1 192.168.20.20 read Server2 192.168.20.30 #环境 read Server 1 2 网关:192.168.20.10 LVS 网关:192.168.20.10 client 网关:10.20.0.10 route 端口转发开启(net.ipv4.ip.forward=1) #配置 #------------------------------------------------------- #vim 192.168.20.100 #------------------------------------------------------- # LVS #1, 回环网卡设置vip ip a a 192.168.20.100/32 dev lo:1 #2, ipvsadm设置 yum install ipvsadm ipvsadm -A -t 192.168.20.100 -s rr ipvsadm -a -t 192.168.20.100 -r 192.168.20.{20,30} #------------------------------------------------------- #Read server #1, 回环网卡设置vip ip a a 192.168.20.100/32 dev lo:1 #2, 内核参数设置 echo 1 > /proc/sys/net/ipv4/conf/{all,lo}/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/{all,lo}/arp_announce #3, 安装开启web服务 yum install httpd systemctl start httpd echo 'ReadServer[1,2]' > /var/www/html/index.html #------------------------------------------------------- #client 访问 for(( i=1;i<1000;i++ )); do curl 192.168.20.200 ;sleep 1 ; done
# 设备 client 10.20.0.20 route 10.20.0.10(eth0) ,192.168.20.10(eth1) LVS 192.168.20.40 read Server1 192.168.20.20 read Server2 192.168.20.30 #环境 read Server 1 2 网关:192.168.20.10 LVS 网关:192.168.20.10 client 网关:10.20.0.10 route 端口转发开启(net.ipv4.ip.forward=1) #配置 #------------------------------------------------------- #VIP 10.0.0.100 #------------------------------------------------------- # LVS #1, 回环网卡设置vip ip a a 10.0.0.100/32 dev lo:1 #2, ipvsadm设置 yum install ipvsadm ipvsadm -A -t 192.168.20.100 -s rr ipvsadm -a -t 192.168.20.100 -r 192.168.20.{20,30} #------------------------------------------------------- #Read server #1, 回环网卡设置vip ip a a 10.0.0.100/32 dev lo:1 #2, 内核参数设置 echo 1 > /proc/sys/net/ipv4/conf/{all,lo}/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/{all,lo}/arp_announce #3, 安装开启web服务 yum install httpd systemctl start httpd echo 'ReadServer[1,2]' > /var/www/html/index.html #------------------------------------------------------- #route #方法一 ip a a 10.0.0.200/8 dev eth1 #方法二 ip route add 10.0.0.100/32 dev eth1 #笔者:我也不知道为什么会这样~我只是知道这样能成~~~ #------------------------------------------------------- #client 访问 for(( i=1;i<1000;i++ )); do curl 192.168.20.200 ;sleep 1 ; done