文章目录
环境说明:
服务器 | IP | 要安装的服务 |
---|---|---|
服务端mq | 192.168.50.154 | lamp zabbix server zabbix agentd |
客户端nginx | 192.168.50.158 | nginx zabbix agentd |
服务端
[root@mq ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
客户端
[root@nginx etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
1. zabbix服务端配置
- 参考这里
- 此时能登陆zabbixweb界面
2. zabbix客户端配置
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
......
location /status {
stub_status on;
allow 192.168.50.0/24;
deny all;
}
......
[root@nginx ~]# curl 192.168.50.158/status
Active connections: 1
server accepts handled requests
13 13 11
Reading: 0 Writing: 1 Waiting: 0
3. 安装zabbix_agentd
[root@nginx ~]# vim /usr/local/etc/zabbix_agentd.conf
Server=192.168.50.154 服务端IP
ServerActive=192.168.50.154
Hostname=runtime1 要与zabbix监控里一致
启动服务
[root@nginx ~]# zabbix_agentd
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
4. 编写脚本
[root@nginx ~]# mkdir /scripts
[root@nginx scripts]# cat check_nginx.sh
#!/bin/bash
case $1 in
Active)
status=$(curl -s http://192.168.50.158/status | awk 'NR==1{print $3}')
echo $status
;;
accepts)
status=$(curl -s http://192.168.50.158/status | awk 'NR==3{print $1}')
echo $status
;;
handled)
status=$(curl -s http://192.168.50.158/status | awk 'NR==3{print $2}')
echo $status
;;
requests)
status=$(curl -s http://192.168.50.158/status | awk 'NR==3{print $3}')
echo $status
;;
Reading)
status=$(curl -s http://192.168.50.158/status | awk 'NR==4{print $2}')
echo $status
;;
Writing)
status=$(curl -s http://192.168.50.158/status | awk 'NR==4{print $4}')
echo $status
;;
Waiting)
status=$(curl -s http://192.168.50.158/status | awk 'NR==4{print $6}')
echo $status
;;
*)
echo "please enter parameter Active|accepts|handled|requests|Reading|Writing|Waiting"
;;
esac
[root@nginx scripts]# chmod +x check_nginx.sh
5. 修改客户端配置文件开启自定义监控
[root@nginx ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1 #取消注释并把0改为1
UserParameter=check_nginx_status[*],/bin/bash /scripts/check_nginx.sh $1 #添加这一行
重启agentd端服务
[root@nginx ~]# pkill zabbix
[root@nginx ~]# zabbix_agentd
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
6. 服务端检测key是否可用
[root@mq ~]# zabbix_get -s 192.168.50.158 -k check_nginx_status[Active]
1
[root@mq ~]# zabbix_get -s 192.168.50.158 -k check_nginx_status[Reading]
0
7. zabbix页面配置
7.1 添加主机组
7.2 添加主机
7.3 添加模板
7.4 添加监控项
7.5 添加触发器
7.6 查看是否出发了监控
7.7 添加其余6个监控项和触发器并触发告警
- 因为脚本里有监控7个目标: Active , accepts ,handled , requests,Reading, Writing, Waiting
-
监控第二个指标
-
其余几个指标以此类推
-
查看监控告警