systemctl stop NetworkManager
systemctl disable NetworkManager
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-ens33:1
vim ifcfg-ens33:1
BOOTPROTO="static"
# 名称
DEVICE="ens33:1"
ONBOOT="yes"
# 虚拟IP
IPADDR="192.168.1.150"
NETMASK="255.255.255.0"
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:1
vim ifcfg-lo:1
DEVICE=lo:1
IPADDR=192.168.1.150
NETMASK=255.255.255.255
NETWORK=127.0.0.1
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
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
echo "route add -host 192.168.1.150 dev lo:1" >> /etc/rc.local
ipvsadm -a -t 192.168.1.150:80 -r 192.168.1.120:80 -g
ipvsadm -a -t 192.168.1.150:80 -r 192.168.1.121:80 -g
* `-a`:添加真实服务器
* `-t`:tcp协议
* `-r`:真实服务器ip地址
* `-g`:设定DR模式 * 保存到规则库,否则重启失效`ipvsadm -S` * 检查集群
* 查看集群列表`ipvsadm -Ln`
* 查看集群状态`ipvsadm -Ln --stats`
* 重启`ipvsadm`,重启后需要重新配置`service ipvsadm restart`
* 查看持久化连接`ipvsadm -Ln --persistent-conn`
* 查看连接请求过期时间及请求资源ip和目标ip`ipvsadm -Lnc`
* 设置tcp tcpfin udp的过期时间(一般保持默认)`ipvsadm --set 1 1 1`
* 查看过期时间`ipvsadm -Ln --timeout`