mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-09 01:30:10 +08:00
Merge pull request #9696 from jessie-pang/master
20180306 How To Check All Running Services In Linux.md
This commit is contained in:
commit
6cea90b920
@ -1,31 +1,30 @@
|
||||
Translating by jessie-pang
|
||||
|
||||
How To Check All Running Services In Linux
|
||||
如何查看 Linux 中所有正在运行的服务
|
||||
======
|
||||
|
||||
There are many ways and tools to check and list all running services in Linux. Usually most of the administrator use `service service-name status` or `/etc/init.d/service-name status` for sysVinit system and `systemctl status service-name` for systemd systems.
|
||||
|
||||
The above command clearly shows that the mentioned service is running on server or not. It is very simple and basic command that should known by every Linux administrator.
|
||||
有许多方法和工具可以查看 Linux 中所有正在运行的服务。大多数管理员会在 sysVinit 系统中使用 `service service-name status` 或 `/etc/init.d/service-name status`,而在 systemd 系统中使用 `systemctl status service-name`。
|
||||
|
||||
If you are new to your environment and you don’t know what services are running on the system. How do you check?
|
||||
以上命令可以清楚地显示该服务是否在服务器上运行,这也是每个 Linux 管理员都该知道的非常简单和基础的命令。
|
||||
|
||||
Yes, we can check this. This will will help us to understand what are the services are running on the system and whether it’s necessary or need to disable.
|
||||
如果你对系统环境并不熟悉,也不清楚系统在运行哪些服务,你会如何检查?
|
||||
|
||||
### What Is SysVinit
|
||||
是的,我们的确有必要这样检查一下。这将有助于我们了解系统上运行了什么服务,以及哪些是必要的、哪些需要被禁用。
|
||||
|
||||
init (short for initialization) is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down.
|
||||
### 什么是 SysVinit
|
||||
|
||||
SysVinit is an old and traditional init system and system manager for old systems. Most of the latest distributions were adapted to systemd system due to some of the long pending issues on sysVinit system.
|
||||
init(初始化 initialization 的简称)是在系统启动期间运行的第一个进程。Init 是一个守护进程,它将持续运行直至关机。
|
||||
|
||||
### What Is systemd
|
||||
SysVinit 是早期传统的 init 系统和系统管理器。由于 sysVinit 系统上一些长期悬而未决的问题,大多数最新的发行版都适用于 systemd 系统。
|
||||
|
||||
systemd is a new init system and system manager which is become very popular and widely adapted new standard init system by most of Linux distributions. Systemctl is a systemd utility which is help us to manage systemd system.
|
||||
### 什么是 systemd
|
||||
|
||||
### Method-1: How To Check Running Services In sysVinit System
|
||||
systemd 是一个新的 init 系统以及系统管理器,它已成为大多数 Linux 发行版中非常流行且广泛适应的新的标准 init 系统。Systemctl 是一个 systemd 管理工具,它可以帮助我们管理 systemd 系统。
|
||||
|
||||
The below command helps us to check and list all running services in sysVinit system.
|
||||
### 方法一:如何在 sysVinit 系统中查看运行的服务
|
||||
|
||||
If you have many number of services, i would advise you to use file view commands such as less, more, etc commands for clear view.
|
||||
以下命令可以帮助我们列出 sysVinit 系统中所有正在运行的服务。
|
||||
|
||||
如果服务很多,我建议使用文件视图命令,如 less、more 等,以便得到清晰的结果。
|
||||
```
|
||||
# service --status-all
|
||||
or
|
||||
@ -103,7 +102,7 @@ zabbix_agentd (pid 2150 2149 2148 2147 2146 2140) is running...
|
||||
|
||||
```
|
||||
|
||||
Run the following command to view only running services in the system.
|
||||
执行以下命令,可以只查看正在运行的服务。
|
||||
```
|
||||
# service --status-all | grep running
|
||||
|
||||
@ -120,14 +119,14 @@ xinetd (pid 485) is running...
|
||||
|
||||
```
|
||||
|
||||
Run the following command to view the particular service status.
|
||||
运行以下命令以查看指定服务的状态。
|
||||
```
|
||||
# service --status-all | grep httpd
|
||||
httpd (pid 627) is running...
|
||||
|
||||
```
|
||||
|
||||
Alternatively use the following command to view the particular service status.
|
||||
或者,使用以下命令也可以查看指定服务的状态。
|
||||
```
|
||||
# service httpd status
|
||||
|
||||
@ -135,7 +134,7 @@ httpd (pid 627) is running...
|
||||
|
||||
```
|
||||
|
||||
Use the following command to view the list of running services enabled in boot.
|
||||
使用以下命令查看系统启动时哪些服务会被启用。
|
||||
```
|
||||
# chkconfig --list
|
||||
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
||||
@ -186,9 +185,9 @@ xinetd based services:
|
||||
|
||||
```
|
||||
|
||||
### Method-2: How To Check Running Services In systemd System
|
||||
### 方法二:如何在 systemd 系统中查看运行的服务
|
||||
|
||||
The below command helps us to check and list all running services in “systemd” system.
|
||||
以下命令帮助我们列出 systemd 系统中所有服务。
|
||||
```
|
||||
# systemctl
|
||||
|
||||
@ -240,15 +239,14 @@ The below command helps us to check and list all running services in “systemd
|
||||
|
||||
```
|
||||
|
||||
* **`UNIT`** Unit describe about the corresponding systemd unit name.
|
||||
* **`LOAD`** This describes whether the corresponding unit currently loaded in memory or not.
|
||||
* **`ACTIVE`** It’s indicate whether the unit is active or not.
|
||||
* **`SUB`** It’s indicate whether the unit is running state or not.
|
||||
* **`DESCRIPTION`** A short description about the unit.
|
||||
* **`UNIT`** 相应的 systemd 单元名称
|
||||
* **`LOAD`** 相应的单元是否被加载到内存中
|
||||
* **`ACTIVE`** 该单元是否处于活动状态
|
||||
* **`SUB`** 该单元是否处于运行状态(LCTT 译者注:是较于 ACTIVE 更加详细的状态描述,不同的单元类型有不同的状态。)
|
||||
* **`DESCRIPTION`** 关于该单元的简短描述
|
||||
|
||||
|
||||
|
||||
The below option help you to list units based on the type.
|
||||
以下选项可根据类型列出单元。
|
||||
```
|
||||
# systemctl list-units --type service
|
||||
UNIT LOAD ACTIVE SUB DESCRIPTION
|
||||
@ -269,7 +267,7 @@ The below option help you to list units based on the type.
|
||||
cups.service loaded active running CUPS Scheduler
|
||||
dbus.service loaded active running D-Bus System Message Bus
|
||||
fwupd.service loaded active running Firmware update daemon
|
||||
[email protected] loaded active running Getty on tty1
|
||||
[email protected] loaded active running Getty on tty1
|
||||
grub-common.service loaded active exited LSB: Record successful boot for GRUB
|
||||
irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems
|
||||
keyboard-setup.service loaded active exited Set the console keyboard layout
|
||||
@ -277,7 +275,7 @@ The below option help you to list units based on the type.
|
||||
|
||||
```
|
||||
|
||||
The below option help you to list units based on the state. It’s similar to the above output but straight forward.
|
||||
以下选项可帮助您根据状态列出单位,输出与前例类似但更直截了当。
|
||||
```
|
||||
# systemctl list-unit-files --type service
|
||||
|
||||
@ -290,31 +288,31 @@ alsa-utils.service masked
|
||||
anacron-resume.service enabled
|
||||
anacron.service enabled
|
||||
apache-htcacheclean.service disabled
|
||||
[email protected] disabled
|
||||
[email protected] disabled
|
||||
apache2.service enabled
|
||||
[email protected] disabled
|
||||
[email protected] disabled
|
||||
apparmor.service enabled
|
||||
[email protected] static
|
||||
[email protected] static
|
||||
apport.service generated
|
||||
apt-daily-upgrade.service static
|
||||
apt-daily.service static
|
||||
aptik-battery-monitor.service generated
|
||||
atop.service enabled
|
||||
atopacct.service enabled
|
||||
[email protected] enabled
|
||||
[email protected] enabled
|
||||
avahi-daemon.service enabled
|
||||
bluetooth.service enabled
|
||||
|
||||
```
|
||||
|
||||
Run the following command to view the particular service status.
|
||||
运行以下命令以查看指定服务的状态。
|
||||
```
|
||||
# systemctl | grep apache2
|
||||
apache2.service loaded active running The Apache HTTP Server
|
||||
|
||||
```
|
||||
|
||||
Alternatively use the following command to view the particular service status.
|
||||
或者,使用以下命令也可查看指定服务的状态。
|
||||
```
|
||||
# systemctl status apache2
|
||||
● apache2.service - The Apache HTTP Server
|
||||
@ -339,7 +337,7 @@ Mar 06 12:39:10 magi-VirtualBox systemd[1]: Reloaded The Apache HTTP Server.
|
||||
|
||||
```
|
||||
|
||||
Run the following command to view only running services in the system.
|
||||
执行以下命令,只查看正在运行的服务。
|
||||
```
|
||||
# systemctl | grep running
|
||||
acpid.path loaded active running ACPI Events Check
|
||||
@ -359,7 +357,7 @@ Run the following command to view only running services in the system.
|
||||
cups.service loaded active running CUPS Scheduler
|
||||
dbus.service loaded active running D-Bus System Message Bus
|
||||
fwupd.service loaded active running Firmware update daemon
|
||||
[email protected] loaded active running Getty on tty1
|
||||
[email protected] loaded active running Getty on tty1
|
||||
irqbalance.service loaded active running LSB: daemon to balance interrupts for SMP systems
|
||||
lightdm.service loaded active running Light Display Manager
|
||||
ModemManager.service loaded active running Modem Manager
|
||||
@ -368,7 +366,7 @@ Run the following command to view only running services in the system.
|
||||
|
||||
```
|
||||
|
||||
Use the following command to view the list of running services enabled in boot.
|
||||
使用以下命令查看系统启动时会被启用的服务列表。
|
||||
```
|
||||
# systemctl list-unit-files | grep enabled
|
||||
acpid.path enabled
|
||||
@ -380,7 +378,7 @@ apache2.service enabled
|
||||
apparmor.service enabled
|
||||
atop.service enabled
|
||||
atopacct.service enabled
|
||||
[email protected] enabled
|
||||
[email protected] enabled
|
||||
avahi-daemon.service enabled
|
||||
bluetooth.service enabled
|
||||
console-setup.service enabled
|
||||
@ -390,7 +388,7 @@ cups.service enabled
|
||||
display-manager.service enabled
|
||||
dns-clean.service enabled
|
||||
friendly-recovery.service enabled
|
||||
[email protected] enabled
|
||||
[email protected] enabled
|
||||
gpu-manager.service enabled
|
||||
keyboard-setup.service enabled
|
||||
lightdm.service enabled
|
||||
@ -403,7 +401,7 @@ NetworkManager.service enabled
|
||||
|
||||
```
|
||||
|
||||
systemd-cgtop show top control groups by their resource usage such as tasks, CPU, Memory, Input, and Output.
|
||||
systemd-cgtop 按资源使用情况(任务、CPU、内存、输入和输出)列出控制组。
|
||||
```
|
||||
# systemd-cgtop
|
||||
|
||||
@ -437,7 +435,7 @@ Control Group Tasks %CPU Memory Input/s Output/s
|
||||
|
||||
```
|
||||
|
||||
Also we can check the running services using pstree command (Output from SysVinit system).
|
||||
同时,我们可以使用 pstree 命令(输出来自 SysVinit 系统)查看正在运行的服务。
|
||||
```
|
||||
# pstree
|
||||
init-|-crond
|
||||
@ -454,7 +452,7 @@ init-|-crond
|
||||
|
||||
```
|
||||
|
||||
Also we can check the running services using pstree command (Output from systemd system).
|
||||
我们还可以使用 pstree 命令(输出来自 systemd 系统)查看正在运行的服务。
|
||||
```
|
||||
# pstree
|
||||
systemd─┬─ModemManager─┬─{gdbus}
|
||||
@ -490,9 +488,9 @@ systemd─┬─ModemManager─┬─{gdbus}
|
||||
|
||||
```
|
||||
|
||||
### Method-3: How To Check Running Services In systemd System using chkservice
|
||||
### 方法三:如何使用 chkservice 在 systemd 系统中查看正在运行的服务
|
||||
|
||||
chkservice is a new tool for managing systemd units in terminal. It requires super user privileges to manage the units.
|
||||
chkservice 是一个管理系统单元的终端工具,需要超级用户权限。
|
||||
```
|
||||
# chkservice
|
||||
|
||||
@ -500,7 +498,7 @@ chkservice is a new tool for managing systemd units in terminal. It requires sup
|
||||
|
||||
![][1]
|
||||
|
||||
To view help page, hit `?` button. This will shows you available options to manage the systemd services.
|
||||
要查看帮助页面,请单击 `?` 按钮,它将显示管理 systemd 服务的可用选项。
|
||||
![][2]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -508,7 +506,7 @@ To view help page, hit `?` button. This will shows you available options to mana
|
||||
via: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[jessie-pang](https://github.com/jessie-pang)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user