nginx环境下搭建nagios 3.5.0

本文基于《LNMP最新源码安装脚本》,Nagios依赖PHP环境和perl环境,由于Nginx不支持Perl的CGI,需先来搭建Perl环境,Nagios原理介绍略。

1、下载最新稳定源码包和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

2、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

perl Makefile.PL

make && make install

cd ..

安装IO-All模块

tar xvf IO-All-0.39.tar.gz

cd IO-All-0.39

perl Makefile.PL

make && make install

启动方法一:

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方法

启动方法二:

下载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 会执行失败。

运行前使用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配置完成。

3、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。

打开 /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

nginx配置文件:

vim /usr/local/nginx/conf/nginx.conf

user  www www;

worker_processes 10;

error_log  /data/logs/nginx_error.log  crit;

#pid        logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

}

http

{

include       mime.types;

default_type  application/octet-stream;

#charset  gbk;

server_names_hash_bucket_size 128;

client_header_buffer_size 16k;

large_client_header_buffers 4 32k;

#client_max_body_size 8m;

server_tokens off;

expires       1h;

sendfile on;

tcp_nopush     on;

keepalive_timeout 60;

tcp_nodelay on;

error_page   404  /;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 8 128k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

fastcgi_temp_path /dev/shm;

gzip on;

gzip_min_length  2048;

gzip_buffers     4 16k;

gzip_http_version 1.1;

gzip_types  text/plain  text/css     application/xml application/x-javascript ;

log_format  access  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" $http_x_forwarded_for‘;

#################  include  ###################

#       server

#       {

#               listen 81;

#               server_name empty;

#               root /data/web/webclose;

#       }

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;

}

}

server

{

listen       81;

server_name  71.69.ming.cn ;

index index.html index.htm index.php;

root  /data/web/awstats/www;

location /status/ {

stub_status on;

access_log   off;

expires off;

}

location ~ .*\.php$

{

include fcgi.conf;

fastcgi_pass  127.0.0.1:10080;

fastcgi_index index.php;

expires off;

}

access_log  /data/logs/71.69.ming.cn.log  access;

}

include block_ips.conf ;

include vhost/nagios.conf ;

}

vim /usr/local/nginx/conf/vhost/nagios.conf

server

{

listen      80;

server_name  nagios.frsy.com;

access_log     /usr/local/nginx/logs/access.log;

root /usr/local/nagios/share;

index index.php index.html index.htm;

location ~ .*\\.(php|php5)?$

{

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include  fcgi.conf;

auth_basic "Nagios Login pain";

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;

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 HTTP_ACCEPT_LANGUAGE zh-cn;

include fcgi.conf;

auth_basic "Nagios Login pain";

auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;

}

location /nagios/ {

alias /usr/local/nagios/share/;

}

}

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;

时间: 2024-11-09 01:51:30

nginx环境下搭建nagios 3.5.0的相关文章

生产环境下搭建 nagios+nconf+cacti+npc的整合

系统:CentOS6.5 内核版本系统:2.6.32-431.23.3.el6.x86_64 关闭iptables .selinux chkconfig iptables off 安装前的准备工作 yum install -y httpd-*  mysql-* php-*  net-snmp*  gcc glibc glibc-common gd gd-devel openssl* 一.nagios 环境的搭建 1.安装nagios useradd nagios tar zxf nagios-3

nginx环境下配置nagios-关于nagios配置文件nginx.conf

接上文:nginx环境下配置nagios-关于nginx.conf 配置如下: 1 server 2 { 3         listen       80; 4         server_name  192.168.44.44; 5         index index.html index.htm index.php; 6         root  /usr/local/nagios/share; 7         auth_basic "Nagios Access"; 

在CentOS 6.5下搭建Nagios

Nagios是一款很棒的监控工具,可以帮助你监控你的网络中的服务器等等,并且具有邮件问题提醒等功能,并且可以结合Nagios的硬件来监控机房的温度并实时查询和报警. 免费版的Nagios只能监控7台(记不清了,也可能是6台),但是对于小型的企业,重要的几台服务器被Nagios实时监控应该够用了. 配置环境:1)CentOS 6.5 作为监控主机,IP:10.0.0.30(根据自己公司需要改变) 2)客户机: windows server  2008R2 , windows 7, windows

nginx环境下配置nagiosQL-关于nagiosql配置文件

接上文:nginx环境下配置nagios-关于nginx.conf nagiosql文件应该处于conf/domain/目录下 nagiosql配置如下: 1 server 2 { 3         listen       8088; 4         server_name  192.168.44.44; 5         index index.html index.htm index.php; 6         root  /usr/local/nagios/nagiosql/;

nginx环境下配置nagios-关于commands.cfg

nagios监控Linux/windows常用配置,以snmp.nrpe实现 1 # 'process-host-perfdata' command definition 2 define command{  3     command_name    process-host-perfdata  4     #command_line    /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HO

lnmp环境下搭建wordpress博客程序

本文档主要介绍如何在lnmp环境下搭建完整的wordpress程序. 基本流程: 1.开源博客程序WordPress介绍 2.WordPress博客程序的搭建准备 3.开始安装blog博客程序 4.实现WordPress博客程序URL静态化 ---------------------------------------------------------------------------------------------------------------------------------

Nginx环境下配置PHP使用的SSL认证(https)

最近一段时间发现好多网站都从http协议变成了加密的https协议,比如说百度.吾志等等.https看起来比http高端了好多,而且在不同的浏览器向上还会显示出不同于http的URL展示效果(比如说chrome 和QQ浏览器 使用https协议的网址就会变色). 于是自己就想着把自己的网站加一个ssl证书,使之变成https://iwenku.net 最开始我使用的是腾讯云的服务器,服务器系统是Windows,使用Windows虽然坏处挺多,但是也有好处,那就是Windows是图形化界面的,这样

windows环境下搭建ffmpeg开发环境

ffmpeg是一个开源.跨平台的程序库,可以使用在windows.linux等平台下,本文将简单讲解windows环境下ffmpeg开发环境搭建过程,本人使用的操作系统为windows 7,集成开发环境为Visual Studio 2005,ffmpeg版本为2.2.有人可能会说都什么年代了,还VS 2005,现在VS 2010/2012/2013都出了.本人电脑也安装了VS2010,每次打开,伴随着硬盘指示灯的闪烁,以及硬盘的吱吱响声,过了许久才弹出闪屏页面,此时你的思绪可能已经飘到了南极,启

Windows环境下搭建Objective-C开发环境

Windows环境下搭建Objective-C开发环境 目前来说,如果真的想用Xcode来运行Objective-C程序,那么可以用虚拟机装Mac OS X或者装黑苹果(在PC机上安装苹果的系统,不建议),不过这两种方式都有些麻烦,以下介绍GNUstep以及Code blocks来实现,具体方法如下. 在我的云盘下载所需工具:链接: http://pan.baidu.com/s/1i34b8wP 密码: wd9e 解压后按照一下顺序进行安装 gnustep-core-0.28.0-setup.e