几种测试服务器间网速的方法

发布时间:2025-08-04 14:52

评测员会测试游戏的服务器稳定性 #生活乐趣# #游戏乐趣# #游戏评测#

3

Dec 2020

几种测试服务器间网速的方法

VPS教程tlanyan

本文介绍几种实用的测试服务器间网速的方法。

准备工作

假设有A、B两台服务器,我们在A服务器上测试从B下载文件的速度。

首先在B服务器上生成大小为1GB的测试文件:

[root@node2 ~]# dd bs=1024K count=1024 if=/dev/random of=test1000m.bin 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 5.69383 s, 189 MB/s

接下来介绍两台服务器间的网速测试方法。

SCP测速

scp是用来拷贝远程主机文件的命令,其用法如下:

scp [-P 远程主机端口] user1@host1:file1 user2@host2:file2

文件传输过程中,会实时显示复制比例、已传输大小、传输速度和剩余时间,因此可以用来测试网速:

[root@node1 ~]# scp root@node2:~/test1000m.bin . test1000m.bin 14% 144MB 13.2MB/s 01:06 ETA

如果想计算平均网速,可以使用time命令:

time scp root@node2:~/test1000m.bin .

复制完成后,用总数据大小除以总耗时就能得到平均传输速率。

wget测速

wget可以下载网络网络文件,支持HTTP、HTTPS、FTP等多种协议。下载过程中同样会实时显示复制比例、已传输大小、传输速度和剩余时间。

由于HTTPS协议涉及到数据加解密,为避免CPU性能影响,推荐使用HTTP协议下载文件来测试服务器间的网速。首先在B服务器上运行静态文件服务器,这里我们使用python的SimpleHTTPServer模块来完成:

python -m SimpleHTTPServer # python3 请使用http.server模块 python3 -m http.server

该命令会启动一个简单的HTTP服务器,监听在8000端口。

接着在A服务器上测试下载速度:

[root@node1 ~]# wget http://node2:8000/test1000m.bin --2020-12-03 02:01:19-- http://raft:8000/test1000m.bin Resolving node2 (node2)... xxx.xxx.xx.xx Connecting to raft (node2)|xxx.xxx.xx.xx|:8000... connected. HTTP request sent, awaiting response... 200 OK Length: 1073741824 (1.0G) [application/octet-stream] Saving to: ‘test1000m.bin’ test1000m.bin 68%[======================> ] 696.59M 10.3MB/s eta 32s

同理,如果想得到平均速度,可以加上time命令,结束后再计算平均网速。

除了wget,也可以用功能更强大的curl

iperf3测速

和scp和wget/curl相比,iperf是专业的网络测速工具。目前大版本是3,因此命令行工具是 iperf3。

iperf3测速分服务端和客户端,两台机器上均需安装iperf3:

# CentOS系统安装 yum install -y iperf3 # Ubuntu/Debian系统 apt install -y iperf3

接着启动服务端,并放行端口:

iperf3 -s # iperf3默认监听5201端口,如果想换成其他端口请用-p参数: # iperf3 -p 8000 -s # 记得放行防火墙 firewall-cmd --add-port=5201/tcp

客户端连接到服务端测速:

iperf3 -c 服务器ip # 如果服务端端口不是5201,使用-p选项指定 # iperf3 -c 服务器ip -p 服务器端口

测速过程中服务端和客户端输出差不多,以下是客户端的一个示例输出:

[root@node1 ~]# iperf3 -c node2 Connecting to host node2, port 5201 [ 5] local xxxx port xxx connected to xxxx port xxx [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-1.00 sec 25.4 MBytes 213 Mbits/sec 0 467 KBytes [ 5] 1.00-2.00 sec 22.5 MBytes 189 Mbits/sec 0 469 KBytes [ 5] 2.00-3.00 sec 22.5 MBytes 189 Mbits/sec 0 467 KBytes [ 5] 3.00-4.00 sec 22.5 MBytes 189 Mbits/sec 0 481 KBytes [ 5] 4.00-5.00 sec 22.5 MBytes 189 Mbits/sec 0 492 KBytes [ 5] 5.00-6.00 sec 23.8 MBytes 199 Mbits/sec 0 481 KBytes [ 5] 6.00-7.00 sec 22.5 MBytes 189 Mbits/sec 0 481 KBytes [ 5] 7.00-8.00 sec 22.5 MBytes 189 Mbits/sec 0 475 KBytes [ 5] 8.00-9.00 sec 22.5 MBytes 189 Mbits/sec 0 512 KBytes [ 5] 9.00-10.00 sec 22.5 MBytes 189 Mbits/sec 0 467 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 229 MBytes 192 Mbits/sec 0 sender [ 5] 0.00-10.00 sec 226 MBytes 190 Mbits/sec receiver iperf Done.

可以看到,iperf3 测出来的速度比上面两个工具的都要高,更能反应服务器之间的真实带宽。

赞(3)

网址:几种测试服务器间网速的方法 https://klqsh.com/news/view/102924

相关内容

提升网速的路由器优化方法(UPnP、QoS、MTU、交换机模式、无线中继)
家庭宽带慢?试试这五个方法提升网速
如何应对服务器突然断电
家里网速慢怎么办?别烦恼,这几招让你轻松恢复高速网络!
提高家用路由器网速的方法(优化家庭网络体验)
家里的网速越来越慢?试试这几招,轻松提速!
快速打扫房间的9种方法
家里路由器网速太慢怎么办(快速提升家庭网络速度的方法)
如何提高家庭网速速度(15个有效方法帮你解决家里网速慢的问题)
家用电器检修与售后服务全攻略

随便看看