配置Nconf管理NAGIOS更简单且效率更高
参照上一篇NAGIOS之SNMP方式监控系统的博文,安装好LAMP环境和NAGIOS.
一.本文的案例所需软件
nconf-1.2.6-0.tgz
pnp4nagios-0.6.18.tar.gz
NSCLIENT++
cgilib-0.6.tar.gz
rrdtool
pnp4nagios-0.6.7.tar.gz
二.安装nconf
1.解压安装包
tar -xf nconf-1.2.6-0.tgz -C /var/www/html/
2.配置nconf所需的数据库级授权用户
mysql> CREATE DATABASE nconf;
Query OK, 1 row affected (0.01 sec)
mysql> GRANT ALL ON nconf.* TO 'nconf'@'localhost' IDENTIFIED BY 'nconf';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
3.修改目录用户权限
chown -R apache.apache config/ temp/ static_cfg/ output/
4.访问nconf http://ip/nconf
…………
5.按照需求删除以安装文件
6.测试登录
二.配置NCONF
1.无法连接数据库
2.配置NCONF链接数据库及执行脚本
ln -s /usr/local/nagios/bin/nagios bin/nagios
chmod +x /var/www/html/nconf/bin/generate_config.pl
chown -R apache.apache bin/
chmod +x /usr/local/nagios/bin/nagios
chmod +x /var/www/html/nconf/ADD-ONS/deploy_local.sh
vim /var/www/html/nconf/ADD-ONS/deploy_local.sh //根据环境修改里面的nagios路径,此处无需修改
3.执行脚本,在/usr/local/nagios/etc/下生成两个目录Default_collector 与global 用于存放通用nconf定义的监控资源
cd ADD-ONS/
./deploy_local.sh
Running configuration check...done.
Reloading nagios configuration...done
4.添加至crontab中让其每隔一分钟执行一次
*/1 * * * * /bin/sh /var/www/html/nconf/ADD-ONS/deploy_local.sh
5.修改nagios.cfg配置文件加注释,添加如下两行
vim /usr/local/nagios/etc/nagios.cfg
6.重启Nagios
7.以上Nconf 配置完成,安装客户端手动添加监控资源测试
8.在被监控机上安装Windows客户端.
9.配置ini文件填入nagios地址,后重启客户端
10.添加监控资源
11.此处省略只列出各属性的参数值
CPU
Memory
12.自定义端口
13.配置邮件告警,将等三方程序sendEmail 传入监控机 并添加执行权限(用法请参考上一篇NAGIOS之SNMP监控的博文,这里不再赘述)
14.分别填入以下内容
/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s 1.1.1.1 -u "** $NOTIFICATIONTYPE$ Address: $HOSTADDRESS$ is $HOSTSTATE$ **"
/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s 1.1.1.1 -u "** $NOTIFICATIONTYPE$ Address:$HOSTADDRESS$ ServiceAlert:$SERVICEDESC$ is $SERVICESTATE$ **"
15.测试邮件通知功能,这里先定义参数值为20 警告,30严重 (邮件通知有点延迟)
三.安装PNP4NAGIOS
1.安装cgilib
tar -zxvf cgilib-0.6.tar.gz
cd cgilib-0.6
make
cp aux.h /usr/include/
cp cgi.h /usr/include/
cp libcgi.a /usr/lib/
2.安装rrdtool
yum �Cy localinstall rrdtool-*
3.安装pnp4nagios
cd /usr/lib/perl5/5.8.8/i386-linux-thread-multi
cp /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/RRDs.pm /usr/lib/perl5/5.8.8/i386-linux-thread-multi/
测试: perl -MRRDs -le 'print q(ok!)'
注:以上步骤采用rpm包安装rrdtool时请忽略
tar -zxvf pnp4nagios-0.6.18.tar.gz
cd pnp4nagios-0.6.18/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
make;make all
make install
make install-webconf(可不装)
make install-config
make install-init(可不装)
(make fullinstall-本命令安装上述所有步骤)
4.配置apache
vi /etc/httpd/conf/httpd.conf
末尾添加如下信息
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.user
Require valid-user
<IfModule mod_rewrite.c>
RewriteEngine On
Options FollowSymLinks
RewriteBase /pnp4nagios/
RewriteRule ^(application|modules|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
</Directory>
保存后重启apache服务: service httpd restart
http://192.168.1.109/pnp4nagios/index.php
rm -rf /usr/local/pnp4nagios/share/install.php
5.配置NCONF支持PNP
6.填入以下内容
/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
7.填入以下内容
/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'class='tips'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
8.分别真入以下内容
process-host-perfdata
/usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
process-service-perfdata
/usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
9.创建host-pnp 及srv-php 模板
10.分别选择上面定义的action_url,执行测试配置文件选项无报错稍后即可出图