nginx编译安装 zabbix自定义监控nginx
#zabbix自定义监控项监控Nginx
#
#
#系统版本:
[root@zabbix_2 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
主机名:zabbix_1
角色:zabbix-server
IP地址:192.168.174.136
主机名:zabbix_2
角色:zabbix-agent
IP地址:192.168.174.137
# 均关闭防火墙和selinux
#编译安装Nginx
#Nginx 下载地址:http://mirrors.sohu.com/nginx/ pcre :http://down.linuxprobe.com/Tools/pcre-8.35.tar.gz
#上传nginx 和pcre 到zabbix_2主机上
#编译安装依赖包
[root@zabbix_2 ~]# ls
anaconda-ks.cfg nginx-1.8.1.tar.gz pcre-8.35.tar.gz
[root@zabbix_2 ~]# yum install -y gcc-c++ openssl-devel zlib-devel
[root@zabbix_2 ~]# tar -xf pcre-8.35.tar.gz
[root@zabbix_2 ~]# cd pcre-8.35/
[root@zabbix_2 pcre-8.35]# ./configure --prefix=/usr/local/pcre/
[root@zabbix_2 pcre-8.35]# make && make install
#编译安装 Nginx
[root@zabbix_2 nginx-1.8.1]# useradd -s /sbin/nologin -M nginx
[root@zabbix_2 nginx-1.8.1]# cd nginx-1.8.1/
[root@zabbix_2 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@zabbix_2 nginx-1.8.1]# make && make install
#./configure --help 查看参数
#启动nginx
[root@zabbix_2 ~]# /usr/local/nginx/sbin/nginx
#启动成功,如图所示
#修改 nginx.conf
[root@zabbix_2 ~]# vim /usr/local/nginx/conf/nginx.conf
#添加如下内容
[root@zabbix_2 ~]# sed -n '47,52p' /usr/local/nginx/conf/nginx.conf
location /status {
stub_status on;
access_log off;
allow 192.168.174.0/24;
deny all;
}
#测试配置文件是否正确
[root@zabbix_2 ~]# /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
#重启nginx
[root@zabbix_2 ~]# /usr/local/nginx/sbin/nginx -s reload
#访问
#zabbix自定义监控项
#编写脚本
[root@zabbix_2 ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@zabbix_2 zabbix_agentd.d]# vim nginx_status.conf
[root@zabbix_2 zabbix_agentd.d]# cat nginx_status.conf
UserParameter=nginx.active, /usr/bin/curl -s http://192.168.174.137/status | grep -i Active | awk -F" " '{print $3}'
#UserParameter 为关键字 /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf里面有案例
#naginx.active 为key ,后面为获取数据脚本
[root@zabbix_2 zabbix_agentd.d]# /usr/bin/curl -s http://192.168.174.137/status | grep -i Active | awk -F" " '{print $3}'
1
[root@zabbix_2 zabbix_agentd.d]# systemctl restart zabbix-agent.service
#在zabbix_1上测试
[root@zabbix_1 ~]# yum install -y zabbix-get
[root@zabbix_1 ~]# zabbix_get -s 192.168.174.137 -p 10050 -k "nginx.active"
1
#找到zabbix_2
#创建监控项
#添加监控项内容(注意此处的键值至关重要,千万不能错)
#监控项添加成功
#创建图形
#选择所要表示的监控项
#zabbix自定义监控项监控Nginx
#
#
#系统版本:
[root@zabbix_2 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
主机名:zabbix_1
角色:zabbix-server
IP地址:192.168.174.136
主机名:zabbix_2
角色:zabbix-agent
IP地址:192.168.174.137
# 均关闭防火墙和selinux
#编译安装Nginx
#Nginx 下载地址:http://mirrors.sohu.com/nginx/ pcre :http://down.linuxprobe.com/Tools/pcre-8.35.tar.gz
#上传nginx 和pcre 到zabbix_2主机上
#编译安装依赖包
[root@zabbix_2 ~]# ls
anaconda-ks.cfg nginx-1.8.1.tar.gz pcre-8.35.tar.gz
[root@zabbix_2 ~]# yum install -y gcc-c++ openssl-devel zlib-devel
[root@zabbix_2 ~]# tar -xf pcre-8.35.tar.gz
[root@zabbix_2 ~]# cd pcre-8.35/
[root@zabbix_2 pcre-8.35]# ./configure --prefix=/usr/local/pcre/
[root@zabbix_2 pcre-8.35]# make && make install
#编译安装 Nginx
[root@zabbix_2 nginx-1.8.1]# useradd -s /sbin/nologin -M nginx
[root@zabbix_2 nginx-1.8.1]# cd nginx-1.8.1/
[root@zabbix_2 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@zabbix_2 nginx-1.8.1]# make && make install
#./configure --help 查看参数
#启动nginx
[root@zabbix_2 ~]# /usr/local/nginx/sbin/nginx
#启动成功,如图所示
#修改 nginx.conf
[root@zabbix_2 ~]# vim /usr/local/nginx/conf/nginx.conf
#添加如下内容
[root@zabbix_2 ~]# sed -n '47,52p' /usr/local/nginx/conf/nginx.conf
location /status {
www.wnhack.com
stub_status on;
access_log off;
allow 192.168.174.0/24;
deny all;
}
#测试配置文件是否正确
[root@zabbix_2 ~]# /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
#重启nginx
[root@zabbix_2 ~]# /usr/local/nginx/sbin/nginx -s reload
#访问
#zabbix自定义监控项
#编写脚本
[root@zabbix_2 ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@zabbix_2 zabbix_agentd.d]# vim nginx_status.conf
[root@zabbix_2 zabbix_agentd.d]# cat nginx_status.conf
UserParameter=nginx.active, /usr/bin/curl -s http://192.168.174.137/status | grep -i Active | awk -F" " '{print $3}'
本文来自无奈人生安全网
#UserParameter 为关键字 /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf里面有案例
#naginx.active 为key ,后面为获取数据脚本
[root@zabbix_2 zabbix_agentd.d]# /usr/bin/curl -s http://192.168.174.137/status | grep -i Active | awk -F" " '{print $3}'
1
[root@zabbix_2 zabbix_agentd.d]# systemctl restart zabbix-agent.service
#在zabbix_1上测试
[root@zabbix_1 ~]# yum install -y zabbix-get
[root@zabbix_1 ~]# zabbix_get -s 192.168.174.137 -p 10050 -k "nginx.active"
1
#找到zabbix_2
#创建监控项
内容来自无奈安全网
#添加监控项内容(注意此处的键值至关重要,千万不能错)
#监控项添加成功
#创建图形
#选择所要表示的监控项