systemctl 命令完全指南(三)

2016-12-17 18:23:20 6916

使用Systemctl控制并管理服务


12. 列出所有服务(包括启用的和禁用的)

# systemctl list-unit-files --type=service
UNIT FILE STATE
arp-ethers.service disabled
auditd.service enabled
autovt@.service disabled
blk-availability.service disabled
brandbot.service static
collectd.service disabled
console-getty.service disabled
console-shell.service disabled
cpupower.service disabled
crond.service enabled
dbus-org.Fedoraproject.FirewallD1.service enabled
....

13. Linux中如何启动、重启、停?、重载服务以及检查服务(如 httpd.service)状态

# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service
httpd.service -TheApache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Tue2015-04-2817:21:30 IST;6s ago
Process:2876ExecStop=/bin/kill -WINCH ${MAINPID}(code=exited, status=0/SUCCESS)
Main PID:2881(httpd)
Status:"Processing requests..."
CGroup:/system.slice/httpd.service
├─2881/usr/sbin/httpd -DFOREGROUND
├─2884/usr/sbin/httpd -DFOREGROUND
├─2885/usr/sbin/httpd -DFOREGROUND
├─2886/usr/sbin/httpd -DFOREGROUND
├─2887/usr/sbin/httpd -DFOREGROUND
└─2888/usr/sbin/httpd -DFOREGROUND
Apr2817:21:30 tecmint systemd[1]:StartingTheApache HTTP Server...
Apr2817:21:30 tecmint httpd[2881]: AH00558: httpd:Couldnot reliably determine the server's fully q...ssage
Apr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

注意:当我们使用systemctl的start,restart,stop和reload命令时,我们不会从终端获?到任何输出内容,只有status命令可以打印输出。

14. 如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务)

# systemctl is-active httpd.service
# systemctl enable httpd.service
# systemctl disable httpd.service

15. 如何屏蔽(让它不能启动)或显示服务(如 httpd.service)

# systemctl mask httpd.service
ln -s '/dev/null''/etc/systemd/system/httpd.service'
# systemctl unmask httpd.service
rm '/etc/systemd/system/httpd.service'

16. 使用systemctl命令杀死服务

# systemctl kill httpd
# systemctl status httpd
httpd.service -TheApache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: failed (Result:exit-code) since Tue2015-04-2818:01:42 IST;28min ago
Main PID:2881(code=exited, status=0/SUCCESS)
Status:"Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
Apr2817:37:29 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:29 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:39 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:39 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:49 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:49 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:59 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2817:37:59 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti...bled.
Apr2818:01:42 tecmint systemd[1]: httpd.service: control process exited, code=exited status=226
Apr2818:01:42 tecmint systemd[1]:Unit httpd.service entered failed state.
Hint:Some lines were ellipsized,use-l to show in full.

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: