关于linux:12个好用的-linux-命令行监控工具

2次阅读

共计 3779 个字符,预计需要花费 10 分钟才能阅读完成。

Linux 管理员不是一件容易的工作。放弃零碎失常运行须要大量的工夫、急躁和艰辛的工作。然而 Linux 系统管理员能够稍作喘息,因为他们有一些命令行监督工具的帮忙。这些工具帮忙他们监督 Linux 服务器性能,并在发现异常时修复任何异样。在本文中,咱们将钻研用于监督 Linux 性能的前 12 个命令行工具。

(1) top

毫无疑问,top 命令是监督 Linux 排第一位的命令行工具。它是全世界 Linux 系统管理员应用最宽泛的命令之一。它以有序的列表疾速提供所有正在运行的过程的详细信息。该列表还会实时更新。它不仅显示过程名,还显示内存应用状况和 CPU 应用状况等。

同步浏览: 25 Top Command Examples to Monitor Linux Server Performance

(2) vmstat

VMSTST 是命令行实用程序,在咱们的列表中占据第二的地位。它的次要工作是显示虚拟内存统计信息。它还能够帮忙您显示各种信息,包含所有零碎过程、CPU 流动、分页、块 IO、内核线程和磁盘等。vmstat 是简直所有 Linux 发行版的默认装置的一部分,因而在装置后能够间接应用它。

(3) lsof

如果您想查看零碎中以后关上的所有文件,则须要应用 lsof 命令。它还用于监督以后正在应用的所有过程。该命令的次要长处之一是:当磁盘无奈卸载时,它能够帮忙管理员查看以后应用的文件。lsof 命令在零碎默认装置后不可用,能够应用以下命令进行装置:

For CentOS / RHEL

$ sudo yum install -y lsof   // CentOS 7 / RHEL 7 or before
$ sudo dnf install -y lsof   // CentOS 8 / RHEL 8

For Ubuntu / Debian

$ apt-get install -y lsof
Or
$ apt-get install -y lsof

要应用 lsof 命令,键入 lsof 并回车

同步浏览 : 18 Quick‘lsof’command examples for Linux Geeks

(4) tcpdump

tcpdump 是另一个命令行实用程序,容许 Linux 系统管理员和网络工程师监督通过网络传输的所有 TCP/IP 数据包。应用 tcpdump,也能够将所有数据包保留在独自的文件中以进行剖析。

tcpdump 不是操作系统默认装置的一部分,通过以下命令装置它

$ sudo yum install tcpdump -y    // CentOS 7 / RHEL 7 or before
$ sudo dnf install tcpdump -y    //CentOS 8 / RHEL 8
$ sudo apt install tcpdump -y    // Ubuntu / Debian

要开始在特定接口上捕捉数据包,请运行以下命令,

# tcpdump -i enp0s3

同步浏览 : How to capture and analyze packets with tcpdump command on Linux

(5) netstat

netstat 是用于网络故障排除的最古老的命令行实用程序之一。应用 netstat,咱们能够很容易地找到网络连接、路由表、以太网卡统计数据和假装连贯。换句话说,它还能够帮忙您疾速排除任何网络相干问题。在最新的 Linux 发行版中,netstat 不是默认装置的一部分。应用上面的命令在不同的 Linux 发行版上装置它。

For CentOS 8 / RHEL 8

$ sudo dnf install net-tools -y

For Ubuntu / Debian

$ sudo apt install -y net-tools

运行以下命令以列出零碎上的所有 TCP 连贯

# netstat -tunlp

(6) htop

htop 是另一个功能丰富的命令行实用程序,它提供对 linux 零碎中各种重要资源的实时监督。与 top 命令相比,htop 是一个十分即兴的版本,甚至提供了黑白编码的输入,以便于了解。它还反对程度和垂直查看,还容许管理员治理过程。

同步浏览: How to Use htop to Monitor Linux System Processes

要在 linux 零碎上装置 htop,请执行以下命令

$ sudo yum install -y htop   // CentOS 7 / RHEL 7 or before
$ sudo dnf install -y htop  // CentOS 8 / RHEL 8 or before
$ sudo apt install -y htop  // Ubuntu / Debian

htop 命令的示例输入

$ htop

(7) iotop

iotop 是另一个收费的命令行实用程序,容许管理员监督磁盘 I/O 应用详细信息。它相似于 top 和 htop 命令,它的次要长处之一是它为零碎中的特定线程或过程提供了细节。因而,系统管理员能够轻松地辨认导致大量服务器写入 I/O 过程。

要在不同的 Linux 发行版上装置 iotop,请运行

$ sudo dnf install -y iotop    // CentOS 8 / RHEL 8
$ sudo yum install -y iotop    // CentOS 7 / RHEL 7
$ sudo apt install -y iotop    // Ubuntu / Debian

要开始应用 iotop 实用程序,请在命令行中键入 iotop 并按回车键

$ iotop

(8) iostat

iostat 是一个 Linux 命令行工具,可提供无关设施和分区零碎输出 / 输入的具体统计信息。Linux 系统管理员还能够应用此命令行工具来监督本地和近程磁盘(NFS)的性能。

同步浏览: How to Monitor Linux Systems Performance with iostat command

iostat 命令的样本输入如下

$ iostat

(9) goaccess

Goaccess 是一个开源的实时日志查看和剖析的命令行工具。它简直实用于所有 Linux 发行版,它能够用来查看所有 web 服务器 (Nginx, Apache, Amazon S3 和 CloudFront 等) 的实时日志。

Installation of Goaccess on CentOS 8 / RHEL 8

$ wget https://pkgs.dyn.su/el8/base/x86_64/goaccess-1.3-3.el8.x86_64.rpm
$ sudo dnf localinstall goaccess-1.3-3.el8.x86_64.rpm  -y

For Ubuntu / Debian

$ sudo apt get install goaccess

剖析 Apache web 服务器的实时日志,运行 goaccess 命令

$ sudo goaccess /var/log/httpd/access_log --log-format=COMBINED

(10) glances

glances 是一个收费的跨平台命令行工具,用于监督 linux 零碎。简直所有 Linux 发行版都能够应用 glances,它能够收集除监督之外的零碎统计信息。它是用 python 编写的,利用 psutil 库从零碎中检索有用的信息。glances 有三种不同的用法

  • Standalone command line utility
  • Client and Server
  • Web Server

在 CentOS / RHEL 零碎上装置 glances

$ sudo dnf install -y glances            // CentOS 8 / RHEL 8
$ sudo yum install -y glances            // CentOS 7 / RHEL 7

在 Ubuntu / Debian 零碎上装置 glances

$ sudo apt get install -y glances

要开始应用 glances,输出 glances 命令

$ glances

(11) iptraf

iptraf 是一个命令行实用程序,提供对以太网卡和网络的实时监督。应用 iptraf,零碎和网络管理员能够收集很多细节,包含以下内容:

  • TCP traffic summary
  • ICMP
  • IP traffic
  • UDP traffic
  • Interface activity
  • Statistical breakdowns
  • Detailed interface statistics

与 iftop 等其余命令相比,iptraf 提供了更具体的分类和统计信息。iptraf 不是操作系统默认装置的一部分,所以要装置它,请运行以下命令

在 CentOS / RHEL 零碎上装置 iptraf-ng

$ sudo dnf install -y iptraf-ng
Or
$ sudo yum install -y iptraf-ng

在 Ubuntu / Debian 零碎上装置 iptraf-ng

$ sudo apt install -y iptraf-ng

要启动 iptraf 实用程序,输出 iptraf-ng 命令并抉择以太网卡

$ iptraf-ng

(12) iftop

iftop 是一个简略的命令行工具,显示 Linux 零碎以太网卡上的带宽应用状况。零碎和网络管理员应用此工具进行带宽监督。应用 iftop,您能够在它侦听的第一个网络接口中查看源和指标。

在 CentOS / RHEL 零碎上装置 iftop

$ sudo dnf install -y iftop
$ sudo yum install -y iftop

在 Ubuntu / Debian 零碎上装置 iftop

$ sudo apt install -y iftop

输出 iftop 以启动该实用程序,如下所示

$ iftop

我的开源我的项目

  • course-tencent-cloud(酷瓜云课堂 – gitee 仓库)
  • course-tencent-cloud(酷瓜云课堂 – github 仓库)
正文完
 0