LVS DR模式配置

LVS Server

# VIP(虚拟IP):172.25.25.200 DIP(转发者IP/内网IP):172.25.25.3
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
BOOTPROTO=static
DEVICE=ens33:0
ONBOOT=yes
IPADDR=172.25.25.200
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network

RealServer

# RIP(真实IP/内网IP):172.25.25.4
# RIP(真实IP/内网IP):172.25.25.5
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=172.25.25.200
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# vim /etc/sysctl.conf
# configration for lvs
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
[root@localhost network-scripts]# sysctl -p
[root@localhost network-scripts]# route add -host 172.25.25.200 dev lo:0
[root@localhost network-scripts]# echo "route add -host 172.25.25.200 dev lo:0" >> /etc/rc.d/rc.local

使用ipvsadm配置集群规则

[root@localhost network-scripts]# ipvsadm -A -t 172.25.25.200:80 -s rr -p 5
[root@localhost network-scripts]# ipvsadm -a -t 172.25.25.200:80 -r 172.25.25.4:80 -g
[root@localhost network-scripts]# ipvsadm -a -t 172.25.25.200:80 -r 172.25.25.5:80 -g
[root@localhost network-scripts]# ipvsadm -S
[root@localhost network-scripts]# ipvsadm -Ln
[root@localhost network-scripts]# ipvsadm -Ln --stats

ARP响应级别与通告行为
arp-ignore:ARP响应级别(处理请求)
0:只要本机配置了ip,就能响应请求
1:请求的目标地址到达对应的网络接口,才会响应请求
arp-announce:ARP通告行为(返回响应)
0:本机上任何网络接口都向外通告,所有的网卡都能接受到通告
1:尽可能避免本网卡与不匹配的目标进行通告
2:只在本网卡通告

posted @ 2021-04-28 19:01  wanghongwei-dev  阅读(81)  评论(0编辑  收藏  举报