Abel'Blog

我干了什么?究竟拿了时间换了什么?

0%

server测试工具

记录一下常用的服务器测试工具。

网络相关

抓包工具

网络分析

wireshark_v3.4.5

tcpdump

通过指令安装yum install tcpdump

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ tcpdump  -XvvennSs 0 -i enp2s0 port 8080

20:01:34.640787 94:c6:91:57:e4:1b > d4:5d:64:f0:76:aa, ethertype IPv4 (0x0800), length 54: (tos 0x0, ttl 64, id 23026, offset 0, flags [DF], proto TCP (6), length 40)
192.168.125.213.8080 > 192.168.125.196.11743: Flags [.], cksum 0x7f69 (correct), seq 2141321887, ack 3936026461, win 471, length 0
0x0000: 4500 0028 59f2 4000 4006 63f3 c0a8 7dd5 E..(Y.@.@.c...}.
0x0010: c0a8 7dc4 1f90 2ddf 7fa1 fa9f ea9a ff5d ..}...-........]
0x0020: 5010 01d7 7f69 0000 P....i..
20:01:34.648655 94:c6:91:57:e4:1b > d4:5d:64:f0:76:aa, ethertype IPv4 (0x0800), length 415: (tos 0x0, ttl 64, id 23027, offset 0, flags [DF], proto TCP (6), length 401)
192.168.125.213.8080 > 192.168.125.196.11743: Flags [P.], cksum 0xe9dc (correct), seq 2141321887:2141322248, ack 3936026461, win 471, length 361: HTTP, length: 361
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Mon, 21 Jun 2021 12:01:34 GMT
Content-Length: 237

0x0000: 4500 0191 59f3 4000 4006 6289 c0a8 7dd5 E...Y.@.@.b...}.
0x0010: c0a8 7dc4 1f90 2ddf 7fa1 fa9f ea9a ff5d ..}...-........]
0x0020: 5018 01d7 e9dc 0000 4854 5450 2f31 2e31 P.......HTTP/1.1
0x0030: 2032 3030 204f 4b0d 0a43 6f6e 7465 6e74 .200.OK..Content
0x0090: 7465 6e74 2d4c 656e 6774 683a 2032 3337 tent-Length:.237
0x00a0: 0d0a 0d0a 7b22 5549 4422 3a34 372c 224c ....{"UID":47,"L
0x00b0: 6f62 6279 4164 6472 223a 2231 3932 2e31 obbyAddr":"192.1
0x00c0: 3638 2e31 3235 2e31 3936 3a32 3636 3622 68.125.196:2666"
0x0170: 3565 3436 3264 6331 3866 3963 3063 3661 5e462dc18f9c0c6a
0x0180: 3366 6439 6465 3261 3835 6538 6522 7d5d 3fd9de2a85e8e"}]
0x0190: 7d

所以,在工作中 tcpdump 只是用来抓取数据包,不用来分析数据包,而是把 tcpdump 抓取的数据包保存成 pcap 后缀的文件,接着用 Wireshark 工具进行数据包分析。

先使用指令将侦听到的数据写入文件,tcpdump -XvvennSs 0 -i enp2s0 port 8080 -w http_tcpdump.pcap。然后使用wireshark来看。

wireshark说明文档

网络限制工具

TC

TC是限速命令,wondershaper是国外人开发的一款在Linux内核下基于TC工具的对整块网卡的限度工具。

1
2
yum install epel-release -y
yum install wondershaper -y

TC工具

监控网络使用率

使用iftop工具能监控服务器通讯情况yum install iftop

网上找到的建议

ip:查看网卡上的总流量
来自 iproute2util 包,在大多数系统上都已经默认安装,也可通过 yum install -y iproute 安装
nload:查看各个网络设备的当前网络速率
来自EPEL软件库,安装:yum install -y epel-release && yum install -y nload
iptraf-ng:可以输出网卡的tcp、udp等各种数据,和各个网卡的实时网速
默认未安装,可使用 yum install -y iptraf-ng 安装
stat:用来替换vmstat、iostat、netstat、nfsstat和ifstat的全能系统信息统计工具,支持数据实时刷新,输出直观易懂
默认没有安装,安装命令为:yum install -y dstat
sar:System Activity Report的缩写,是一款全面的Linux系统运行状态统计和性能分析工具,可从磁盘IO、CPU负载、内存使用等多个维度对系统活动进行报告
来自 sysstat 包,安装:yum install -y sysstat
ss 和 netstat:查看活动链接/监听端口的常用命令。ss 是 netstat 的替代,性能更好,建议使用
ss 是 iproute2util 包的一部分,netstat 来自 net-tools 包,新版系统上需要自行安装:yum install -y net-tools
nethogs:查看单个进程流量而设计的工具,按照进程进行带宽分组
来自EPEL软件库,安装命令是:yum install -y epel-release && yum install -y nethogs
tcpdump:用来抓包,保存的数据可以用wireshark打开和查看

版权声明:本文为CSDN博主「guotianqing」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接

Linux网络工具

nethogs: 按进程查看流量占用
iptraf: 按连接/端口查看流量
ifstat: 按设备查看流量
ethtool: 诊断工具
tcpdump: 抓包工具
ss: 连接查看工具
其他: dstat, slurm, nload, bmon