systemd linux_如何使用Systemd启动,停止和获取Linux服务的状态?

systemd linux

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
List Installed Services
List Installed Services
列出已安装的服务
  • 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

Get Status of a Service
Get Status of a Service
获取服务状态
  • 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
LEARN MORE  Windows WMIC (Windows Management Interface Command) Tutorial with Examples
了解更多Windows WMIC(Windows管理界面命令)教程和示例

如何使用Systemd启动,停止和获取Linux服务的状态? 信息移植 (How To Start, Stop and Get Status of Linux Service With Systemd? Infografic)

How To Start, Stop and Get Status of Linux Service With Systemd? Infografic
How To Start, Stop and Get Status of Linux Service With Systemd? Infografic
如何使用Systemd启动,停止和获取Linux服务的状态? 信息移植

翻译自: https://www.poftut.com/start-stop-get-status-linux-service-systemd/

systemd linux

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值