1.查看自己服务具体错误信息
systemctl status zk_exporter
2.使用systemctl列出启动失败的服务
- (1)列出启动失败的服务
[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'.
=============================================================
查看服务的状态是否打开,一般好像也没啥用,直接输入:chkconfig,也会有systemctl list-unit-file提示,若忘记,可以这么操作
systemctl list-unit-file --type=services|grep -i http
启动,关闭httpd服务,查看httpd服务状态
systemctl start httpd
systemctl stop httpd
systemctl status httpd
- chkconfig增加一个服务
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig –add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig –level 35 mysqld on
修改服务的默认启动等级。
chkconfig –list #列出所有的系统服务
chkconfig –add httpd #增加httpd服务
chkconfig –del httpd #删除httpd服务
chkconfig –level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig –list #列出系统所有的服务启动情况
chkconfig –list mysqld #列出mysqld服务设置情况
chkconfig –level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,–level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级
等级runlevel含义,可以看:(16)linux知识点扩展
- (2)is-failed选项
可以使用is-failed选项检查指定的服务是否启动失败。如果启动失败,结果是failed。如果启动没有问题,结果是active。
[root@localhost ~]# systemctl is-failed httpd
failed
[root@localhost ~]# systemctl is-failed vsftpd
active
- (3)检查服务的状态
可以使用status选项,查看服务启动失败的原因,下面状态信息里面告诉我们,是httpd.conf配置文件354行有语法错误。
[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.
- (4)使用journalctl查看服务的启动日志
如果使用systemctl status [unit]没有找到服务启动失败的原因,可以使用journalctl查看更多的启动日志。
下面操作是过滤出所有带有error的行,可以找到启动失败的服务。
[root@localhost ~]# journalctl |grep 'fail'
[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.
- (5)也可以使用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.
3.systemctl命令列出所有服务
列出所有service
systemctl list-units --type=service
systemctl --type=service
watchdog.service loaded active running watchdog daemon
查看某个service状态
service watchdog status