systemd linux
Services are all over the Linux world. Enterprise Linux world turn over services. There are different tools to manage Linux services like Sys-V, upstart, systemd etc. Systemd is gaining popularity in recent times. Fedora, CentOs, RedHat uses systemd for a long time. Ubuntu started to use systemd too. Here we will look into basics of the service management with systemd.
服务遍布Linux世界。 企业Linux世界的移交服务。 有多种工具可以管理Sys-V,upstart,systemd等Linux服务。Systemd在最近变得越来越流行。 Fedora,CentOs,RedHat长期使用systemd。 Ubuntu也开始使用systemd。 在这里,我们将研究systemd服务管理的基础知识。
列出已安装的服务 (List Installed Services)
Linux operating systems like Ubuntu, CentOS, Debian etc. cames with a lot of default services. Also we can install them later with package managers. We can list currently existing services with the systemctl
command by providing list-units
option.
Linux操作系统(如Ubuntu,CentOS,Debian等)带有许多默认服务。 我们也可以稍后使用软件包管理器进行安装。 通过提供list-units
选项,我们可以使用systemctl
命令列出当前存在的服务。
$ systemctl list-units
In systemd services are named unit so we use systemctl list-units command.
在systemd服务中将其命名为unit,因此我们使用systemctl list-units命令。
As we see there information about service status like active
正如我们看到的那样,有关服务状态的信息(例如有效)
获取服务状态 (Get Status of a Service)
Now we can know exact names of the services. We will use status
option with the service name in order to get detailed information about the given service. In this example we will list apache2
service.
现在我们可以知道服务的确切名称。 我们将使用status
选项和服务名称,以获取有关给定服务的详细信息。 在此示例中,我们将列出apache2
服务。
$ systemctl status apache2
systemctl status is the command to get status information
systemctl status是获取状态信息的命令
httpd is the service we want to see status information.
httpd是我们要查看状态信息的服务。
Active:active means it is running currently
活动:活动表示它当前正在运行
- At the bottom we can see latest logs generated by httpd service在底部,我们可以看到httpd服务生成的最新日志
启动服务(Start Service)
If the service is in a stoppped state we need to start this service to use properly. We will use start
option by providing the service name. In this example we will start the service apache2
如果服务处于停止状态,则需要启动此服务才能正确使用。 我们将通过提供服务名称来使用start
选项。 在此示例中,我们将启动服务apache2
$ systemctl start apache2
停止服务 (Stop Service)
The easiest part of managing services is stopping them. We can stop them like start
管理服务最简单的部分就是停止它们。 我们可以像开始一样阻止他们
$ systemctl stop httpd
重新启动服务 (Restart Service)
After making configuration changes about services we need to stop and start service. The practical way is just restarting service like below.
在对服务进行配置更改后,我们需要停止并启动服务。 实际的方法只是重新启动服务,如下所示。
$ systemctl restart httpd
如何使用Systemd启动,停止和获取Linux服务的状态? 信息移植 (How To Start, Stop and Get Status of Linux Service With Systemd? Infografic)
翻译自: https://www.poftut.com/start-stop-get-status-linux-service-systemd/
systemd linux