LVS(IPVS) - linux virtual server

官网:http://www.linuxvirtualserver.org/

关闭网络管理器:

systemctl stop NetworkManager;
systemctl disable NetworkManager;

调度节点虚拟IP配置:

负载节点虚拟IP配置:

ARP配置:

vi /etc/sysctl.conf

加入内容如下:

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

加入路由:

route add -host 192.168.31.200 dev lo:1;
echo "route add -host 192.168.31.200 dev lo:1" >> /etc/rc.local;

修改持久化:

ipvsadm -E -t 192.168.31.200:80 -s rr -p 5

lvs负载均衡安装:

yum install -y ipvsadm;
rpm -qa ipvsadm;
#把ipvs加入到内核
modprobe ip_vs; 
lsmod|grep ip_vs;
uname -r;
ln -s /usr/src/kernels/4.19.91-25.3.an7.x86_64 /usr/src/linux;
ls -l /usr/src;

如果没有/usr/src/kernels的,可以通过下面命令安装:

yum install kernel-devel -y

配置LVS虚拟IP(VIP):

ifconfig eth0:1 192.168.31.200/24 up;
route add -host 192.168.31.200 dev eth1;
ping 192.168.31.200;

配置命令:

ipvsadm -C;
ipvsadm --set 30 5 60;
#
ipvsadm -A -t 192.168.31.200:80 -s wrr;
#
ipvsadm -a -t 192.168.31.200:80 -r 192.168.31.101:80 -g -w 1;
ipvsadm -a -t 192.168.31.200:80 -r 192.168.31.102:80 -g -w 1;
ipvsadm -a -t 192.168.31.200:80 -r 192.168.31.103:80 -g -w 1;
#
ipvsadm -Ln;

删除:

ipvsadm -d -t 192.168.31.200:80 -r 192.168.31.103:80

保存配置:

ipvsadm-save > /etc/sysconfig/ipvsadm

参考:

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享