一:环境准备:
rhel9
软件:httpd, ipvsadm
四台纯净的rhel9机子:一台LVS调度设备(双网卡),两台webserver(单网卡仅主机),一台客户机 DR模式多一个路由起到转发作用
二:NAT模式:
LVSvip局域网:
打开内核路由功能:
[root@lvs ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@lvs ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@lvs ~]# sysctl -p 生效
net.ipv4.ip_forward = 1
两台后台服务器地址配置:
三台机子下载httpd:
[root@lvs ~]# yum install httpd
在LVS下载ipvsadm:
[root@lvs ~]# yum install ipvsadm.x86_64 -y
编写规则;
[root@lvs boot]# ipvsadm -A -t 172.25.254.100:80 -s rr -A:虚拟server -t:tcp协议
-s指定算法 rr:轮循
[root@lvs boot]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.200:80 m
unexpected argument m
[root@lvs boot]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.200:80 -m(nat)-g:直连路由 -i:隧道
[root@lvs boot]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.250:80 -m
[root@lvs boot]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.254.100:80 rr
-> 192.168.0.200:80 Masq 1 0 0
-> 192.168.0.250:80 Masq 1 0 0
测试:
[root@lvs boot]# ipvsadm-save -n > /etc/sysconfig/ipvsadm 保存解析
三:ipvsadm参数练习:
-D:删除 -A:添加, ipvsadm -Ln --rate:统计访问总量 -E:更改 -Z:清空浏览量 -r:指定地址
、
四:DR模式:
ip规划:
lvs主机:网关为192.168.0.100
router:
打开内核路由:
Clint:
rs主机中使vip不对外响应:
server:
[root@lvs ~]# ip a a 192.168.0.200/32 dev lo
[root@webser1 ~]# ip a a 192.168.0.200/32 dev lo
[root@webserver2 ~]# ip a a 192.168.0.200/32 dev lo
制作策略:
[root@lvs ~]# ipvsadm -A -t 192.168.0.200:80 -s wrr
[root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.10:80 -g -w 1
[root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.20:80 -g -w 2
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.200:80 wrr
-> 192.168.0.10:80 Route 1 0 3
-> 192.168.0.20:80 Route 2 0 7
测试: