systemctl -- 系统服务管理器 【转】

systemctl  — 系统服务管理器

systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

直接运行命令可以列出所有正在运行的服务,输出列表具有更详细的信息,比如:


[root
@beyes   command]# systemctl

… …

sendmail.service          loaded active exited        LSB: start and stop sendmail

sshd.service              loaded active running       LSB: Start up the OpenSSH server daemon

udev.service              loaded active running       udev Kernel Device Manager

… …

这里,还有一个 systemd-cgls 命令可以以树状的形式列出正在运行的进程信息。

如果要启动 httpd 服务,那么运行下面命令:

[root
@beyes   command]# systemctl start httpd.service

注意,上面的 httpd 后面的 .service 是不能少的。

同理,停止服务和重启服务可以分别如下运行命令:

# systemctl stop httpd.service       #停止服务

# systemctl restart httpd.service              #重启服务

如果我们要查看服务的运行状态,那么如下运行:

[root
@beyes   command]# systemctl status httpd.service

httpd.service – LSB: start and stop Apache HTTP Server

      Loaded: loaded (/etc/rc.d/init.d/httpd)

      Active: active (running) since Wed, 22 Feb 2012 10:37:30 +0800; 2s ago

     Process: 2573 ExecStop=/etc/rc.d/init.d/httpd stop (code=exited, status=0/SUCCESS)

     Process: 2589 ExecStart=/etc/rc.d/init.d/httpd start (code=exited, status=0/SUCCESS)

    Main PID: 2594 (httpd)

      CGroup: name=systemd:/system/httpd.service

          ├ 2594 /usr/sbin/httpd

          ├ 2596 /usr/sbin/httpd

          ├ 2597 /usr/sbin/httpd

          ├ 2598 /usr/sbin/httpd

          ├ 2599 /usr/sbin/httpd

          ├ 2600 /usr/sbin/httpd

          ├ 2601 /usr/sbin/httpd

          ├ 2602 /usr/sbin/httpd

          └ 2603 /usr/sbin/httpd

如果我们打算让服务可以随机启动,那么如下运行:

[root
@beyes   command]# systemctl enable httpd.service

httpd.service is not a native service, redirecting to /sbin/chkconfig.

Executing /sbin/chkconfig httpd on

用 chkconfig 命令检测一下服务是否运行成功

[root
@beyes   command]# chkconfig –list |grep httpd

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off

可见服务已经在 第2 到 第5 运行等级打开。

同理禁止服务随机启动可以如下运行:

[root
@beyes   command]# systemctl disable httpd.service

httpd.service is not a native service, redirecting to /sbin/chkconfig.

Executing /sbin/chkconfig httpd off

用 chkconfig 检测一下:

[root
@beyes   command]# chkconfig –list |grep httpd

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

httpd              0:off    1:off    2:off    3:off    4:off    5:off    6:off

已经关闭成功。

此外,我们还可以直接检测服务是否随机启动或否,如下运行命令:

[root
@beyes   command]# systemctl is-enabled httpd.service; echo $?

httpd.service is not a native service, redirecting to /sbin/chkconfig.

Executing /sbin/chkconfig httpd –level=5

0

上面,0 表示该服务已经使能随机启动;如果返回 1 那么表示该服务不随机启动

ref:http://www.groad.net/bbs/simple/?t6224.html

    原文作者:the_tops
    原文地址: https://www.cnblogs.com/the-tops/p/8798523.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