- 通过整合pnp4nagios,ndoutils,nconf提供了关于nagios的一套完整的配置方案
- 操作系统Centos5.5
- 目前nagios最新版本的nagios3.4.1
- 首先把编译环境准备好,我们这里把开发库先都装上
- yum groupinstall "Development Libraries" "Development Tools" "Legacy Software Development"
- "X Software Development" -y
- 相关依赖包
- yum -y install mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel ruby
- ruby-devel2 ruby-devel mysql-devel libpng libpng-devel libjpeg libjpeg-devel zlib zlib-devel
- yum默认安装的是5.1版本的php,但是pnp4nagios-0.6.6需要5.2以上版本的php,我们这里就装5.3的
- yum search php 看看有没有php53相关的包,没有请配置好相关的源
- yum install php53-*
- 准备如下软件包
-rw-r--r-- 1 root root 1782817 Jul 9 08:45 nagios-3.4.1.tar.gz
-rw-r--r-- 1 root root 2087089 Jul 9 14:36 nagios-plugins-1.4.16.tar.gz
-rw-r--r-- 1 root root 491706 Jul 6 14:40 nconf-1.3.0-0.tgz
-rw-r--r-- 1 root root 2135521 Jul 6 14:42 ndoutils-1.4b9.tar.gz
-rw-r--r-- 1 root root 405725 Dec 14 2011 nrpe-2.12.tar.gz
-rw-r--r-- 1 root root 2815857 Sep 15 2011 pnp4nagios-0.6.15.tar.gz
-rw-r--r-- 1 root root 2135521 Jul 6 14:42 ndoutils1.4b9_light.patch- 建立相关用户和组
- useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G apache nagios- 安装nagios
- tar zxvf nagios-3.4.1.tar.gz -C /usr/src
cd /usr/src/nagios-3.4.1
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd- --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
- make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf- 生成web管理界面用户和密码
- htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //登录nagios web界面时的
- 用户为nagiosadmin 下面输入的密码为此用户密码
- chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on
chkconfig mysqld on- 安装插件
- tar zxvf nagios-plugins-1.4.16.tar.gz -C /usr/src
cd /usr/src/nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install- service nagios start
service httpd start
service mysqld start
使用http://localhost/nagios/来访问- 点开service会看到本机的httpd服务有个告警,并提示HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002
- second response time
- 修改下面的配置文件即可消除错误
- vim /usr/local/nagios/etc/objects/localhost.cfg
- define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 1 #######此处改为1- define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 1 ########此处改为1
}- 提示HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002 second response time是因为在目前网站根目录下面没
- 有首页文件,可自己建立一个index.html的文件放在/var/www/html/下面,如果是源码安装的请放在定义的网站根下面。
- 重启Nagios和httpd服务刷新页面即可
- ################################################################################################################
- pnp4nagios的安装和配置,能够把nagios捕获到的数据绘制成图片
- 安装前准备
- yum install rrdtool-perl rrdtool-devel rrdtool
- tar zxvf pnp4nagios-0.6.15.tar.gz -C /usr/src
cd /usr/src/pnp4nagios-0.6.15
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make all
make install
make install-webconf
make install-config
make isntall-init
make fullinstall- pnp4nagios官方提供了三种配置方法,我这里选取一种
vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1 //此处修改为1- 添加如下行
- #
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::- $SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::
- $HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::- $HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
vi /usr/local/nagios/etc/objects/commands.cfg 修改最后两行为- define command{
command_name process-service-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --- bulk=/usr/local/pnp4nagios/var/service-perfdata
}
define command{
command_name process-host-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-- perfdata
}
cd /usr/local/pnp4nagios/share
mv install.php install.php.bak- 访问测试 http://localhost/pnp4nagios
- ############################################################################
- 让nagios显示小太阳图标
在pnp4nagios的源码包下面执行- cp contrib/ssi/* /usr/local/nagios/share/ssi/
- 然后在服务或者主机定义里面添加action_url
- #vi /usr/local/nagios/etc/objects/templates.cfg
- define host{
use linux-server
host_name localhost
alias localhost
address 127.0.0.1
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips'- rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ //添加此行
}- define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'- class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ //添加此行
}- 此时在web界面的ping旁边会显示一个小的图标,把鼠标放上去会放大
########################################################################################################- 安装nconf实现nagios的图形化配置,可以直接在web界面操作,不用去编辑配置文件
- tar zxvf nconf-1.3.0-0.tgz -C /var/www/html/
chown -R apache.apache /var/www/html/nconf/- 为nconf创建数据库,默认Mysql安装后没有密码,后面要用到密码,这里提前设置一个密码
- mysqladmin -u root password "p@ssw0rd"
- mysql -u root -p
- create database nconf;
- grant all privileges on nconf.* to 'nconf'@localhost identified by 'nconf' with grant option;
cp /usr/local/nagios/bin/nagios /var/www/html/nconf/bin- chown apache.nagios /var/www/html/nconf/bin/nagios
- 然后通过浏览器访问: http://localhost/nconf
- 按照提示安装,并输入上面创建的数据库和用户及密码
- 根据提示进行安装 然后删除/var/www/html/nconf/下面的 INSTALL/ INSTALL.php UPDATE/ UPDATE.php重新刷新页面就可以
- 使用了!
- 如果用WEB配置时提示mysql、nconf错误时,可手工设置/var/www/html/nconf/config下的mysql.php与nconf.php文件
- 把mysql.php里的相应相应项做更改,如:
- define('DBHOST', "localhost");
define('DBNAME', "nconf");
define('DBUSER', "nconf");
define('DBPASS', "nconf");
- nconf.php文件:
- define('NCONFDIR', "/var/www/html/nconf");
- define('NAGIOS_BIN', "/var/www/html/nconf/bin/nagios");
- 如要做Nconf认证,使用file认证类型 //web配置时如果使用认证才可以配置,那么先按照如下配置再进行
- 修改/var/www/html/nconf/config/authentication.php如下:
- define('AUTH_ENABLED', '1');
- 此时默认帐号是admin,密码nconf,具体可见/var/www/html/nconf/include/login_check.php
- 及/var/www/html/nconf/./index.php
- 帐号密码保存在/var/www/html/nconf/config/.file_accounts.php文件中,帐号密码格式如下
- #username::password::authorization(user|admin)::[user's full name (optional)]::
admin::nconf::admin::Administrator::- 然后再打开http://localhost/nconf,此时跟前面的会不一样,全部下一步就好,最好提示删除INSTALL/ INSTALL.php UPDATE/
- UPDATE.php,照做就行
###############################################################################################################- 安装配置ndoutils把nagios的数据导入mysql数据库
mysql -u root -p
mysql>CREATE DATABASE nagios;
mysql>GRANT ALL ON nagios.* TO 'nagios'@localhost IDENTIFIED BY ‘nagios’ #授权nagios用户,密码为 nagios
mysql>FLUSH PRIVILEGES;
wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-1.4b9.tar.gz
wget http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.4b9_light.patch- tar zxvf ndoutils-1.4b9.tar.gz /usr/src
cd /usr/src/ndoutils-1.4b9- 把补丁包放在/usr/src/ndoutils-1.4b9目录下面
- patch -p1 -N < ndoutils1.4b9_light.patch
提示补丁成功打上- ./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-
- group=nagios
make
cd db/
./installdb -u root -p 数据库密码 -d nagios
mysql -u root -p- mysql>USE nagios;
mysql>SHOW TABLES; //查看验证表已经生成- cd ndoutils-1.4b9
- cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chmod 774 /usr/local/nagios/bin/ndo*
chown nagios:nagios /usr/local/nagios/bin/ndo*
chown nagios:nagios /usr/local/nagios/etc/ndo*
vi ndo2db.cfg
db_name=nagios
db_user=nagios //修改为nagios
db_pass=nagios //修改为nagios- vi /usr/local/nagios/etc/nagios.cfg
- 添加以下行
- broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
- cp ./daemon-init /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
chkconfig --add ndo2db
service nagios restart- 如果启动失败使用命令检查,看看是什么地方出错,并修正
- /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service ndo2db start- tail -f /usr/local/nagios/var/nagios.log
- [root@test ndoutils-1.4b9]# cat /usr/local/nagios/var/nagios.log
[1345086976] Nagios 3.4.1 starting... (PID=22899)
[1345086976] Local time is Thu Aug 16 11:16:16 CST 2012
[1345086976] LOG VERSION: 2.0
[1345086976] Finished daemonizing... (New PID=22900)
[1345088085] Finished daemonizing... (New PID=27417)
[1345088175] SERVICE ALERT: localhost;HTTP;OK;HARD;4;HTTP OK: HTTP/1.1 200 OK - 302 bytes in 0.001 second- response time
[1345089958] Caught SIGTERM, shutting down...
[1345089958] Successfully shutdown... (PID=27417)
[1345089958] Nagios 3.4.1 starting... (PID=8993)
[1345089958] Local time is Thu Aug 16 12:05:58 CST 2012
[1345090128] LOG VERSION: 2.0
[1345090128] ndomod: NDOMOD-MERETHIS 1.4b9-merethis (10-27-2009) Copyright (c) 2009 Nagios Core Development Team- and Community Contributors
[1345090128] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1345090128] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully. //初始化成功
[1345090128] Finished daemonizing... (New PID=9360)- 二、php session权限问题
- 访问pnp4nagios时有
- An error was detected which prevented the loading of this page. If this problem persists, please contact the
- website administrator.
- /usr/local/pnp4nagios/lib/kohana/system/libraries/Session.php [160]:
- session_start(): open(/var/lib/php/sess_d1suf0cpph46v95efp1b7l0cbtt0q7nr, O_RDWR) failed: Permission denied (13)
- 错误
- 检查 /var/lib/php5目录的权限,发现原来是root才可以读写,而apache采用了nagios的用户来运行,所以php的session数据没
- 有权限写入,于是更改/var/lib/php的写入权限
chown -R nagios.nagios /var/lib/php 或
chown -R 777 /var/lib/php- ---------------------------------------------出自运维联盟-----------------------------------------