F5负载均衡抓包方法

作者:易隐者 发布于:2012-10-17 12:48 Wednesday 分类:参考资料

登录F5

1,超级终端的登录:
通过Console电缆一端连接BIGIP,一端连接PC机的串口,然后打开超级终端,建立一个连接,超级终端中COM的参数设置如图: 

点击查看原图

不论是从Console口登陆,还是用SSH从网络登陆,BIG-IP的缺省登陆帐号与密码如下:
缺省登陆帐号:root
缺省登陆密码:default
输入帐号和密码后,将见到以下界面: 

点击查看原图

缺省的终端类型为vt100,回车后如图: 

点击查看原图

F5下的tcpdump的使用

1,web管理界面下的抓包
Tcpdump 工具在V4.5 之前只能在CLI 下使用,V9 提供了图形界面下的Tcpdump,在 System->support 界面下,我们可以直接使用tcpdump 工具: 

点击查看原图

2,F5命令行下Tcpdump的使用示例:
当业务无法正常工作时,经常需要在BIG-IP上抓包进行分析定位是什么原因导致数据包没有被常转发。BIG-IP上提供了TCPDUMP抓包分析工具。
TCPDUMP是Unix系统常用的报文分析工具,TCPDUMP经常用于故障定位,如会话保持失效、SNAT通信问题等。本文讲述TCPDUMP命令的基本用法,更详细的使用说明请参见“man tcpdump”。
命令语法:
       tcpdump [ -adeflnNOpqRStvxX ] [ -c count ] [ -F file ]
               [ -i interface ] [ -m module ] [ -r file ]
               [ -s snaplen ] [ -T type ] [ -w file ]
               [ -E algo:secret ] [ expression ]
其中:
 -i 报文捕获监听的接口,如果不指定,默认为系统最小编号的接口(不包括loop-back接口),一般对指定Vlan名称进行监控,如-i external 是对external vlan进行监控;也可以对指定端口进行监控如 –i 1.1。注意:当vlan 名称过长时,-i后面直接用vlan名称,tcpdump会出现错误提示,这时需要将vlan名改由vlan加vlan ID代替。如有一vlan名称为bip_external,vlan ID为2022,如要对bip_external vlan进行监听,需采用-i vlan2022的方式。
 -nn 不将IP地址或端口号转化为域名或协议名称
注:与BIG-IP 4.5版本的TCPDUMP命令不一样,在BIG-IP V9里面必须用两个nn才能使IP地址与端口不会被转化为域名或协议名称显示。
 -r 从文件中读取(该文件由-w选项创建)
 -s 确定捕获报文大小
 -w 直接将捕获报文写入文件,而不是对其进行解析并通过屏幕显示(与-r选项对应)
注:如果要将TCPDUMP所抓的包保存到文件,建议采用-s1600 –w /var/tmp/filename的方式,-s1600可以保证抓取完整的数据包,而/var/tmp使抓包文件保存在/var/tmp目录。

 -x 每个报文以十六进制方式显示
 -X 每个报文同时以文本和十六进制显示
 expression 匹配表达式的分组将进行解析。如果不指定表达式,系统对所有分组进行捕获分析。复杂表达式可以使用“and”与、“or”或以及“not”非操作进行组合。表达式有三种:
 type  三种种类:host、net和port。比如:host 10.1.1.1。如果不指定类型,默认为host。
 dir  有src、dst、 src or dst和src and dst四种方向。默认为src or dst,即双向。
 proto 常见协议有:ip、arp、tcp、udp、icmp等。如果不指定协议类型,默认为所有协议。 
