LVS 之搭建
部署LVS
10.0.0.20
[root@node1 ~]# yum -y install ipvsadm
进入到 /usr/src 目录查看结果,如果有ip_vs_rr、ip_vs,表示正常
[root@node1 ~]# cd /usr/src/ [root@node1 src]# lsmod|grep ip_vs ip_vs 136798 0 nf_conntrack 105702 1 ip_vs libcrc32c 12644 2 xfs,ip_vs
如果没有显示加载一下,在此查看
[root@node1 src]# lsmod|grep ip_vs [root@node1 src]# modprobe ip_vs [root@node1 src]# lsmod|grep ip_vs ip_vs 136798 0 nf_conntrack 105702 1 ip_vs libcrc32c 12644 2 xfs,ip_vs
添加VIP(虚拟IP),虚拟IP需和实际IP为一个网段
[root@node1 ~]# ip addr add 10.0.0.28/24 dev eth0 label eth0:0
查看虚拟IP
[root@node1 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:29:39:b8 brd ff:ff:ff:ff:ff:ff inet 10.0.0.20/24 brd 10.0.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.0.0.28/24 scope global secondary eth0:0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe29:39b8/64 scope link valid_lft forever preferred_lft forever
清空ipvsadm记录
[root@node1 ~]# ipvsadm -C
配置ipvs,并查看
[root@node1 ~]# ipvsadm -A -t 10.0.0.28:80 -s wrr [root@node1 ~]# ipvsadm -a -t 10.0.0.28:80 -r 10.0.0.21:80 -g -w 1 [root@node1 ~]# ipvsadm -a -t 10.0.0.28:80 -r 10.0.0.22:80 -g -w 1 [root@node1 ~]# 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.28:80 wrr -> 10.0.0.21:80 Route 1 0 0 -> 10.0.0.22:80 Route 1 0 0
加入开机启动
[root@node1 ~]# systemctl enable ipvsadm
Web
绑定虚拟IP(VIP)
[root@node2 ~]# ip addr add 10.0.0.28/32 dev lo label lo:0 每台web都要执行
抑制VIP,防止LVS和RSVIP冲突
[root@node2 ~]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore [root@node2 ~]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce [root@node2 ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore [root@node2 ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce