1.zabbix 安裝流程
2.zabbix agent Active Passive Mode
3.zabbix 獲取Nginx 連線狀態
4.通過API修改zabbix server HOST IP參數
5.忘記Zabbix 密碼
1.zabbix 安裝流程
安裝過程 可以參考
https://www.zabbix.com/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=nginx
2.zabbix agent Active Passive Mode
Passive Mode | Zabbix Server 輪詢連線到Zabbix Agent 10050端口上確認並取值 |
Active Mode | Zabbix Agent 每兩分鐘(預設值)連線到Zabbix Server 10051端口上並把數值送到Zabbix Server |
Passive Mode 設定
確認Server 這個參數既可
#vi /etc/zabbix/zabbix_agentd.conf
Server=3.3.3.3 (你的Zabbix Server 或者是 Zabbix Proxy 被動模式) ServerActive=3.3.3.3 (主動模式使用) Hostname=主機名稱 (Agent上的Hostname必須與zabbix server上的 Hostname相同)
3.zabbix 獲取Nginx 連線狀態
在監控主機上生成ngx_status.sh腳本
#!/bin/bash # Description:nginx status HOST="127.0.0.1" PORT="80" # pid check function ping { /sbin/pidof nginx | wc -l } # nginx status function active { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}' } # exe function $1
#echo "UserParameter=nginx.status[*],/etc/zabbix/ngx_status.sh \$1" >> /etc/zabbix/zabbix_agentd.conf
完成後 restart zabbix-agent
#systemctl restart zabbix-agent.service
接著確認Nginx 是否有http_stub_status_module
#nginx -V 2>&1 | grep -o with-http_stub_status_module
確認有了話,設定nginx stub status (nginx.conf)
server { listen 80; server_name 127.0.0.1 localhost; location /ngx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
從nginx本地驗證是否正常運作
#curl http://127.0.0.1/ngx_status
Active connections: 1 server accepts handled requests 57495 57495 59094 Reading: 0 Writing: 1 Waiting: 0
從Zabbix Server 驗證是否正常運作
#zabbix_get -s 3.3.3.3 -k nginx.status[accepts]
4.通過API修改zabbix server HOST IP參數
獲取zabbix api token
#curl -X POST -s http://yourzabbix/zabbix/api_jsonrpc.php \
-H 'Content-Type:application/json' \
-d '{"jsonrpc": "2.0","method":"user.login","params":{"user":"'$user'","password":"'$pass'"},"auth": null,"id":0}' | jq -r .result
a8dad60295858044alksdjfdcb2499d51a6
獲取zabbix hostid
#curl -X POST -s http://yourzabbix/zabbix/api_jsonrpc.php \
-H 'Content-Type:application/json' \
-d '{"jsonrpc": "2.0","method":"host.get","params": {"output": ["host"],"search" :{"description": "hostname"}},"id": 1,"auth":"'$token'"}' | jq -r .result[] | jq -r .hostid
獲取zabbix interfaceid
#curl -X POST -s http://yourzabbix/zabbix/api_jsonrpc.php \
-H 'Content-Type:application/json' \
-d '{"jsonrpc": "2.0","method": "hostinterface.get","params": {"output": "extend","hostids": "'$hostid'"},"auth":"'$token'","id":1}' | jq -r .result[] | jq -r .interfaceid
5.忘記Zabbix 密碼
登入SSH Zabbix主機
#mysql -u root -p
mysql> use zabbix;
mysql> update zabbix.users set passwd=md5('zabbix') where alias='Admin';
Facebook Comments