diff --git a/translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md b/published/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md similarity index 60% rename from translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md rename to published/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md index ec3367d6ef..bcb25f74e6 100644 --- a/translated/tech/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md +++ b/published/20191220 How to Start, Stop - Restart Services in Ubuntu and Other Linux Distributions.md @@ -1,8 +1,8 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: reviewer: (wxy) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-11722-1.html) [#]: subject: (How to Start, Stop & Restart Services in Ubuntu and Other Linux Distributions) [#]: via: (https://itsfoss.com/start-stop-restart-services-linux/) [#]: author: (Sergiu https://itsfoss.com/author/sergiu/) @@ -10,37 +10,33 @@ 如何在 Ubuntu 和其他 Linux 发行版中启动、停止和重启服务 ====== -服务是必不可少的后台进程,它通常随系统启动,并在关机时关闭。 +![](https://img.linux.net.cn/data/attachment/album/201912/28/081645vee5lkult55kituu.jpg) -如果你是系统管理员,那么你会定期处理服务。 - -如果你是普通桌面用户,你可能会遇到需要重启服务的情况,例如[安装 Barrier 来用于在计算机之间共享鼠标和键盘][1]。或[在使用 ufw 设置防火墙][2]时。 +服务是必不可少的后台进程,它通常随系统启动,并在关机时关闭。如果你是系统管理员,那么你会定期处理服务。如果你是普通桌面用户,你可能会遇到需要重启服务的情况,例如[安装 Barrier 来用于在计算机之间共享鼠标和键盘][1]。或[在使用 ufw 设置防火墙][2]时。 今天,我将向你展示两种管理服务的方式。你将学习在 Ubuntu 或任何其他 Linux 发行版中启动、停止和重启服务。 -systemd 与 init +> systemd 与 init +> +> 如今,Ubuntu 和许多其他发行版都使用 systemd 而不是旧的 init。 +> +> 在 systemd 中,可以使用 `systemctl` 命令管理服务。 +> +> 在 init 中,你可以使用 `service` 命令管理服务。 +> +> 你会注意到,即使你的 Linux 系统使用 systemd,它仍然可以使用 `service` 命令(与 init 系统一起使用的)。这是因为 `service` 命令实际上已重定向到 `systemctl`。systemd 引入了向后兼容性,因为系统管理员们习惯使用 `service` 命令。 +> +> 在本教程中,我将同时展示 `systemctl` 和 `service` 命令。 -如今,Ubuntu 和许多其他发行版都使用 systemd 而不是旧的 init。 - -在 systemd 中,可以使用 systemctl 命令管理服务。 - -在 init 中,你可以使用 service 命令管理服务。 - -你会注意到,即使你的 Linux 系统使用 systemd,它仍然可以使用 service 命令(为了与 init 系统一起使用)。这是因为 service 命令实际上已重定向到 systemctl。systemd 引入了向后兼容性,因为系统管理员们习惯使用 service 命令。 - -在本教程中,我将同时展示 systemctl 和 service 命令。 - -_我的是 Ubuntu 18.04,但其他版本的过程也一样_。 +我用的是 Ubuntu 18.04,但其他版本的过程也一样。 ### 方法 1:使用 systemd 在 Linux 中管理服务 我从 systemd 开始,因为它被广泛接受。 -#### 1\. 列出所有服务 +#### 1、列出所有服务 -为了管理服务,你首先需要知道系统上有哪些服务可用。 - -你可以使用 systemd 命令列出 Linux 系统上的所有服务: +为了管理服务,你首先需要知道系统上有哪些服务可用。你可以使用 systemd 的命令列出 Linux 系统上的所有服务: ``` systemctl list-unit-files --type service -all @@ -48,9 +44,9 @@ systemctl list-unit-files --type service -all ![systemctl list-unit-files][3] -此命令将输出所有服务的状态。服务状态有启用、禁用、屏蔽(在取消掩码之前处于非活动状态)、静态和已生成。 +此命令将输出所有服务的状态。服务状态有启用enabled禁用disabled屏蔽masked(在取消屏蔽之前处于非活动状态)、静态static已生成generated。 -与 [grep 命令][4] 结合,你可以**仅显示正在运行的服务**: +与 [grep 命令][4] 结合,你可以仅显示正在运行的服务: ``` sudo systemctl | grep running @@ -60,9 +56,9 @@ sudo systemctl | grep running 现在,你知道了如何引用所有不同的服务,你可以开始主动管理它们。 -**注意:** 命令中的 **<service-name>** 应该用你想管理的服务名代替。(比如:network-manager、ufw 等) +**注意:** 下列命令中的 `` 应该用你想管理的服务名代替。(比如:network-manager、ufw 等) -#### 2\. 启动服务 +#### 2、启动服务 要在 Linux 中启动服务,你只需使用它的名字: @@ -70,15 +66,15 @@ sudo systemctl | grep running systemctl start ``` -#### 3\. 停止服务 +#### 3、停止服务 -要停止 systemd 服务,可以使用 systemctl 命令的 stop 选项: +要停止 systemd 服务,可以使用 `systemctl` 命令的 `stop` 选项: ``` systemctl stop ``` -#### 4\. 重启服务 +#### 4、重启服务 要重启 systemd 服务,可以使用: @@ -86,7 +82,7 @@ systemctl stop systemctl restart ``` -#### 5\. 检查服务状态 +#### 5、检查服务状态 你可以通过打印服务状态来确认你已经成功执行特定操作: @@ -104,7 +100,7 @@ systemctl status init 的命令和 systemd 的一样简单。 -#### 1\. 列出所有服务 +#### 1、列出所有服务 要列出所有 Linux 服务,使用: @@ -114,9 +110,9 @@ service --status-all ![service –status-all][7] -前面的 **[ – ]** 代表**禁用**,**[ + ]** 代表**启用**。 +前面的 `[ – ]` 代表**禁用**,`[ + ]` 代表**启用**。 -#### 2\. 启动服务 +#### 2、启动服务 要在 Ubuntu 和其他发行版中启动服务,使用命令: @@ -124,7 +120,7 @@ service --status-all service start ``` -#### 3\. 停止服务 +#### 3、停止服务 停止服务同样简单。 @@ -132,7 +128,7 @@ service start service stop ``` -#### 4\. 重启服务 +#### 4、重启服务 如果你想重启服务,命令是: @@ -140,9 +136,9 @@ service stop service restart ``` -#### 5\. 检查服务状态 +#### 5、检查服务状态 -此外,要检查是否达到了预期的结果,你可以输出服务**状态**: +此外,要检查是否达到了预期的结果,你可以输出服务状态: ``` service status @@ -152,9 +148,9 @@ service status ![service status][8] -最重要的是,这将告诉你某项服务是否处于活跃状态(**正在运行**)。 +最重要的是,这将告诉你某项服务是否处于活跃状态(正在运行)。 -**总结** +### 总结 今天,我详细介绍了两种在 Ubuntu 或任何其他 Linux 系统上管理服务的非常简单的方法。 希望本文对你有所帮助。 @@ -167,7 +163,7 @@ via: https://itsfoss.com/start-stop-restart-services-linux/ 作者:[Sergiu][a] 选题:[lujun9972][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出