#安装 yum install ipvsadm -y #设置超时时间 ipvsadm --set 30 5 60 #配置vip ipvsadm -A -t 10.0.0.1:80 -s wrr -p 20 -A 添加服务端 -t tcp -s 轮询算法 -p 会话吧保持时间 #添加客户端 ipvsadm -a -t 10.0.0.1:80 -r 10.0.0.2:80 -g -w 1 ipvsadm -a -t 10.0.0.1:80 -r 10.0.0.3:80 -g -w 1 -g 是dr模式 -w 权重 -a 指定客服端 #保存配置 ipvsadm-save -n >/tmp/lvs.bak #重新配置文件 ipvsadm-restore -n </tmp/lvs.bak
#手动添加vip #lb01 ip addr add 10.0.0.1/24 dev eth0 label eth0:1 #删除 ip addr del 10.0.0.1/24 dev eth0 label eth0:1
#web01 web02 #添加vip ip addr add 10.0.0.1/32 dev lo label lo:1 #不让web上的vip解析 cat >>/etc/sysctl.conf<<EOF net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2 EOF sysctl -p
#查看访问了多少次 [root@test ~ 19:20:04]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.1:80 wrr persistent 20 -> 10.0.0.2:80 Route 1 1 0 -> 10.0.0.3:80 Route 1 0 0