ipvsadm 命令详解

查看内核是否支持 ipvsadm

[test@LVS ~]$ /sbin/modprobe -l|grep ipvs
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_dh.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_ftp.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lblc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lblcr.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_lc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_nq.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_rr.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_sed.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_sh.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_wlc.ko
/lib/modules/2.6.18-308.el5/kernel/net/ipv4/ipvs/ip_vs_wrr.ko

如果不支持,就安装 ipvsadm

sudo yum -y install ipvsadm

ipvsadm 参数详解:

-C 清除表中所有的记录
-A --add-service在服务器列表中新添加一条新的虚拟服务器记录
-t 表示为tcp服务
-u 表示为udp服务
-s --scheduler 使用的调度算法, rr | wrr | lc | wlc | lblb | lblcr | dh | sh | sed | nq 默认调度算法是 wlc
ipvsadm -a -t 192.168.3.187:80 -r 192.168.200.10:80 -m -w 1
-a --add-server 在服务器表中添加一条新的真实主机记录
-t --tcp-service 说明虚拟服务器提供tcp服务
-u --udp-service 说明虚拟服务器提供udp服务
-r --real-server 真实服务器地址
-m --masquerading 指定LVS工作模式为NAT模式
-w --weight 真实服务器的权值
-g --gatewaying 指定LVS工作模式为直接路由器模式(也是LVS默认的模式)
-i --ipip 指定LVS的工作模式为隧道模式
-p 会话保持时间,定义流量呗转到同一个realserver的会话存留时间

[test@LVS ~]$ sudo /sbin/ipvsadm -l 
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.1.17.10:http wlc
  -> 10.2.4.35:http            Route   100    25095      18542     
  -> 10.2.4.31:http            Route   100    25097      17657     
  -> 10.2.4.30:http            Route   100    25123      18953     
  -> 10.2.4.29:http            Route   100    25091      18727     
  -> 10.2.4.24:http            Route   100    25075      17703     
  -> 10.2.4.23:http            Route   100    25086      17465     
  -> 10.2.4.22:http            Route   100    25124      17628     

InActConn 指非活跃连接数,我们将处于 TCP ESTABLISH 状态以外的连接都称为不活跃连接。例如处于 SYN_RECV 状态的连接,处于 TIME_WAIT 状态的连接等。

[test@LVS ~]$ sudo /sbin/ipvsadm -l --rate 
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port                 CPS    InPPS   OutPPS    InBPS   OutBPS
  -> RemoteAddress:Port
TCP  192.1.17.10:http               2438    16241        0  6385560        0
  -> 10.2.4.35:http                 146      965        0   372714        0
  -> 10.2.4.34:http                 164     1089        0   423347        0
  -> 10.2.4.28:http                 152     1035        0   406658        0
  -> 10.2.4.27:http                 157     1031        0   411744        0
  -> 10.2.4.22:http                 160     1078        0   425447        0
  -> 10.2.4.21:http                 159     1078        0   423759        0

--rate选项是显示速率信息

  • CPS (current connection rate) 每秒连接数
  • InPPS (current in packet rate) 每秒的入包个数
  • OutPPS (current out packet rate) 每秒的出包个数
  • InBPS (current in byte rate) 每秒入流量(字节)
  • OutBPS (current out byte rate) 每秒入流量(字节)
[test@LVS ~]$ sudo /sbin/ipvsadm -l --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP 192.1.17.10:http            326629K    3588M        0   22517G        0
  -> 10.2.4.23:http             584349K    3896M        0    1469G        0
  -> 10.2.4.34:http             597422K    3956M        0    1501G        0
  -> 10.2.4.28:http             631106K    4198M        0    1592G        0
  -> 10.2.4.27:http             578297K    3850M        0    1459G        0
  -> 10.2.4.22:http             580208K    3859M        0    1463G        0
  -> 10.2.4.21:http             685758K  283146K        0    1737G        0

--stats 选项是统计自该条转发规则生效以来的

  • Conns (connections scheduled) 已经转发过的连接数
  • InPkts (incoming packets) 入包个数
  • OutPkts (outgoing packets) 出包个数
  • InBytes (incoming bytes) 入流量(字节)
  • OutBytes (outgoing bytes) 出流量(字节)

修改 LVS 表中的 fin_timeout 使用指令如下

ipvsadm --set 900 60 300

中间的 60 就是 tcp 的 fin_timeout 时间

查看默认的值使用如下命令:

$ sudo /sbin/ipvsadm -Ln --timeout 
Timeout (tcp tcpfin udp): 900 60 300
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值