Linux 服务管理两种方式service和systemctl
systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动。
systemd对应的进程管理命令是systemctl
[root@localhost ~]# systemctl list-units --state failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● httpd.service loaded failed failed The Apache HTTP Server
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
可以发现,有个一个服务启动失败了。
可以使用is-failed
选项检查指定的服务是否启动失败。如果启动失败,结果是failed
。如果启动没有问题,结果是active
。
[root@localhost ~]# systemctl is-failed httpd
failed
[root@localhost ~]# systemctl is-failed vsftpd
active
可以使用status
选项,查看服务启动失败的原因,下面状态信息里面告诉我们,是httpd.conf
配置文件354行有语法错误。
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /...osed.
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2020-05-26 09:22:05 CST; 18min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2958 (code=exited, status=1/FAILURE)
May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server...
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /...osed.
May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 26 09:22:05 localhost kill[2959]: kill: cannot find process ""
May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1
May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server.
May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state.
May 26 09:22:05 localhost systemd[1]: httpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
CentOS7中使用systemctl列出启动失败的服务CentOS7中使用systemctl列出启动失败的服务
如果使用systemctl status [unit]
没有找到服务启动失败的原因,可以使用journalctl查看更多的启动日志。
下面操作是过滤出所有带有error
的行,可以找到启动失败的服务。
[root@localhost ~]# journalctl |grep 'error'
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
也可以使用journalctl -u [unit]
只查看某一个服务的启动日志:
[root@localhost ~]# journalctl -u httpd.service
-- Logs begin at Sun 2020-05-24 06:52:52 CST, end at Tue 2020-05-26 09:48:03 CST. --
May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server...
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 26 09:22:05 localhost kill[2959]: kill: cannot find process ""
May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1
May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server.
May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state.
May 26 09:22:05 localhost systemd[1]: httpd.service failed.
#过滤出有错误的信息。
[root@localhost ~]# journalctl -u httpd.service |grep 'error'
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354: was not closed.
发现/etc/httpd/conf/httpd.conf
配置文件的354行,Directory
标签没有关闭,返现原因了,就马上修改吧。
当前题目:通过systemctl列出启动失败的服务
转载源于:http://www.csdahua.cn/qtweb/news34/386934.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网