1在nginx 服务器上安装nrpe客户端:
Nginx的服务需要监控起来,不然万一down了而不及时修复,会影响web应用,如下web应用上面启动的nginx后台进程
[root@lb-net-2 ~]# ps aux|grep nginx
nobody 15294 0.0 0.0 22432 3464 ? S Jul03 0:05 nginx: worker process
nobody 15295 0.0 0.0 22432 3480 ? S Jul03 0:05 nginx: worker process
......
nobody 15316 0.0 0.0 22432 3468 ? S Jul03 0:05 nginx: worker process
nobody 15317 0.0 0.0 22432 3480 ? S Jul03 0:05 nginx: worker process
root 16260 0.0 0.0 20584 1684 ? Ss Jun18 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 21211 0.0 0.0 103252 860 pts/1 S+ 17:50 0:00 grep nginx
在RHEL5.3上配置基本的Nagios系统(使用Nagios-3.1.2)
CentOS 5.5+Nginx+Nagios监控端和被控端安装配置指南
Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用
1.1,rpm方式安装nrpe客户端
[root@localhost nagios]# ll
总计 768
-rw-r--r-- 1 root root 713389 12-16 12:08 nagios-plugins-1.4.11-1.x86_64.rpm
-rw-r--r-- 1 root root 32706 12-16 12:09 nrpe-2.12-1.x86_64.rpm
-rw-r--r-- 1 root root 18997 12-16 12:08 nrpe-plugin-2.12-1.x86_64.rpm
[root@localhost nagios]# rpm -ivh *.rpm --nodeps --force
1.2 在配置文件最末尾,添加配置信息以及监控主机服务器ip地址
[root@ localhost nagios]# vim /etc/nagios/nrpe.cfg
# add by tim on 2014-06-11
command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 15
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
#command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 50 -c 80
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 750 -c 800
command[check-host-alive]=/usr/local/nagios/libexec/check_ping -H 10.xx.3.29 -w 3000.0,80% -c 5000.0,100% -p 5
allowed_hosts = 127.0.0.1,10.xx.3.41
check下命令是否生效:
[root@web-9 nrpe-2.15]# /usr/local/nagios/libexec/check_users -w 8 -c 15
USERS OK - 2 users currently logged in |users=2;8;15;0
[root@web-9 nrpe-2.15]#
看到已经USERS OK -….命令已经生效。
1.3 启动nrpe报错如下:
[root@web-9 ~]# service nrpe restart
Shutting down nrpe: [失败]
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
[失败]
[root@web-9 ~]#
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
[失败]
[root@db-m2-slave-1 nagios_client]#
建立连接
[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6
(如果没有libssl.so,就采用别的libssl.so.10来做软连接,ln -s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6)
[root@db-m2-slave-1 nagios_client]#
再重新启动如下:
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory
[失败]
[root@web-10 ~]# ll /usr/lib64/libcrypto.so
lrwxrwxrwx. 1 root root 18 10月 13 2013 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.0
[root@db-m2-slave-1 nagios_client]#
再建链接:
[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6
(或者如果没有libcrypto.so,就采用libcrypto.so.10做软连接, ln -s /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6)
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: [确定]
[root@db-m2-slave-1 nagios_client]#
1.4 检测下nrpe是否正常运行:
去nagios服务器端check下
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.3.xx
NRPE v2.12
[root@cache-2 ~]#
看到返回NRPE v2.15表示已经连接成功,客户端的nrpe服务已经监控完成。
2,比较简单的通过check_http的方式监控
可以在/etc/nagios/nrpe.cfg里面采用check_http的方式来获取nginx是否运行:
(1) 编辑nrpe.cfg
Vim /etc/nagios/nrpe.cfg
command[check_nginx_status]=/usr/lib/nagios/plugins/check_http -I localhost -p 80 -u /nginx_status -e 200 -w 3 -c 10
(2) 重启nrpe服务
[root@lb-net-2 ~]# service nrpe restart
Shutting down nrpe: [确定]
Starting nrpe: [确定]
[root@lb-net-2 ~]#
(3) 在nagios服务器端check,成功。
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H10.xx.1.22 -c check_nginx_status
HTTP OK HTTP/1.1 200 OK - 254 bytes in 0.002 seconds |time=0.002031s;3.000000;10.000000;0.000000 size=254B;;;0
(4) 在services.cfg里面添加check_nginx_status服务
define service{
host_name lb-net-2
service_description check_nginx_status
check_command check_nrpe!check_nginx_status
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups opsweb
}
(5) 在command.cfg添加check_nginx_status服务
define command{
command_name check_nginx_status
command_line $USER1$/check_nginx_status -I $HOSTADDRESS$ -w $Warning$ -c $Cri$
}
(6) 重新加载nagios
[root@cache-2 objects]# service nagios reload
Running configuration check...
Reloading nagios configuration...
done
[root@cache-2 objects]#
(7) 查看界面的nginx监控服务,如下所示: