在 Ubuntu 22.04 上安装和配置 iotop
在这一步骤中,你将学习如何在 Ubuntu 22.04 系统上安装和配置 iotop
命令。
首先,更新软件包索引并安装 iotop
软件包:
sudo apt-get update
sudo apt-get install -y iotop
示例输出:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
...
Fetching 172 kB in 0s (0 B/s)
Extracting templates from packages: 100%
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
iotop
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 44.5 kB of archives.
After this operation, 141 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 iotop amd64 1.22-2 [44.5 kB]
Fetching packages...
Selecting previously unselected package iotop.
(Reading database ... 25105 files and directories currently installed.)
Preparing to unpack .../iotop_1.22-2_amd64.deb ...
Unpacking iotop (1.22-2) ...
Setting up iotop (1.22-2) ...
Processing triggers for man-db (2.10.2-1) ...
现在 iotop
已经安装完成,让我们来探索它的配置选项。iotop
不需要任何特定的配置,但你可以通过使用命令行选项来自定义其行为。
一些常用的 iotop
选项包括:
-o
:仅显示实际执行 I/O 的进程
-b
:以批处理模式运行,不使用 ncurses
-n NUM
:在结束前运行的迭代次数
-d DELAY
:每次迭代之间的延迟,单位为秒(默认 3 秒)
例如,要以批处理模式运行 iotop
并仅显示实际执行 I/O 的进程,可以使用以下命令:
sudo iotop -o -b
示例输出:
Total DISK READ: 0.00 B/s | Total DISK WRITE: 0.00 B/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
1234 be/4 labex 0.00 B/s 0.00 B/s 0.00 % 0.00 % iotop
5678 be/4 labex 0.00 B/s 0.00 B/s 0.00 % 0.00 % bash
9012 be/4 labex 0.00 B/s 0.00 B/s 0.00 % 0.00 % sleep 60
这将以批处理模式运行 iotop
,仅显示当前正在执行磁盘 I/O 的进程。
现在你已经安装并配置了 iotop
,接下来我们将进入下一步,学习如何使用 iotop
分析磁盘 I/O 使用情况。