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
nf_conntrack ip_vs
libcrc32c 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
nf_conntrack ip_vs
libcrc32c xfs,ip_vs

添加VIP(虚拟IP),虚拟IP需和实际IP为一个网段

[root@node1 ~]# ip addr add 10.0.0.28/ dev eth0 label eth0:0

查看虚拟IP

[root@node1 ~]# ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::::b8 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.20/ brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet 10.0.0.28/ scope global secondary eth0:
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe29:39b8/ scope link
valid_lft forever preferred_lft forever

清空ipvsadm记录

[root@node1 ~]# ipvsadm -C

配置ipvs,并查看

[root@node1 ~]# ipvsadm -A -t 10.0.0.28: -s wrr
[root@node1 ~]# ipvsadm -a -t 10.0.0.28: -r 10.0.0.21: -g -w
[root@node1 ~]# ipvsadm -a -t 10.0.0.28: -r 10.0.0.22: -g -w
[root@node1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.28: wrr
-> 10.0.0.21: Route
-> 10.0.0.22: Route

加入开机启动

[root@node1 ~]# systemctl enable ipvsadm

Web

绑定虚拟IP(VIP)

[root@node2 ~]# ip addr add 10.0.0.28/ dev lo label lo:0  每台web都要执行

抑制VIP,防止LVS和RSVIP冲突

[root@node2 ~]# echo "" >/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node2 ~]# echo "" >/proc/sys/net/ipv4/conf/lo/arp_announce
[root@node2 ~]# echo "" >/proc/sys/net/ipv4/conf/all/arp_ignore
[root@node2 ~]# echo "" >/proc/sys/net/ipv4/conf/all/arp_announce
上一篇:关于pdfbox操作pdf的分享链接手长


下一篇:Spring Maven 包的依赖