透過 ssh 運行 iperf

透過 ssh 運行 iperf

ubuntu我正在嘗試對我沒有權限的兩台伺服器之間的網路連接進行基準測試root

我確實成功下載並啟動iperf-2.0.9了兩個盒子。

我的問題是我無法打開連接埠(透過防火牆)。

所以客戶端無法連接到伺服器。

有什麼辦法可以透過兩者之間的 ssh 連接來完成這項工作嗎?轉送埠什麼的?

任何解決方案將不勝感激!

筆記:我scp來回做了幾個文件...但這還遠不及iperf能給我的

答案1

iperf 允許用戶在三個位置指定端口 - 一個是伺服器偵聽的端口,一個是客戶端連接的位置,還有一個是客戶端為-d/--dualtest選項生成迷你伺服器的位置。為此,我們需要這三者。

雖然可以用更少的數量來完成此任務,但我發現指定所有連接埠更容易,這樣我就可以更好地追蹤它們。在此設定中,我將假設設定如下所示:

-----------            -------          -------
| Control |  SSH #1,2  | Box |  SSH #3  | Box |
|   Box   | ---------> | #1  | -------> | #2  |
-----------            -------          -------

「控制盒」也可能可以直接存取 2 號盒上的 SSH,但我們不需要它。為此,框 #2 將是偵聽 7001 的 iperf 伺服器,框 2 將是偵聽端口 7002 的客戶端。

首先,連接到框 #1。接下來,您需要連接到 Box #2。在此嵌套會話中,您將需要建立兩個連接埠隧道:一個正向和一個反向。執行此操作的 ssh 選項適用-L7001:localhost:7001於正向和-R7002:localhost:7002反向。由於 iperf 期望連接埠位於遠端主機上,因此每個隧道必須是對稱的(隧道兩端的連接埠號碼相同)。然後,啟動 iperf 伺服器偵聽連接埠 7001 ( iperf -s -p 7001)。

它可能看起來像這樣:

me@control$ ssh box1.example.com
box1$ ssh -L7001:localhost:7001 -R7002:localhost:7002 box2.example.com
box2$ iperf -s -p 7001
------------------------------------------------------------
Server listening on TCP port 7001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

啟動後,開啟 Box #1 的第二個會話。在這裡,在連接埠 7001 啟動一個到 localhost 的 iperf 用戶端,監聽連接埠為 7002(預設監聽連接埠是 5001,與伺服器一樣)。這表示客戶端將嘗試連接 localhost:7001 上的 iperf 伺服器,SSH 會抓取該伺服器並將其傳送至框 #2。然後,它啟動一個「迷你」iperf 伺服器,偵聽 7002。 .0.1(或::1,取決於配置),因此它將啟動一個連接到127.0.0.1:7002 的「迷你」客戶端。因為我們也設定了反向轉發,所以 ssh 也會搶佔此連線並將其傳送到框 1。

您的第二次會議可能如下所示:

(此範例的附註:我將不同測試的時間設為 30 秒;預設值就足夠了)

me@control$ ssh box1.example.com
box1$ iperf -c localhost -p 7001 -L 7002 -d -t 30
------------------------------------------------------------
Server listening on TCP port 7002
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to localhost, TCP port 7001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[  3] local 127.0.0.1 port 37014 connected with 127.0.0.1 port 7001
[  5] local 127.0.0.1 port 7002 connected with 127.0.0.1 port 51806
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-30.0 sec  1.26 GBytes   361 Mbits/sec
[  5]  0.0-30.2 sec  1.23 GBytes   349 Mbits/sec

當客戶端完成測試後,您的伺服器視窗可能如下所示:

...
box2$ iperf -s -p 7001
------------------------------------------------------------
Server listening on TCP port 7001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 127.0.0.1 port 7001 connected with 127.0.0.1 port 41997
------------------------------------------------------------
Client connecting to 127.0.0.1, TCP port 7002
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[  6] local 127.0.0.1 port 46864 connected with 127.0.0.1 port 7002
[ ID] Interval       Transfer     Bandwidth
[  6]  0.0-30.0 sec  1.23 GBytes   351 Mbits/sec
[  4]  0.0-30.2 sec  1.26 GBytes   359 Mbits/sec

警告:SSH 會扭曲感知的連線速度。在相同的兩台機器之間執行不含 SSH 的 iperf 會產生以下結果(這些機器具有相同的角色):

客戶:

box1$ iperf -c box2.example.com -d
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to box2.example.com, TCP port 5001
TCP window size:  306 KByte (default)
------------------------------------------------------------
[  3] local 172.20.0.1 port 45722 connected with 172.20.0.2 port 5001
[  5] local 172.20.0.1 port 5001 connected with 172.20.0.2 port 60909
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.01 GBytes   866 Mbits/sec
[  5]  0.0-10.0 sec   823 MBytes   689 Mbits/sec

伺服器:

box2$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 172.20.0.2 port 5001 connected with 172.20.0.1 port 45722
------------------------------------------------------------
Client connecting to 172.20.0.1, TCP port 5001
TCP window size:  306 KByte (default)
------------------------------------------------------------
[  6] local 172.20.0.2 port 60909 connected with 172.20.0.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  6]  0.0-10.0 sec   823 MBytes   690 Mbits/sec
[  4]  0.0-10.0 sec  1.01 GBytes   864 Mbits/sec

我嘗試修改 TCP 視窗設定、緩衝區長度、TCP_NODELAY 並使用多個 SSH 會話,但開銷仍然存在。我也嘗試過 HPN-SSH,但實際上比常規 SSH 獲得了更好的性能,所以我認為在設定 HPN 時我錯過了一個設定。以單工而非雙工(選項-r/ --tradeoff(單獨進行雙向測試))執行 iperf 連線所得到的結果更接近連結速度,但仍具有顯著的 SSH 開銷。

話雖如此,如果您需要在這兩台機器之間創建橋樑並測量該橋樑的容量,那麼這個解決方案是完美的。如果您嘗試測量這些機器之間的原始吞吐量,這些測試提供的數字將小於(並且可能遠小於)連結速度。

相關內容