DR : 192.168.29.150
VIP:192.168.29.100
RS1: 192.168.29.110
VIP:192.168.29.100
RS2:192.168.29.120
VIP:192.168.29.100
RS 配置
1 配置VIP
[root@local ~]# ifconfig lo:0 192.168.29.100 netmask 255.255.255.255 broadcast 192.168.29.100 up
2 添加路由
[root@local ~]# ip route add 192.168.29.100 dev lo:0
3 ARP相关配置
ARP 响应行为和ARP解析行为内核参数
(1)arp_announce 定义通告级别
0:默认级别,将本地的任何端口的配置地址都在网络中通告
1:不是同一个接口的请求尽量不响应,尽量避免向本主机上的其他网卡进行网络通信,特殊情况下其他接口也可以
2:针对参数1来讲,不在同一个接口过来的请求总是不响应,针对1问题避免,总是使用最佳网络地址接口(仅使用定义的网卡接口在同网络通信)
(2)arp_ignore 定义响应级别(0-8九个级别),响应是忽略方式
0:使用本地任意接口上配置地址进行响应,既全都响应
1:只对本接口进入的请求响应,且本接口地址是个网络地址
2:限制子网模式下响应
……
8:谁都不响应
(3)配置RS主机参数
注意:all必须配置、ens33(本地)和lo两个可以同时全部配置或者只配置其中一个RealServer内核参数
[root@local ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@local ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@local ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@local ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
此处的的物理接口可以是ens33 也可以是lo
4 http相关配置
(1)安装httpd
[root@local ~]# yum install httpd
(2)修改默认主页
[root@local ~]# echo “This is RS1 192.168.29.110” >/var/www/html/index.html
[root@local ~]# echo “This is RS2192.168.29.120” >/var/www/html/index.html
(3)启动httpd服务
[root@local ~]# systemctl start httpd.service
VS 主机配置
1安装ipvsadm
[root@local ~]# yum install ipvsadm
2定义ipvsadm 负载均衡集群规则
[root@local ~]# ipvsadm -A -t 192.168.29.100:80 -s rr
[root@local ~]# ipvsadm -a -t 192.168.29.100:80 -r 192.168.29.110 –g
[root@local ~]# ipvsadm -a -t 192.168.29.100:80 -r 192.168.29.120 -g
3查看集群
[root@local ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.29.100:80 rr
-> 192.168.29.110:80 Route 1 0 0
-> 192.168.29.120:80 Route 1 0 0
4 测试
[root@centos7 ~]# for i in {1..10} ; do curl http://192.168.29.100; done
This is RS2 192.168.29.120
This is RS1 192.168.29.110
This is RS2 192.168.29.120
This is RS1 192.168.29.110
This is RS2 192.168.29.120
This is RS1 192.168.29.110
This is RS2 192.168.29.120
This is RS1 192.168.29.110
This is RS2 192.168.29.120
This is RS1 192.168.29.110
测试成功!!
基于rr算法,请求依次分发给RS主机
原创文章,作者:linux is not unix,如若转载,请注明出处:http://www.178linux.com/78917