pnp4nagios的安装
Toc
  1. 安装rrdtool
  2. 安装pnp4nagios
  3. 安装php和php-fpm
  4. 配置nginx

pnp4nagios依赖rrdtool,把数据写入RRD文件,同时需要一个web服务器来托管pnp4nagios的php页面,因为需要安装rrdtool、pnp4nagios、php、nginx。

安装rrdtool

在系统CentOS 5.9上,我通过rpm安装rrdtool以及它的perl模块,版本为1.4.7。其他版本可以在http://pkgs.repoforge.org/rrdtool/下载。

cd /tmp
wget http://pkgs.repoforge.org/rrdtool/perl-rrdtool-1.4.7-1.el5.rf.x86_64.rpm
wget http://pkgs.repoforge.org/rrdtool/rrdtool-1.4.7-1.el5.rf.x86_64.rpm

# 删除已有版本1.2.7
yum remove rrdtool

rpm -ivh perl-rrdtool-1.4.7-1.el5.rf.x86_64.rpm rrdtool-1.4.7-1.el5.rf.x86_64.rpm


安装pnp4nagios

pnp4nagios从sourceforge上下载最新版本,configure时配置rrd文件路径perfdata文件池目录spool日志文件目录,其他配置项可通过./configure --help查看

cd /tmp
wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.21.tar.gz/download
cd pnp4nagios-0.6.21
./configure\
  --prefix=/home/pnp4nagios \
  --with-nagios-user=nagios \
  --with-nagios-group=nagios \
  --with-rrdtool=/usr/bin/rrdtool  \
  --with-perfdata-dir=/diska/pnp4nagios/perfdata \
  --with-perfdata-spool-dir=/diska/pnp4nagios/spool \
  --with-perfdata-logfile=/diska/pnp4nagios/perf_logs

configure后的信息如下:

*** Configuration summary for pnp4nagios-0.6.21 03-24-2013 ***

  General Options:
  -------------------------         -------------------
  Nagios user/group:                nagios nagios
  Install directory:                /home/pnp4nagios
  HTML Dir:                         /home/pnp4nagios/share
  Config Dir:                       /home/pnp4nagios/etc
  Location of rrdtool binary:       /usr/bin/rrdtool Version 1.4.7
  RRDs Perl Modules:                FOUND (Version 1.4007)
  RRD Files stored in:              /diska/pnp4nagios/perfdata
  process_perfdata.pl Logfile:      /diska/pnp4nagios/perf_logs
  Perfdata files (NPCD) stored in:  /diska/pnp4nagios/spool

  Web Interface Options:
  -------------------------         -------------------
  HTML URL:                         http://localhost/pnp4nagios
  Apache Config File:               /etc/httpd/conf.d/pnp4nagios.conf

再接着编译安装

make all  
make fullinstall

一开始我采用pnp4nagios的npcd来读取数据,启动npcd,npcd进程会扫描spool目录/diska/pnp4nagios/spool(spool目录在configure时配置,或者在配置文件/home/pnp4nagios/etc/npcd.cfg进行修改)

/etc/init.d/npcd start

同时我在/home/pnp4nagios/etc/npcd.cfg配置了npcd的日志也输出到/diska/pnp4nagios/perf_logs中,本意打算把各种日志都存入这个目录,方便查看。

安装php和php-fpm

./configure --prefix=/home/pnp --enable-fpm --with-gd --with-zlib
make
make install

修改配置/home/php/etc/php-fpm.conf,监听socket修改为: listen = /home/php/php-fastcgi.sock,打开pid文件路径,然后启动php-fpm

# 启动
/home/pnp/sbin/php-fpm
# 重启,发送INT信号
cat /home/php/var/run/php-fpm.pid | xargs kill -INT
# 重启,发送USR2信号
cat /home/php/var/run/php-fpm.pid | xargs kill -USR2


配置nginx

安装略,主要是配置,在nginx的配置文件中,引入pnp4nagios的配置模板内容,/home/nginx/conf/nginx.conf截取如下

# ... 
http {
    # ... 
    server {
        listen       80; 

        location /pnp4nagios {
            alias /home/pnp4nagios/share;
            index index.php;

            #auth_basic "Nagios Access";
            #auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;

            # if we have e.g. /pnp4nagios/media/css/common.css
            # nginx will check
            # /usr/local/png4nagios/share/media/css/common/css
            # and return it if it's found
            # if it can't find a matching file even adding a trailing /
            # the request is handled to the @pnp4nagios location
            try_files $uri $uri/ @pnp4nagios;
        }   

        location @pnp4nagios {
            fastcgi_pass unix:/home/php/php-fastcgi.sock;
            fastcgi_index index.php;

            # implies an external file, but this is common nginx practice
            include fastcgi_params;

            # this splits out the trailing path
            # eg index.php?host -> $fastcgi_path_info == 'host'
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME /home/pnp4nagios/share/index.php;
        }   
    }   
}

alias配置php4nagios的目录,在fastcgi_pass配置php-fpm的socket文件,启动nginx后,通过http://localhost/pnp4nagios/index.php后会跳转到pnp4nagios的「配置测试页面」,包含PNP4Nagios Environment TestsKohana Environment Tests,测试正常的话,页面底部会提示:

Your environment passed all requirements. Remove or rename the /home/pnp4nagios/share/install.php file now.

若测试异常,页面上会给出红色说明,若一切都ok,则把/home/pnp4nagiosn/share/install.php删除或rename。

后续就是在http://localhost/pnp4nagios/index.php加上参数hostname和serv来访问某个机器的数据。

pnp4nagios的模板配置另外整理。



– EOF –

Categories: in_lib
Tags: nagios,perl