echo “123” >> /usr/local/nginx/html/index.html
命令:./nginx
问成功显示如下;
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to < a href="http://nginx.org/">nginx.org.
Commercial support is available at < a href="http://nginx.com/">nginx.com.
Thank you for using nginx.
123
location = /nginx_status{ # 配置访问路径,即uri
stub_status on; # 开启该模块 其实只配置这一行就可以的
access_log off; # 关闭日志
allow 192.168.234.150; # 允许访问的ip,即白名单ip
allow 127.0.0.1;
deny all; # 拒绝白名单ip以外的ip访问
}
在/usr/local/nginx/sbin/下输入
命令:./nginx -t
命令:./nginx -s reload
在浏览器中输入:http://192.168.234.150/nginx_status
编写nginx_status.sh 的脚本,脚本内容如下;
- #!/bin/bash
- HOST="127.0.0.1"
- PORT="80"
-
- function ping {
- /sbin/pidof nginx | wc -l
- }
-
- function active {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
- }
- function reading {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
- }
- function writing {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
- }
- function waiting {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
- }
- function accepts {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
- }
- function handled {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
- }
- function requests {
- /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
- }
- $1
-
-
注意脚本中的配置文件的nginx_status这个地方和nginx.conf中的自定义的监控模块的名字要是一致的
给这个脚本可执行的权限
chmod a+x nginx_status.sh
bash nginx_status.sh active
bash nginx_status.sh requests
zabbix_agentd.conf这个脚本所在的目录/etc/zabbix
修改配置文件的内容如下;
UnsafeUserParameters=1
UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh $1
service zabbix-agent restart
点击配置,点击模板,点击导入
点击浏览,桌面上有一个文件叫做zbx_export_template.xml(这个文件需要去自己下载去)
然后再点击模板的时候,就会出现template app nginx的模板了
然后点击检测-图形,选择喜哥的服务器(参考你自己创建的主机名称),选择nginx的几个选项
其中有一个选项叫做,nginx_status_server