Tôi đã thiết lập tổng cộng bốn máy chủ trong trung tâm dữ liệu dựa trên đám mây. Chúng chạy CentOS hoặc Ubuntu Linux. Tôi cần đảm bảo hiệu suất hệ thống tệp theo cụm ở mức hợp lý vì máy chủ của tôi được chia sẻ với những người dùng khác. Làm cách nào để kiểm tra tốc độ băng thông mạng giữa hai máy chủ Linux bằng tùy chọn dòng lệnh cho mạng LAN/VLAN riêng?
Bạn có thể kiểm tra tốc độ băng thông mạng/thông lượng mạng giữa Ubuntu/CentOS/Debian/Fedora Linux hoặc Unix bằng lệnh iperf. Các lệnh Iperf hiển thị thông tin về băng thông, độ trễ, sự gián đoạn và mất datagram. Nó là một công cụ để thực hiện các phép đo thông lượng mạng. Nó có thể kiểm tra thông lượng TCP hoặc UDP. Để thực hiện kiểm tra iperf, người dùng phải thiết lập cả máy chủ (để loại bỏ lưu lượng truy cập) và máy khách (để tạo lưu lượng truy cập). Bài viết này sẽ giải thích cách kiểm tra tốc độ mạng/thông lượng mạng giữa hai máy chủ Linux.
Dưới đây là ví dụ của tôi được thiết lập để kiểm tra tốc độ mạng/thông lượng mạng giữa hai máy chủ Linux.
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-14286942-2024-04-22-17137501751.jpg)
1. Bước 1 – Cài đặtBạn cần cài đặt iperf theo phiên bản phân phối Linux của bạn. Có hai phiên bản của iperf:
Iperf/iperf3 hoạt động trên Linux, Unix, Windows, *BSD và các hệ điều hành khác.
1.1. Cài đặt iperf trên máy chủ Ubuntu/Debian LinuxNhập lệnh apt-get/apt sau để cài đặt iperf trên cả hai máy chủ:
$ sudo apt-get update
$ sudo apt-get install iperf
Đây là những gì chúng ta thấy trên hệ thống Ubuntu 20.04 LTS:
[sudo] password for vivek:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
iperf
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 76.5 kB of archives.
After this operation, 213 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 iperf amd64 2.0.13+dfsg1-1build1 [76.5 kB]
Fetched 76.5 kB in 1s (70.5 kB/s)
Selecting previously unselected package iperf.
(Reading database ... 344795 files and directories currently installed.)
Preparing to unpack .../iperf_2.0.13+dfsg1-1build1_amd64.deb ...
Unpacking iperf (2.0.13+dfsg1-1build1) ...
Setting up iperf (2.0.13+dfsg1-1build1) ...
Processing triggers for man-db (2.9.1-1) ...
Lưu ý về việc cài đặt iperf3 trên Debian/Ubuntu Linux: Cũng có thể cài đặt iperf3 (phiên bản mới nhất) như sau:
$ sudo apt-get install iperf3
Đầu ra:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libiperf0
The following NEW packages will be installed:
iperf3 libiperf0
0 upgraded, 2 newly installed, 0 to remove and 23 not upgraded.
Need to get 86.2 kB of archives.
After this operation, 294 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 libiperf0 amd64 3.7-3 [72.0 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 iperf3 amd64 3.7-3 [14.2 kB]
Fetched 86.2 kB in 1s (97.4 kB/s)
Selecting previously unselected package libiperf0:amd64.
(Reading database ... 344807 files and directories currently installed.)
Preparing to unpack .../libiperf0_3.7-3_amd64.deb ...
Unpacking libiperf0:amd64 (3.7-3) ...
Selecting previously unselected package iperf3.
Preparing to unpack .../iperf3_3.7-3_amd64.deb ...
Unpacking iperf3 (3.7-3) ...
Setting up libiperf0:amd64 (3.7-3) ...
Setting up iperf3 (3.7-3) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
1.2. Cài đặt iperf trên máy chủ Linux mới nhất/RHEL/CentOS 8 của FedoraNhập lệnh dnf sau để cài đặt iperf trên cả hai máy chủ:
$ sudo dnf install iperf
Lưu ý về việc cài đặt iperf3 trên CentOS/RHEL/SL/Oracle Linux: Nhập lệnh sau:
$ sudo dnf install iperf3
1.3. Cài đặt iperf trên máy chủ CentOS/RHEL/Oracle/Scientific LinuxNhập lệnh yum sau để cài đặt iperf trên cả hai máy chủ (trước tiên hãy bật repo EPEL cho CentOS/RHEL 7.x):
$ sudo yum install iperf
Nếu bạn đang sử dụng phiên bản mới nhất của Fedora và CentOS/RHEL 8.x, hãy thử lệnh dnf như sau:
$ sudo dnf install iperf3
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-207465336-2024-04-22-17137506631.jpg)
Lưu ý về việc cài đặt iperf3 trên CentOS/RHEL/SL/Oracle Linux: Nhập lệnh sau:
$ sudo yum install iperf3
2. Bước 2 – Khởi động máy chủ iperf trên serverA (chế độ máy chủ)Nhập lệnh sau để chạy iperf ở chế độ máy chủ:
iperf -s
Hoặc
iperf3 -s
Đầu ra mẫu:
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-504005579-2024-04-22-17137508161.jpg)
Vui lòng ghi lại cổng TCP #5001.
Lưu ý về cấu hình tường lửa: Xin lưu ý rằng bạn phải mở cổng TCP 5001 trên máy chủ A. Xem cách sử dụng ufw để mở cổng trên Ubuntu/Debian Linux:
$ sudo ufw allow from 192.168.149.0/24 to 192.168.149.69 port 5001 proto tcp
Người dùng CentOS/RHEL/Fedora cần chuyển sang bằng firewallD. Xem cách thiết lập tường lửa bằng firewallD trên CentOS 8:
sudo firewall-cmd --zone=public --add-port=5001/tcp --permanent
Cũng có thể thay đổi cổng bằng cách chuyển tùy chọn -p như sau (ví dụ: mở và sử dụng cổng TCP 2323):
iperf -s -p 2323
iperf3 -s -p 4242
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-415534275-2024-04-22-17137510111.jpg)
3. Bước 3 – Khởi động máy chủ iperf trên serverB (chế độ máy khách)Nhập lệnh sau để chạy ở chế độ máy khách, kết nối với 192.168.149.69:
iperf -c {ip-address-of-serverA-here}
iperf -c {ip-address-of-serverA-here} -p {tcp-port}
iperf -c 192.168.149.69 -p 2323
iperf -c 192.168.149.69
Hoặc
iperf3 -c {ip-address-of-serverA-here}
iperf3 -c {ip-address-of-serverA-here} -p {tcp-port}
iperf3 -c 192.168.149.69 -p 2323
iperf3 -c 192.168.149.69
Đầu ra mẫu:
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-442605124-2024-04-22-17137512501.jpg)
3.1. Cách sử dụng UDP thay vì TCPVề phía máy chủ:
iperf -s -u
Về phía máy khách:
iperf -c 192.168.149.69 -u
3.2. Cách đặt số lượng luồng máy khách song song để chạy (tùy chọn chế độ máy khách)Truyền tùy chọn -P:
iperf -c 192.168.149.69 -P 3
Bạn cũng có thể đặt thời gian tính bằng giây để truyền trong (10 giây mặc định) như sau:
iperf -c 192.168.149.69 -P 3 -t 30
Đầu ra mẫu:
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-493770385-2024-04-22-17137515331.jpg)
Đây là đầu ra từ iperf3:
## ở phía máy chủ ##
iperf3 -s
## về phía máy khách ##
iperf3 -c 192.168.149.69
Đầu ra mẫu:
(https://image.vietnetwork.vn/uploads/VietNetwork.Vn-105337882-2024-04-22-17137516681.jpg)
3.3. Nhận trợ giúp thật dễ dàng từ các lệnh sau đâyNhập lệnh sau:
$ man iperf
$ man iperf3
$ iperf --help
$ iperf3 --help
Server or Client:
-p, --port # server port to listen on/connect to
-f, --format [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits
-i, --interval # seconds between periodic throughput reports
-F, --file name xmit/recv the specified file
-A, --affinity n/n,m set CPU affinity
-B, --bind <host> bind to the interface associated with the address <host>
-V, --verbose more detailed output
-J, --json output in JSON format
--logfile f send output to a log file
--forceflush force flushing output at every interval
-d, --debug emit debugging output
-v, --version show version information and quit
-h, --help show this message and quit
Server specific:
-s, --server run in server mode
-D, --daemon run the server as a daemon
-I, --pidfile file write PID file
-1, --one-off handle one client connection then exit
--rsa-private-key-path path to the RSA private key used to decrypt
authentication credentials
--authorized-users-path path to the configuration file containing user
credentials
Client specific:
-c, --client <host> run in client mode, connecting to <host>
--sctp use SCTP rather than TCP
-X, --xbind <name> bind SCTP association to links
--nstreams # number of SCTP streams
-u, --udp use UDP rather than TCP
--connect-timeout # timeout for control connection setup (ms)
-b, --bitrate #[KMG][/#] target bitrate in bits/sec (0 for unlimited)
(default 1 Mbit/sec for UDP, unlimited for TCP)
(optional slash and packet count for burst mode)
--pacing-timer #[KMG] set the timing for pacing, in microseconds (default 1000)
--fq-rate #[KMG] enable fair-queuing based socket pacing in
bits/sec (Linux only)
-t, --time # time in seconds to transmit for (default 10 secs)
-n, --bytes #[KMG] number of bytes to transmit (instead of -t)
-k, --blockcount #[KMG] number of blocks (packets) to transmit (instead of -t or -n)
-l, --length #[KMG] length of buffer to read or write
(default 128 KB for TCP, dynamic or 1460 for UDP)
--cport <port> bind to a specific client port (TCP and UDP, default: ephemeral port)
-P, --parallel # number of parallel client streams to run
-R, --reverse run in reverse mode (server sends, client receives)
--bidir run in bidirectional mode.
Client and server send and receive data.
-w, --window #[KMG] set window size / socket buffer size
-C, --congestion <algo> set TCP congestion control algorithm (Linux and FreeBSD only)
-M, --set-mss # set TCP/SCTP maximum segment size (MTU - 40 bytes)
-N, --no-delay set TCP/SCTP no delay, disabling Nagle's Algorithm
-4, --version4 only use IPv4
-6, --version6 only use IPv6
-S, --tos N set the IP type of service, 0-255.
The usual prefixes for octal and hex can be used,
i.e. 52, 064 and 0x34 all specify the same value.
--dscp N or --dscp val set the IP dscp value, either 0-63 or symbolic.
Numeric values can be specified in decimal,
octal and hex (see --tos above).
-L, --flowlabel N set the IPv6 flow label (only supported on Linux)
-Z, --zerocopy use a 'zero copy' method of sending data
-O, --omit N omit the first n seconds
-T, --title str prefix every output line with this string
--extra-data str data string to include in client and server JSON
--get-server-output get results from server
--udp-counters-64bit use 64-bit counters in UDP test packets
--repeating-payload use repeating pattern in payload, instead of
randomized payload (like in iperf2)
--username username for authentication
--rsa-public-key-path path to the RSA public key used to encrypt
authentication credentials
[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at: https://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
Bài viết này đã giải thích cách thực hiện kiểm tra tốc độ băng thông mạng/thông lượng mạng giữa hai máy chủ Linux hoặc Unix bằng công cụ iperf3/iperf. Các bạn cũng có thể xem thêm tài liệu trực tuyến iperf và mã nguồn iperf3 để biết thêm thông tin.