zabbix实现nginx 故障自治愈

            zabbix实现nginx 故障自治愈

                                     作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.使用zabbix监控nginx

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12340063.html

二.zabbix agent主机开启支持远程命令管理功能

1>.开启zabbix agent的允许运行远程命令功能

[root@nginx201.yinzhengjie.org.cn ~]# grep EnableRemoteCommands= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
# EnableRemoteCommands=0
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's@# (EnableRemoteCommands=)0@11@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep EnableRemoteCommands= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
EnableRemoteCommands=1
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 

2>.开启zabbix agent的允许运行特殊字符功能

[root@nginx201.yinzhengjie.org.cn ~]# grep UnsafeUserParameters= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
# UnsafeUserParameters=0
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's@# (UnsafeUserParameters=)0@11@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep UnsafeUserParameters= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
UnsafeUserParameters=1
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 

3>.重启zabbix agent服务

[root@nginx201.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service 

4>.编辑sudoers文件,为zabbix用户提权

[root@nginx201.yinzhengjie.org.cn ~]# grep "^[a-Z]" /etc/sudoers
Defaults   !visiblepw
Defaults    always_set_home
Defaults    match_group_by_gid
Defaults    always_query_group_plugin
Defaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
root    ALL=(ALL)     ALL
zabbix    ALL=(ALL)     NOPASSWD: ALL
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 

 

三.zabbix webUI定义重启nginx的动作

1>.点击"创建动作"

2>.添加触发条件

3>.自定义启动Nginx的命令

4>.点击"添加",完成动作的创建

5>.动作创建成功

6>.手动停止nginx

7>.查看web界面

8>.nginx启动成功

9>.nginx启动失败请检查上面的命令是否少加了sudo关键字

sudo /yinzhengjie/softwares/nginx/sbin/nginx

原文地址:https://www.cnblogs.com/yinzhengjie2020/p/12358927.html