nginx环境下搭建nagios 3.5.0,及配置pnp4nagios画图
本文基于《LNMP最新源码安装脚本》,Nagios依赖PHP环境和perl环境,由于Nginx不支持Perl的CGI,需先来搭建Perl环境,Nagios原理介绍略。
一、下载最新稳定源码包和Perl脚本
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
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz
wget http://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.25.tar.gz
二、Nginx对Perl的CGI支持
Nginx支持Perl的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 ../
安装IO模块
tar xvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make && make install
cd ..
安装IO-All模块
tar xvf IO-All-0.41.tar.gz
cd IO-All-0.41
perl Makefile.PL
make && make install
启动方法:
下载nginx-fcgi脚本
Wget http://www.nginx.eu/nginx-fcgi/nginx-fcgi.txt
#mv nginx-fcgi.txt /usr/sbin/nginx-fcgi
#chmod +x /usr/sbin/nginx-fcgi
mv nginx-fcgi.txt /usr/local/nginx/sbin/nginx-fcgi (我的nginx安装位置)
chmod +x /usr/local/nginx/sbin/nginx-fcgi
如果不用 sudo 方式运行 nginx-fcgi,请注释掉 nginx-fcgi 脚本中的:
if ( $> == "0" ) {
print "\n\tERROR\tRunning as a root!\n";
print "\tSuggested not to do so !!!\n\n";
exit 1;
}
启动 nginx-fcgi:
/usr/local/nginx/sbin/nginx-fcgi -l /usr/local/nginx/logs/nginx-fcgi.log -pid /usr/local/nginx/logs/nginx-fcgi.pid -S /usr/local/nginx/logs/nginx-fcgi.sock
chown nginx:nginx /usr/local/nginx/logs/nginx-fcgi.sock
注意一定要为 socket 添加 nginx 帐户的权限,否则 cgi 会执行失败,页面会报502错误
运行前使用cpan 安装 FCGI; Getopt::Long; Socket;
设置开机启动(添加到/etc/rc.loacl文件)
/bin/rm -rf /usr/local/nginx/logs/nginx-fcgi.pid
/usr/local/nginx/sbin/nginx-fcgi -l /usr/local/nginx/logs/nginx-fcgi.log -pid /usr/local/nginx/logs/nginx-fcgi.pid -S /usr/local/nginx/logs/nginx-fcgi.sock
chmod 777 /usr/local/nginx/logs/nginx-fcgi.sock
新建 nginx-fcgi 脚本指令配置,直接从 fastcgi_params 复制模板:
cp /etc/nginx/fastcgi_params /etc/nginx/nginx_fcgi_params
去除尾部的:
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
新建示例 cgi 站点配置:
server {
listen 80;
server_name test.local;
location ~ ^/cgi-bin/.*\.cgi$
{
root /work/www/test;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include nginx_fcgi_params;
fastcgi_read_timeout 5m;
fastcgi_pass unix:/var/run/nginx-fcgi.sock;
}
}
重启 nginx,cgi配置完成。
三、Nagios安装(服务端)
useradd 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 gd-devel
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-htmurl=/ --with-cgiurl=/cgi-bin
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 Web界面登陆帐号及密码
借用Apache的htpasswd命令工具
yum install httpd
service httpd stop && chkconfig httpd off #不启用Apache
/usr/local/apache/bin/htpasswd -nb nagiosadmin 123456 > /usr/local/nagios/etc/htpasswd.users
生成加密文件
cat /usr/local/nagios/etc/htpasswd.users
nagiosadmin:wqx7mC26z5vKs
* 修改配置文件
打开 /usr/local/nagios/etc/cgi.cfg,修改 use_authentication 为:
use_authentication=0
即去除用户验证,然后重启 nagios。
(否则会提示:It appears as though you do not have permission to view information for any of the hosts you requested... ,无法显示host和service列表)
打开 /usr/local/nagios/share/config.inc.php,把:
$cfg['cgi_base_url']='/nagios/cgi-bin';
改为(根据自己的实际情况修改,可能不用改):
$cfg['cgi_base_url']='/cgi-bin';
如果报错:Error: No such CGI app - /usr/local/nagios/sbin/cgi-bin/status.cgi may not exist or is not executable by this process.
则一般都是这里的错误,此处修改的位置根据上面configure编译nagios时定义–with-cgiurl=/cgi-bin修改,本人的这次安装不知道哪里出问题,编译nagios带参数–with-cgiurl=/cgi-bin,此处却必须为 $cfg['cgi_base_url']='/nagios/cgi-bin';不能修改,可能带的参数编译不成功
启动前先检查下配置文件是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有报错,可以启动Nagios服务
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
【或者/etc/init.d/nagios start】
查看nagios监控状态
/usr/local/nagios/bin/nagiostats
四、配置pnp4nagios使nagios画图
1、首先安装rrdtool等相关依赖环境
yum install -y pango pango-devel freetype freetype-devel libpng libpng-devel gettext gettext-devel libjpeg libjpeg-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart* ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bisonautoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-devellibpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel
yum install -y rrdtool perl-rrdtool rrdtool-devel
2、开始安装pnp4nagios
tar xvf pnp4nagios-0.6.25.tar.gz
cd pnp4nagios-0.6.25
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make all
make install
make install-webconf
make install-config
make install-init
3、创建配置文件
cd /usr/local/pnp4nagios/etc
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
mv npcd.cfg-sample npcd.cfg
mv process_perfdata.cfg-sample process_perfdata.cfg
mv rra.cfg-sample rra.cfg
cd pages
mv web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands
mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
mv check_nrpe.cfg-sample check_nrpe.cfg
mv check_nwstat.cfg-sample check_nwstat.cfg
4、重启npcd服务
/etc/init.d/npcd restart
5、修改 nagios 的配置文件.打开performance_data
vim /usr/local/nagios/etc/nagios.cfg
以下三项有注释则去掉,并按以下修改
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
6、修改commands.cfg,添加新的"process-host-perfdata"和"process-service-perfdata",如果原有定义,则注释掉原定义
vim /usr/local/nagios/etc/objects/commands.cfg
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
7、添加小太阳模版,镶嵌在nagios页面上
vim /usr/local/nagios/etc/objects/templates.cfg
define host {
name hosts-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name services-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
8、修改 hosts.cfg和services.cfg,添加hosts-pnp和services-pnp
vim /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server,hosts-pnp
host_name 123.206.34.2
alias 123.206.34.2
address 123.206.34.2
}
vim /usr/local/nagios/etc/objects/services.cfg
define service {
use generic-service,services-pnp
host_name 123.206.34.2
service_description Disk / Partition
check_command check_nrpe!check_disk!15%!10%!/
}
9、重启nagios服务
/etc/init.d/nagios restart
四、nginx配置文件
vim /usr/local/nginx/conf/vhost/nginx.conf
server
{
listen 80;
server_name nagios.test.com;
root /usr/local/nagios/share;
index index.php index.html index.htm;
charset utf-8;
expires 2h;
location ~ .*\\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
auth_basic "Nagios Login";
auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
}
location ~ .*\\.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\\.cgi /$1.cgi break;
#rewrite ^/nagios/(.*)\\.cgi /$1.cgi break;
fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.sock;
fastcgi_index index.cgi;
#fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_ACCEPT_LANGUAGE zh-cn;
include fcgi.conf;
auth_basic "Nagios Login";
auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
}
location /nagios/ {
alias /usr/local/nagios/share/;
}
##如果没有配置pnp4nagios画图,以下两段location则不用配置
##在nagios监控页面点击小太阳图标时如果显示404找不到rrd图片文件,则需要注意以下配置是否正确无误
location /pnp4nagios {
alias /usr/local/pnp4nagios/share;
index index.php;
try_files $uri $uri/ @pnp4nagios;
}
location @pnp4nagios {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME /usr/local/pnp4nagios/share/index.php;
}
}
vim /usr/local/nginx/conf/fcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
或者
(nginx + php-fpm页面显示空白的问题http://blog.sina.com.cn/s/blog_67d781d20101nhy0.html)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
附加参考:
http://cwtea.blog.51cto.com/4500217/1278745/
http://blog.csdn.net/remote_roamer/article/details/49414173
nginx环境下搭建nagios 3.5.0,及配置pnp4nagios画图的更多相关文章
- Windows环境下搭建Hadoop(2.6.0)+Hive(2.2.0)环境并连接Kettle(6.0)
前提:配置JDK1.8环境,并配置相应的环境变量,JAVA_HOME 一.Hadoop的安装 1.1 下载Hadoop (2.6.0) http://hadoop.apache.org/release ...
- web服务器Nginx环境下如何实现安全证书https的配置
https跟http的关系 https没出现之前,我们网站大多数都是http开头,http全名超文本传输协议,客户端据此获取服务器上的超文本内容.超文本内容则以HTML为主,客户端拿到HTML内容后可 ...
- 在nginx环境下搭建基于ssl证书的websocket服务转发,wss
1.证书准备 本地调试,可以安装自签名证书,安装方法参考https本地自签名证书添加到信任证书访问 2.修改配置文件 将上面的配置文件拷贝到conf目录,添加或者修改节点如下 # HTTPS serv ...
- 在nginx环境下搭建https服务,代理到本地web项目
安装过程略. 1.证书准备 本地调试,可以安装自签名证书,安装方法参考https本地自签名证书添加到信任证书访问 2.修改配置文件 将上面的配置文件拷贝到conf目录,添加或者修改节点如下 http{ ...
- linux环境下搭建osm_web服务器一(Postgresql配置及osm2pgsql原始数据导入):
Postgresql配置及osm2pgsql原始数据导入 2012年,Ubuntu 12.04LTS发布,又一个长效支持版,我们又该更新OpenStreetMap服务器了,这次,将详细在博客中记录配置 ...
- nginx环境下配置nagios-关于nagios配置文件nginx.conf
接上文:nginx环境下配置nagios-关于nginx.conf 配置如下: ; location ~ .*\.(php|php5)?$ { ...
- Ubuntu下搭建Hyperledger Fabric v1.0环境
多次尝试才正常启动了Fabric,如遇到各种莫名错误,请参考如下一步步严格安装,特别用户权限需要注意. 一.安装Ubuntu16 虚拟机或双系统,虚拟机有VirtualBox或者VMware,Ub ...
- nginx环境下配置nagiosQL-关于nagiosql配置文件
接上文:nginx环境下配置nagios-关于nginx.conf nagiosql文件应该处于conf/domain/目录下 nagiosql配置如下: ; gzi ...
- Nginx基础知识之————Nginx 环境的搭建?
本课时主要给大家讲解如何在 Linux 系统下搭建 Nginx 和 Nginx 搭建过程中常见问题的知识,并结合实例让学员掌握 Nginx 环境的搭建. 下载解压: 安装gcc-c++ 从新配置文件: ...
随机推荐
- python函数参数的pack与unpack
python函数参数的pack与unpack 上周在使用django做开发的时候用到了mixin(关于mixin我还要写一个博客专门讨论一下,现在请参见这里),其中又涉及到了一个关于函数参数打包(pa ...
- HDU 4627(最小公倍数最大问题)
HDU 4627 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- ARM9的MMU
一 页表 1. 页表是放置在RAM(一般为DRAM)中的一个数据段. 2. ARM的地址空间为2^32字节,即4G字节. 3. 一级页表总共有4096条记录,每条记录对应的地址块为1M,一级页表中的记 ...
- easyui tabs 真正刷新用法
//刷新当前标签Tabs function RefreshTab(currentTab) { var url = $(currentTab.panel('options')).attr('href') ...
- CGlib使用案例
实际对象: public class RealObject { public void doSomething() { System.out.println("RealObject.doSo ...
- cf B. Making Sequences is Fun
http://codeforces.com/contest/373/problem/B 用二分枚举长度就可以. #include <cstdio> #include <cstring ...
- SQL(二) 将一张表数据插入另外一张表
INSERT INTO BaomingRelation ([BaomingID] ,[RelationNumber] ,[UserID] ,[Area]) SELECT BaomingID,NEWID ...
- 【HDOJ】1243 反恐训练营
LCS. /* 1243 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...
- Delphi——Window 消息 - 转载▼
Delphi是Borland公司的一种面向对象的可视化软件开发工具. Delphi集中了Visual C++和Visual Basic两者的优点:容易上手.功能强大,特别是在界面设计.数据库编程.网络 ...
- Android---优化下载让网络访问更高效(三)
批处理传输和连接 每次启动一个连接---跟传输的数据大小无关---在使用典型的3G无线信号时,就会潜在的导致无线信号消耗近20秒的电量. 如果一个应用程序每隔20秒ping一次服务器,只是告知该应用程 ...