构建DR模式的负载均衡集群
拓展
ARP
arp_annouce 通告
0 将本机任何接口上的任何地址都向外通告
1 尽可能避免向目标网络通告其网络不匹配的地址信息
2 仅向目标网络通告与其网络匹配的地址信息
arp_ignore 响应
0 只要本机配置有该ip就响应
1 仅在请求的目标地址配置在请求到达的接口上时,才给予响应。
Centos7五台服务器(考试可以去除测试机和路由器)
IP:192.168.10.13
GW:192.168.10.23
ens33:192.168.10.23
ens37:192.168.11.23
vim /etc/sysctl.conf
添加内容:net.ipv4.ip_forward = 1
sysctl -p
DIP--ens33
IP:192.168.11.33
GW:192.168.11.23
网卡子接口:VIP地址
VIP--ens33:0
IP:192.168.11.200
GW:192.168.11.23
4号:
ens33:192.168.11.43
GW:192.168.11.23
5号:
ens33:192.168.11.53
GW:192.168.11.23
本地回环网卡配置子接口----------两台应用服务器同步操作:按照以下步骤操作
cd /etc/sysconfig/network-scripts/
cp -a ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
1 DEVICE=lo
2 IPADDR=192.168.11.200
3 NETMASK=255.255.255.255
systemctl restart network
yum -y install httpd
cd /var/www/html/
echo "http1 1 hao" >> index.html
cd /var/www/html/
echo "http2 2 hao " >> index.html
route add default gw 192.168.11.23
cp -a /usr/share/doc/httpd-2.4.6/httpd-default.conf /etc/httpd/conf.d/
vim /etc/httpd/conf.d/httpd-default.conf
修改以下两部分
systemctl restart httpd
systemctl enable httpd
vim /etc/sysctl.conf
添加内容:net.ipv4.ip_forward = 1
sysctl -p
测试机测试
[root@zjt13 ~]# curl 192.168.11.43
http1 1 hao
[root@zjt13 ~]# curl 192.168.11.53
http2 2 hao
vim /etc/sysctl.conf
(三选一)
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
sysctl –p
[root@zjt33 ~]# cd /etc/sysconfig/network-scripts/
[root@zjt33 network-scripts]# cp -a ifcfg-ens33 ifcfg-ens33:0
[root@zjt33 network-scripts]# vim ifcfg-ens33:0
systemctl restart network
config为内核文件,如果做过内核升级应该判断正在用的内核版本的文件
grep -i "ip_vs" /boot/config-3.10.0-957.el7.x86_64
yum -y install ipvsadm.x86_64
ipvsadm -A -t 192.168.11.200:80 -s rr
ipvsadm -ln
ipvsadm -a -t 192.168.11.200:80 -r 192.168.11.43:80 -g
ipvsadm -a -t 192.168.11.200:80 -r 192.168.11.53:80 -g
ipvsadm -ln
集群创建完成没有配置文件不需要保存
cd /etc/sysconfig/network-scripts/
cp -a ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
1 DEVICE=lo
2 IPADDR=192.168.11.200
3 NETMASK=255.255.255.255
4 NETWORK=127.0.0.0
5 # If you're having problems with gated making 127.0.0.0/8 a martian,
6 # you can change this to something else (255.255.255.255, for example)
7 BROADCAST=127.255.255.255
8 ONBOOT=yes
9 NAME=loopback
systemctl restart network
vim /etc/sysctl.conf
三组任选一组
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@zjt43 network-scripts]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
route add -host 192.168.11.200 dev lo:0
iptables -t nat -A PREROUTING -i ens33 -d 192.168.10.23 -p tcp --dport 80 -j DNAT --to-destination 192.168.11.200
#192.168.10.23—路由器公网IP地址
#192.168.11.200—集群IP地址(VIP)
iptables -t nat -L
[root@zjt13 ~]# curl www.zjt.com
yum -y install httpd-tools
[root@zjt13 ~]# which ab
/usr/bin/ab
[root@zjt13 ~]# rpm -qf /usr/bin/ab
httpd-tools-2.4.6-88.el7.centos.x86_64
ab -c 100 -n 1000 http://192.168.10.23:80/index.html
ipvsadm -ln
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。