LVS+NAT集群之最少连接和加权最少连接

最少连接的设计:

 

删除规则

[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

++++++++++++++++++++++++++++++++++++++++++++++++

权重优先,那个服务器的权重小就优先连接

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维螺丝钉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值