最少连接的设计:
删除规则
[root@ds1 ~]# ipvsadm -C
查看规则列表
[root@ds1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
添加虚拟服务器:
[root@ds1 ~]# ipvsadm -A -t 201.1.1.100:80 -s lc
添加真实服务器:
[root@ds1 ~]# ipvsadm -a -t 201.1.1.100:80 -r 192.168.4.11 -m
[root@ds1 ~]# ipvsadm -a -t 201.1.1.100:80 -r 192.168.4.12 -m
查看规则:
[root@ds1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 201.1.1.100:80 lc
-> 192.168.4.11:80 Masq 1 0 0
-> 192.168.4.12:80 Masq 1 0 0
客户端访问测试:
[root@client ~]# curl http://201.1.1.100
rs1
[root@client ~]# curl http://201.1.1.100
rs2
[root@client ~]# curl http://201.1.1.100
rs1
[root@client ~]# curl http://201.1.1.100
rs2
++++++++++++++++++++++++++++++++++++++++++++++++++++++
连接完192.168.4.11 接着下一回就会连接192.168.4.12 体现最少连接的算法
启动服务:
[root@ds1 ~]# service ipvsadm start
Redirecting to /bin/systemctl start ipvsadm.service
关停服务:
[root@ds1 ~]# service ipvsadm stop
Redirecting to /bin/systemctl stop ipvsadm.service
设置开机自动开启:
[root@ds1 ~]# chkconfig ipvsadm on
注意:正在将请求转发到“systemctl enable ipvsadm.service”。
加权最少连接的配置:
删除规则:
[root@ds1 ~]# ipvsadm -C
查看规则:
[root@ds1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
添加虚拟服务器:
[root@ds1 ~]# ipvsadm -A -t 201.1.1.100:80 -s wlc
添加真实的服务器:
[root@ds1 ~]# ipvsadm -a -t 201.1.1.100:80 -r 192.168.4.11 -m -w 2
[root@ds1 ~]# ipvsadm -a -t 201.1.1.100:80 -r 192.168.4.12 -m -w 1
查看规则:
[root@ds1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 201.1.1.100:80 wlc
-> 192.168.4.11:80 Masq 2 0 0
-> 192.168.4.12:80 Masq 1 0 0
客户端测试查看:
rs2
[root@client ~]# curl http://201.1.1.100
rs1
[root@client ~]# curl http://201.1.1.100
rs1
[root@client ~]# curl http://201.1.1.100
rs2
[root@client ~]# curl http://201.1.1.100
rs1
++++++++++++++++++++++++++++++++++++++++++++++++
权重优先,那个服务器的权重小就优先连接