前言
Zabbix 監控網站關鍵詞,防止惡意篡改網站信息,並觸發微信告警
一、主機規劃
服務器 | IP |
---|---|
Zabbix-server | 192.168.1.111 |
Zabbix-agent、Nginx | 192.168.1.116 |
二、Zabbix-agent端安裝Nginx服務
1、獲取nginx源碼包,並解壓
[root@localhost src]# ls
nginx-1.8.0.tar.gz
[root@localhost src]# tar -xzvf nginx-1.8.0.tar.gz
2、編譯安裝
[root@localhost src]# cd nginx-1.8.0/
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.8.0]# make && make install
3、修改nginx發佈頁面做測試
[root@localhost ~]# vim /usr/local/nginx/html/index.html
<h1>ZABBIX-test</h1> ///添加這一句測試語句
4、重啓nginx服務
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
5、訪問nginx界面
6、統計測試界面中是否存在ZABBIX-test
文字,如果存在則數字大於或等於1
[root@localhost ~]# curl -s 192.168.1.116/| grep -c ZABBIX-test
1
三、配置zabbix監控關鍵詞
1、編寫監控腳本
[root@localhost ~]# vim /tmp/auto_monitor_nginx.sh
```javascript
#!/bin/bash
#by auto monitor nginx test
WEBSITE="http://192.168.1.116/"
NUM=`curl -s $WEBSITE| grep -c "ZABBIX-test"`
echo $NUM
2、授予腳本可執行權限,並測試
[root@localhost tmp]# chmod +x auto_monitor_nginx.sh
[root@localhost tmp]# sh auto_monitor_nginx.sh
1
3、在zabbix-agent.conf配置文件中創建key值
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=check_nginx_word,sh /tmp/auto_monitor_nginx.sh
4、重啓zabbix-agent服務
[root@localhost ~]# systemctl restart zabbix-agent
5、在zabbix-server端測試獲取鍵值
[root@zabbix ~]# zabbix_get -s 192.168.1.116 -k check_nginx_word
1 ///獲取成功
四、配置zabbix-web端
1、創建主機
2、創建監控
3、創建圖像
4、創建觸發器
5、配置微信告警
運維之道 | Zabbix 使用企業微信發送郵件報警及定製郵件報警內容
PS:觸發微信告警詳細步驟可按此鏈接進行操作
五、查看檢測結果及微信觸發告警
1、查看檢測圖像
2、將Nginx配置文件中的"ZABBIX-test"字刪除,查看觸發告警
[root@localhost ~]# vim /usr/local/nginx/html/index.html
<h1>ZABBIX-test</h1> ///將此含刪除
3、重啓Nginx服務
[root@localhost ~]#
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
4、查看zabbix-web端圖像
5、查看微信觸發告警
6、將"ZABBIX-test"值寫入Nginx配置文件中,再次查看告警
[root@localhost ~]# vim /usr/local/nginx/html/index.html
<h1>ZABBIX-test</h1> ///添加這一句測試語句
PS:通過此案例,可以自行按企業需求編寫腳本,並在ZABBIX中創建監控項和觸發器,並部署企業微信告警信息