一、实验环境
每台主机的防火墙和SELinux都要关掉
systemctl stop firewalld
setenforce 0
client(测试机):
ip 172.25.254.50
lvs(调度器):
vip 172.25.254.100
dip 192.168.0.100
RS1(真实服务器):
dip 192.168.0.10
gw:192.168.0.100
RS2(真实服务器):
dip 192.168.0.20
gw:192.168.0.100
vmset.sh脚本:
client:
lvs:
RS1:
RS2:
二、配置步骤
lvs配置:
1、在lvs启动内核路由功能
echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
sysctl -p
2、在lvs安装ipvsadm
yum install ipvsadm -y
3、在lvs添加调度策略
ipvsadm -A -t 172.25.254.100:80 -s rr
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m
ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m
查看策略:
4、保存规则
ipvsadm -Sn > /etc/sysconfig/ipvsadm-config
5、删除所有规则
ipvsadm -C
6、重新加载规则
ipvsadm -R < /etc/sysconfig/ipvsadm-config
7、以上操作均为临时,如果想开机启动
systemctl enable --now ipvsadm.service
8、配置RS1、RS2
RS1:
RS2:
9、测试
10、修改为权重调用算法
ipvsadm -E -t 172.25.254.100:80 -s wrr
ipvsadm -e -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 2
ipvsadm -e -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 1
11、测试