文章目录
- 1,用systemctl status zabbix-agent2查看报错状态
- 2,用journalctl -xe查看一下报错日志
- 3,再看一下zabbix的日志。
- 4,错误修改
- 5, 再次重启zabbix-agent2
1,用systemctl status zabbix-agent2查看报错状态
[root@c1 zabbix]# systemctl status zabbix-agent2
● zabbix-agent2.service - Zabbix Agent 2
Loaded: loaded (/usr/lib/systemd/system/zabbix-agent2.service; disabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Tue 2024-06-25 15:46:27 CST; 8s ago
Process: 31777 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=1/FAILURE)
Process: 31767 ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 31767 (code=exited, status=0/SUCCESS)
Jun 25 15:46:27 c1 systemd[1]: Unit zabbix-agent2.service entered failed state.
Jun 25 15:46:27 c1 systemd[1]: zabbix-agent2.service failed.
发现只提示说Unit zabbix-agent2.service entered failed state,这样子的报错并不清晰,具体什么原因也没说。
2,用journalctl -xe查看一下报错日志
然并卵,这个也没给出实质性有帮助的报错提示,只说 zabbix-agent2.service failed,没啥用。
[root@c1 zabbix]# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit zabbix-agent2.service has finished starting up.
--
-- The start-up result is done.
Jun 25 15:47:32 c1 zabbix_agent2[31899]: Starting Zabbix Agent 2 []. (5.0.42)
Jun 25 15:47:32 c1 zabbix_agent2[31899]: Press Ctrl+C to exit.
Jun 25 15:47:33 c1 zabbix_agent2[31899]: Zabbix Agent 2 stopped. (5.0.42)
Jun 25 15:47:33 c1 kill[31910]: Usage:
Jun 25 15:47:33 c1 kill[31910]: kill [options] <pid|name> [...]
Jun 25 15:47:33 c1 kill[31910]: Options:
Jun 25 15:47:33 c1 kill[31910]: -a, --all do not restrict the name-to-pid conversion to processes
Jun 25 15:47:33 c1 kill[31910]: with the same uid as the present process
Jun 25 15:47:33 c1 kill[31910]: -s, --signal <sig> send specified signal
Jun 25 15:47:33 c1 kill[31910]: -q, --queue <sig> use sigqueue(2) rather than kill(2)
Jun 25 15:47:33 c1 kill[31910]: -p, --pid print pids without signaling them
Jun 25 15:47:33 c1 kill[31910]: -l, --list [=<signal>] list signal names, or convert one to a name
Jun 25 15:47:33 c1 kill[31910]: -L, --table list signal names and numbers
Jun 25 15:47:33 c1 kill[31910]: -h, --help display this help and exit
Jun 25 15:47:33 c1 kill[31910]: -V, --version output version information and exit
Jun 25 15:47:33 c1 kill[31910]: For more details see kill(1).
Jun 25 15:47:33 c1 systemd[1]: zabbix-agent2.service: control process exited, code=exited status=1
Jun 25 15:47:33 c1 systemd[1]: Unit zabbix-agent2.service entered failed state.
Jun 25 15:47:33 c1 systemd[1]: zabbix-agent2.service failed.
Jun 25 15:47:43 c1 systemd[1]: zabbix-agent2.service holdoff time over, scheduling restart.
Jun 25 15:47:43 c1 systemd[1]: Stopped Zabbix Agent 2.
3,再看一下zabbix的日志。
vim /var/log/zabbix/zabbix_agent2.log
在vim里面搜索cannot
, error
, failed
等关键字。这是一个非常有用的技巧。
在很多时候我们分析日志的时候,不需要每一行都去看,要学会用关键字搜索,快速找到错误位置,比如这里,我搜了以下关键字cannot
,正好就在这一天的日志内容中有这个关键字,它说cannot start agent: listen unix /tmp/agent.sock: bind: permission denied
- 翻译过来就是/tmp/agent.sock没有被赋予权限。
4,错误修改
查看一下/tmp
文件夹的权限,发现确实权限缺失了
[root@c1 zabbix]# ls -ld /tmp
drwxr-xr-t 8 root root 4096 Jun 25 15:42 /tmp
赋予root用户组权限
[root@c1 zabbix]# chmod 777 /tmp
[root@c1 zabbix]# chown root:root /tmp
5, 再次重启zabbix-agent2
systemctl start zabbix-agent2
systemctl status zabbix-agent2
启动成功!
- 思路总结,记得查看日志的时候,要学会关键字搜索,并且要在当时那个时间段的日志内搜索,这样可以提高错误定位的效率。