举例1:对external接口主机139.212.96.2并且端口为1433的流量进行监控。端口不指定tcp和udp,默认为同时对tcp和udp进行报文捕获。本命令不解析IP地址/端口号为主机名/服务名称,同时显示报文十二进制和文本信息,报文最大为1500字节。
f5-1:~# tcpdump -i external -nn -X -s 1600  port 1433 and host 139.212.96.2     
tcpdump: listening on external                                                 
21:48:41.295546 139.212.96.2.1201 > 10.75.9.44.1433: . 302192826:302192827(1) ac
k 558871968 win 64360 (DF)                                                     
0x0000   012c 0800 4500 0029 38cf 4000 7f06 c3b2        .,..E..)8.@.....       
0x0010   8bd4 6002 0a4b 092c 04b1 0599 1203 18ba        ..`..K.,........       
0x0020   214f b5a0 5010 fb68 a926 0000 00               !O..P..h.&...          
21:48:41.296015 10.75.9.44.1433 > 139.212.96.2.1201: . ack 1 win 64636 (DF)    
0x0000   012c 0800 4500 0028 cb2d 4000 7f06 3155        .,..E..(.-@...1U       
0x0010   0a4b 092c 8bd4 6002 0599 04b1 214f b5a0        .K.,..`.....!O..       
0x0020   1203 18bb 5010 fc7c a812 0000 0000 0000        ....P..|........       
0x0030   0000                                           ..                     
21:48:50.701130 139.212.96.2.1206 > 10.75.9.44.1433: . 304974934:304974935(1) ac
k 565108263 win 64882 (DF)                                                     
0x0000   012c 0800 4500 0029 38f7 4000 7f06 c38a        .,..E..)8.@.....       
0x0010   8bd4 6002 0a4b 092c 04b6 0599 122d 8c56        ..`..K.,.....-.V       
0x0020   21ae de27 5010 fd72 0a6b 0000 00               !..'P..r.k...          
21:48:50.702567 10.75.9.44.1433 > 139.212.96.2.1206: . ack 1 win 65267 (DF)    
0x0000   012c 0800 4500 0028 d3a6 4000 7f06 28dc        .,..E..(..@...(.       
0x0010   0a4b 092c 8bd4 6002 0599 04b6 21ae de27        .K.,..`.....!..'       
0x0020   122d 8c57 5010 fef3 08ea 0000 0000 0000        .-.WP...........       
0x0030   0000                                           ..                     

举例2:对internal接口主机172.31.230.53和172.31.230.51之间端口8080的流量进行分组捕获。本命令不解析IP地址/端口号为主机名/服务名称,报文最大为1600字节,捕获信息以“/var/tmp/intdump”文件保存:
tcpdump -s 1600 -i internal -w /var/tmp/intdump  host 172.31.230.53 and host 172.31.230.51 and port 8080
如果查看该捕获文件,请用tcpdump –r  /var/tmp/intdump命令。也可以将捕获的文件下载下来用Ethereal工具解包分析。
Tcpdump的具体使用语法参见tcpdump使用手册

F5命令行下使用tcpdump的常见问题

1,对某一Virtual Server用TCPDUMP命令无法抓到包如何处理?
可能是该Virtual Server的属性中选用了Performance Layer4类型,导致数据包由四层加层ASIC芯片处理而没有流经CPU引起,碰到这种情况,选取该Virtual Server将type由Performance Layer4临时改为Standard再来用TCPDUMP命令抓包,抓包以后,改回到Performance Layer4。
2,TCPDUMP出现“truncated-ip - 1215 bytes missing!”信息是不是说明网络上有丢包?
在BIG-IP V9里面出现”Truncated-IP xxxx bytes missing”信息,一般来说并不是网络上有丢包引起的,而是在执行TCPDUMP命令时没有加上 –s0或-s1600参数时,而数据包大小超过TCPDUMP缺省的抓包大小(如果不加-s0或-s1600参数,则缺省的每个数据包只抓前面400byes),就会出现truncated-ip的情况。出现这种情况,只需要重新输入tcpdump命令,加上-s0或-s1600即可。
3,TCPDUMP 命令中的-i interface中的interface用VLAN名称(如external或internal)与接口编号(1.1或2.1)有什么区别?
如果采用VLAN名称作为-i的参数,TCPDUMP收集的数据包是经由内部接口到达TMM进程经由中央CPU处理的数据包。
采用VLAN名称作为-i参数的局限性在于,由于PVA四层加速芯片时位于BIG-IP的交换板(Swithboard)上,并不需要经由主机板与交换机板的内部接口到达中央CPU,因此TCPDUMP无法抓取这些四层加速的数据包。
因此采用VLAN名称作为-i的参数一般是用于对采用Standard作为Virtual Server类型的应用抓包时采用。

