文章目錄
- 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 2Loaded: 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 agoProcess: 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
啟動成功!
- 思路總結,記得查看日志的時候,要學會關鍵字搜索,并且要在當時那個時間段的日志內搜索,這樣可以提高錯誤定位的效率。