nginx-nagios-pnp4nagios-nrpe安装配置过程
一 安装PHP(version 5.3.13),使得PHP支持png,jpeg,freetype,t1lib,zlib gd,这些都是为了支持PNP
./configure –prefix=/usr/local/php –with-mysql=/usr –with-config-file-path=/usr/local/php/lib –with-png-dir=/usr/include –with-jpeg-dir=/usr/include –with-freetype-dir=/usr/include/freetype2/freetype –with-t1lib=/usr/include –with-zlib –with-zlib-dir=/usr/include –with-gd=/usr –enable-fpm
1 –with-mysqli=/usr/include/mysql 编译通不过,–with-mysql=/usr(不能是/usr/include);
2 –with-gd=/usr(不能是/usr/include);
3 –with-apxs2 和 –enable-fpm 不能同时使用,否则会出现 error:
You\’ve configured multiple SAPIs to be build. You can build only one SAPI module and CLI binary at the same time.
4 –with-apxs2=/usr/sbin/apxs 是和apache结合来使用的;–enable-fpm是和nginx结合使用的;
最后把PHP5.3.13源代码文件中的php.ini-production 复制到 /usr/local/php/lib/php.ini
二 安装nginx(version 1.2.2)
nginx的配置:
user nagios; //用户为nagios
server {
listen 80 ;
server_name localhost;
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
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 ;
include fastcgi_params ;
fastcgi_index index.cgi;
fastcgi_read_timeout 60;
}
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;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/pnp4nagios/share/index.php;
}
}
开始nginx的PHP,Perl支持
/usr/local/php/sbin/php-fpm
/usr/local/nginx/nginx-fcgi start
/usr/local/nginx/sbin/nginx -t,若没问题,就开启nginx
三 安装nagios(version 3.4.1)
建立nagios用户和安装目录
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
编译安装nagios
cd nagios-3.4.1
./configure –prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
编译安装nagios-plugins-1.4.16
cd nagios-plugins-1.4.16
./configure –prefix=/usr/local/nagios
make
make install
编译安装汉化插件(可选) nagios-cn-3.2.0
cd nagios-cn-3.2.0
./configure
make all
make install
配置nagios
cd /usr/local/nagios/etc
vim nagios.cfg
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
vim objects/template.cfg
增加hosts,service模板,pnp要用到
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
vim objects/commands.cfg
修改process-host-perfdata 和 process-service-perfdata 的command_line为以下内容:
define command{
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
define command{
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
vim objects/localhosts.cfg
在localhosts.cfg中的每个host和service中,分别增加 host-pnp,srv-pnp
define host{
use linux-server,host-pnp
host_name localhost
alias localhost
address 127.0.0.1
}
define service{
use local-service,srv-pnp
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
不要验证并设htpasswd的帐号和密码为ckthsen/711710
vim cgi.cfg
use_authentication =0
default_user_name=ckthsen
authorized_for_system_information=nagiosadmin,ckthsen
authorized_for_configuration_information=nagiosadmin,ckthsen
authorized_for_system_commands=nagiosadmin,ckthsen
authorized_for_all_services=nagiosadmin,ckthsen
authorized_for_all_hosts=nagiosadmin,ckthsen
authorized_for_all_services_commands=nagiosadmin,ckthsen
authorized_for_all_host_commands=nagiosadmin,ckthsen
四 安装rrdtool(version 1.4.7) 和 pnp4nagios(version 0.6.21)
cd rrdtool-1.4.7
./configure –prefix=/usr/local/rrdtool
make
make install
cd pnp4nagios-0.6.21
./configure –with-rrdtool=/usr/local/rrdtool/bin/rrdtool
make all
make install
make install-config
make install-init
配置PNP4nagios
cd /usr/local/pnp4nagios/etc
把这个目录下的所有以sample结尾的文件全部转为.cfg结尾的配置文件
chown -R nagios.nagios /usr/local/pnp4nagios