注:如果Virtual Server是用PVA四层加速芯片作加速处理,则在Virtual Server的属性中PVA Acceleration显示为Full。
(The PVA handles accelerated traffic in the following order:
• The PVA receives accelerated traffic from the switch subsystem
• The PVA transforms the packet in order to redirect the packet to the appropriate pool member
• The PVA sends the packet back to the switch subsystem
Fully accelerated traffic never reaches the internal trunk and is not processed by TMM. )
 如果采用接口编号作为-i的参数,则进出该接口的数据包将先被镜像给SCCP(SCCP是BIG-IP的管理子系统),然后送到主机板上通过TCPDUMP抓包。由于是直接镜像了端口,因此经由四层加速芯处理的数据包也能被TCPDUMP获取。
采用接口编号作为-i的参数的局限性在于,由于数据包是经由SCCP(管理子系统)转发给主机板,数据包的处理速度有限,每秒只能处理200个数据包。因此采用接口编号作为-i的参数一般是用于做基本网络故障诊断时。
(When tcpdump is run on an interface, the packet is copied on switch ingress to the SCCP, which then sends it to the host to be captured by tcpdump.
Limitations
Running tcpdump on a switch interface is rate-limited to 200 packets per second. Therefore, if you run tcpdump on an interface that is processing more than 200 packets per second, the captured tcpdump file will not include all of the packets.
For example, the following command will capture PVA accelerated traffic, but the syntax will result in a rate limit of 200 packets per second。)
注:对于采用了PVA四层加速芯片加速处理的Virtual,而且网络流量又比较大时,如果需要进行抓包分析,建议在上一级交换机作端口镜像,将网络流量输出到外部的抓包主机上处理。

4,TCPDUMP 命令中出现“pcap_loop: Error: Interface packet capture busy”错误信息?
同时执行多个TCPDUMP,出现“pcap_loop: Error: Interface packet capture busy”错误,例如:
[root@bigip1:Active] config # tcpdump: listening on 1.1
[root@bigip1:Active] config # tcpdump -ni 1.3 -s 1600 -X -w/var/tmp/v741-E13.dmp port 22 &
[3] 6813
tcpdump: listening on 1.3
[root@bigip1:Active] config # tcpdump -ni 1.4 -s 1600 -X -w/var/tmp/v742-E14.dmp port 22 &
[4] 6820
tcpdump: listening on 1.4
[root@bigip1:Active] config # tcpdump: pcap_loop: Error: Interface packet capture busy
tcpdump: pcap_loop: Error: Interface packet capture busy
这种情况一般只发生在TCPDUMP -i参数采用接口编号时。原因主要在于当采用接口编号作为-i参数时,是通过BIG-IP的二层芯片将该接口的数据包镜像到中央CPU作处理。而BIG-IP的二层芯片的接口镜像功能不支持多个接口同时镜像,因此如果同时执行多个用接口名称作-i参数的TCPDUMP命令,就会出现Interface packet capture busy的信息。
注:对于采用VLAN名称作为TCPDUMP –i参数,则不存在这个问题,可以支持对多个VLAN同时执行TCPDUMP抓包命令。
(Currently only one tcpdump session is possible at a time on a switch interface (tcpdump on vlan alllows multiple sessons).  This is due to a limitation of the Broadcom SDK, but we may be able to extend the SDK to support multiple sessions.
The root difficulty here is that mirrored packets don't carry a note saying "this is where I came from." In a Broadcom switch fabric we can mirror from multiple ports, and all the packets will funnel to the host -- but we don't know which tcpdump session to route them to. One idea involves a layer 2 lookup on each packet performed by the bcm56xx daemon on the sccp. This would be intense so we continue to have this limitation.)

标签: 负载均衡 F5 tcpdump 抓包


您对本文的评分:
当前平均分: 9.5(3 次打分)

版权所有:《蚂蚁网-多维人生,三实而立!》 => 《F5负载均衡抓包方法
本文地址:http://www.vants.org/?post=170
除非注明,文章均为 《蚂蚁网-多维人生,三实而立!》 原创,欢迎转载!转载请注明本文地址,谢谢。

发表评论:

Powered by 易隐者 基于emlog 皖ICP备12002343号-1