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