zabbix agent需要开启远程命令执行

sed -i 's@#EnableRemoteCommands=0@EnableRemoteCommands=1@'  /etc/zabbix/zabbix_agentd.conf 
sed -i 's@#UnsafeUserParameters=0@UnsafeUserParameters=1@' /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent

zabbix用户授权

echo "zabbix ALL = NOPASSWD: ALL" >> /etc/sudoers

创建脚本

zabbix5.4 故障自愈功能_用户授权

zabbix5.4 故障自愈功能_用户授权_02

zabbix5.4 故障自愈功能_用户授权_03

创建动作

zabbix5.4 故障自愈功能_sed_04

zabbix5.4 故障自愈功能_用户授权_05

zabbix5.4 故障自愈功能_用户授权_06

zabbix5.4 故障自愈功能_用户授权_07

zabbix5.4 故障自愈功能_sed_08

zabbix5.4 故障自愈功能_用户授权_09

验证自愈功能

ss -tnlp |grep 3000
LISTEN 0 511 *:3000 *:* users:(("node",pid=27323,fd=19))
ps -ef |grep npm
zabbix 27304 1 0 16:26 ? 00:00:00 npm
root 27605 25719 0 16:34 pts/0 00:00:00 grep --color=auto npm
kill 27304

 

zabbix5.4 故障自愈功能_sed_10

# ss -tnlp |grep 3000
LISTEN 0 511 *:3000 *:* users:(("node",pid=27631,fd=19))
ps -ef |grep npm
zabbix 27611 1 0 16:35 ? 00:00:00 sh -c export PATH=$PATH:/usr/local/node/bin cd /data/explorer && nohup npm start &
zabbix 27612 27611 0 16:35 ? 00:00:00 npm
root 27707 25719 0 16:36 pts/0 00:00:00 grep --color=auto npm