博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx下搭建Nagios监控平台(转载)
阅读量:5047 次
发布时间:2019-06-12

本文共 4452 字,大约阅读时间需要 14 分钟。

Nagios依赖PHP环境和perl环境,由于不支持Perl的CGI,需先来搭建Perl环境,Nagios原理介绍略。

文章原出处:https://blog.linuxeye.com/312.html

1、下载最新稳定源码包和Perl脚本

mkdir -cacticd nagios-cacti wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.74.tar.gz wget http://www.cpan.org/authors/id/B/BO/BOBTFISH/FCGI-ProcManager-0.24.tar.gz wget http://blog.linuxeye.com/wp-content/uploads/2013/04/perl-fcgi.pl wget http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

2、Nginx对Perl的CGI支持

Nginx支持的CGI方法有好几种,基本原理都是通过Perl的FCGI模块实现,下面的方法就是其中一种:
安装FCGI模块

tar xzf FCGI-0.74.tar.gz cd FCGI-0.74 perl Makefile.PL make && make install cd ../

安装FCGI-ProcManager模块

tar xzf FCGI-ProcManager-0.24.tar.gz cd FCGI-ProcManager-0.24 perl Makefile.PL make && make install cd ../

Perl脚本

cp perl-fcgi.pl /usr/local/nginx chmod +x /usr/local/nginx/perl-fcgi.pl /usr/local/nginx/perl-fcgi.pl > /usr/local/nginx/logs/perl-fcgi.log 2>&1 & #启动Perl chmod 777 /usr/local/nginx/logs/perl-fcgi.sock #Nginx Log中提示Permision Denied方法 cd ../

3、Nagios安装(服务端)

useradd -s /sbin/nologin nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www tar xzf nagios-3.5.0.tar.gz cd nagios yum -y install gd-devel ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd make all make install #用于安装主要的程序、CGI及HTML文件 make install-init #用于生成init启动脚本 make install-config #用于安装示例配置文件 make install-commandmode #用于设置相应的目录权限 chkconfig --add nagios chkconfig nagios on cd ../

Nagios主程序只是提供一个运行框架,其具体监控是靠运行在其下的插件完成的,Nagios插件必须安装

tar xzf nagios-plugins-1.4.16.tar.gz cd nagios-plugins-1.4.16 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios make && make install cd ../

由于Nagios只能监测自己所在的主机的一些本地情况,例如,cpu负载、内存使用、硬盘使用等等。如果想要监测被监控的服务器上的这些本地情况,就要

用到NRPE。NRPE(Nagios Remote Plugin
Executor)是Nagios的一个扩展,它被用于被监控的服务器上,向Nagios监控平台提供该服务器的一些本地的情况。NRPE可以称为
Nagios的客户端。

tar xzf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure make && make install cp sample-config/nrpe.cfg /usr/local/nagios/etc/ chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg cd ../

4、Nginx配置(服务端)

ln -s /usr/local/nagios/share /data/admin/nagios

以http://www.linuxeye.com/nagios,需要建立软链接,服务nginx.conf配置文件如下:

################http://www.linuxeye.com/nagios#########################        server {
listen 80; server_name _; access_log /dev/null; root /data/admin; index index.php; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } location /status { stub_status on; } location ~ .*\.(cgi|pl)?$ { auth_basic "Nagios Access"; auth_basic_user_file /usr/local/nagios/etc/htpasswd.users; gzip off; root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; fastcgi_index index.cgi; fastcgi_param REMOTE_USER $remote_user; fastcgi_param HTTP_ACCEPT_LANGUAGE en_US; include fastcgi_params; fastcgi_read_timeout 60; } }

以http://nagios.linuxeye.com服务nginx.conf配置文件如下:

################http://nagios.linuxeye.com##############################        server {
listen 80; server_name nagios.linuxeye.com; access_log logs/nagios_access.log combined; auth_basic "Nagios Access"; auth_basic_user_file /usr/local/nagios/etc/htpasswd.users; location / { root /usr/local/nagios/share; index index.html index.htm index.php; } location ~ .*\.(php|php5)?$ { root /usr/local/nagios/share; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location /nagios { alias /usr/local/nagios/share; } location /cgi-bin/images { alias /usr/local/nagios/share/images; } location /cgi-bin/stylesheets { alias /usr/local/nagios/share/stylesheets; } location /cgi-bin { alias /usr/local/nagios/sbin; } location ~ .*\.(cgi|pl)?$ { gzip off; root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; fastcgi_index index.cgi;

转载于:https://www.cnblogs.com/evevil/p/5057251.html

你可能感兴趣的文章
JQ 操作样式,单选按钮跟复选框
查看>>
python中的自测语句是什么?
查看>>
JQuery 基础:
查看>>
Proj.4坐标系统创建参数
查看>>
我有一个 APP 创意,如何将其实现?
查看>>
SVN改地址eclipse怎么同步
查看>>
Xadmin查询
查看>>
Jsf 页面导航Navigation总结
查看>>
android studio 2018.4.16 intent
查看>>
html4与html5的区别
查看>>
html复习
查看>>
cordova StatusBar插件的使用(设置手机状态栏颜色和页面头部颜色一致),做出和原生一样的页面效果体验...
查看>>
<button>和<input type="button"> 的区别
查看>>
编辑代码或者文档时光标变成了一闪一闪的方块怎么处理?
查看>>
Carthage的安装和使用
查看>>
iOS bug解决方案(01)
查看>>
TopCoder SRM 642 Div.2 1000 --二分+BFS
查看>>
UVALive 4426 Blast the Enemy! --求多边形重心
查看>>
http://www.cs.cmu.edu/~ggordon/IRLS-example/
查看>>
用上了360免费云盘
查看>>