1、安装ndoutils
wget
tar xzvf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9
yum install mysql-devel
./configure --enable-mysql --disable-pgsql --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
make
cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /data/www/wwwroot/nagios/bin/
mysql> create database ndodb;
mysql> grant all privileges on ndodb.* to ndoutils@localhost identified by 'zzzzzzz';
mysql> flush privileges;
mysql> \q
cd db
./installdb -u ndoutils -p zzzzzzz -h localhost -d ndodb
============================注意===========================================
若出现类似错误
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at (eval 5) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Proxy, Sponge.
at ./installdb line 41
执行 yum install perl-DBD-MySQL
若出现
DBI connect('database=ndodb;host=localhost','ndoutils',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at ./installdb line 41
mkdir -p /var/lib/mysql
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock(根据实际情况而定)
=============================END_注意=========================================
cd ..
cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /data/www/wwwroot/nagios/etc/
cd /data/www/wwwroot/nagios/etc/
mv ndo2db.cfg-sample ndo2db.cfg
mv ndomod.cfg-sample ndomod.cfg
chmod 644 ndo*
chown -R nagios:nagios /data/www/wwwroot/nagios/
vim /data/www/wwwroot/nagios/etc/nagios.cfg
在最后添加
broker_module=/data/www/wwwroot/nagios/bin/ndomod-3x.o config_file=/data/www/wwwroot/nagios/etc/ndomod.cfg
vim /data/www/wwwroot/nagios/etc/ndo2db.cfg
============================begin============================
socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=ndodb
db_prefix=nagios_
db_user=ndoutils
db_pass=zzzzzzz
lock_file=/data/www/wwwroot/nagios/var/ndo2db.lock
debug_file=/data/www/wwwroot/nagios/var/ndo2db.debug
===============================end===========================
vim /data/www/wwwroot/nagios/etc/ndomod.cfg
=============================begin==========================
output_type=tcpsocket
output=127.0.0.1
buffer_file=/data/www/wwwroot/nagios/var/ndomod.tmp
================================end================================
启动 /data/www/wwwroot/nagios/bin/ndo2db-3x -c /data/www/wwwroot/nagios/etc/ndo2db.cfg
service nagios restart
tail /var/log/message
================出现类似内容===================================================
Mar 2 15:52:28 localhost nagios: Nagios 3.3.1 starting... (PID=20779)
Mar 2 15:52:28 localhost nagios: Local time is Fri Mar 02 15:52:28 CST 2012
Mar 2 15:52:28 localhost nagios: LOG VERSION: 2.0
Mar 2 15:52:28 localhost nagios: ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
Mar 2 15:52:28 localhost nagios: ndomod: Successfully connected to data sink. 5000 queued items to flush.
Mar 2 15:52:28 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.
Mar 2 15:52:28 localhost nagios: Event broker module '/data/www/wwwroot/nagios/bin/ndomod-3x.o' initialized successfully.
Mar 2 15:52:29 localhost nagios: Finished daemonizing... (New PID=20781)
============================ok成功==========================================================
cp /usr/local/src/ndoutils-1.4b9/daemon-init /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
vim /etc/init.d/ndo2db
=======================修改下面内容===========================
servicename=ndo2db
prefix=/data/www/wwwroot/nagios
exec_prefix=/data/www/wwwroot/nagios
Ndo2dbBin=/data/www/wwwroot/nagios/bin/ndo2db-3x
Ndo2dbCfgFile=/data/www/wwwroot/nagios/etc/ndo2db.cfg
Ndo2dbVarDir=/data/www/wwwroot/nagios/var
Ndo2dbRunFile=$Ndo2dbVarDir/ndo2db.lock
Ndo2dbLockDir=/var/lock/subsys
Ndo2dbLockFile=ndo2db
==========================end======================
chkconfig --add ndo2db
chkconfig ndo2db on
service ndo2db start
service nagios start
2、安装ncp,以在Cacti中展现Nagios
cd /usr/local/src
wget
tar xzvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
cp -R cacti-plugin-arch/* /data/www/wwwroot/cacti
cd /data/www/wwwroot/cacti
mysql -ucacti -pzzzzzzz cacti < pa.sql
patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff
vim include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;
$url_path = "/cacti/"; 注:此路径根据cacti 在apache中的设置而定
用浏览器打开cacti 点击 User Management>admin>最下面勾选Plugin Management>save
npc 包 见附件
tar xzvf npc-2.0.4.tar.gz
mv npc /data/www/wwwroot/cacti/plugins/
vim /data/www/wwwroot/cacti/include/config.php
$plugins[] = 'npc';
wget Fedoraproject.org/repo/pkgs/php-pecl-json/json-1.2.1.tgz/d8904d2f004ceec85eeacf524cd25539/json-1.2.1.tgz
tar xvf json-1.2.1.tgz
cd json-1.2.1
/usr/local/php-5.2.17/bin/phpize
./configure --with-php-config=/usr/local/php-5.2.17/bin/php-config --enable-shared --enable-static --with-json
make&&make install
vim /usr/local/php-5.2.17/etc/php.ini
extension_dir = "/usr/local/php-5.2.17/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "json.so"
访问cacti
Configuration -> Plugin Management -> Actions -> 箭头点击安装 -> 右击绿色箭头启用,这时页面就有NPC选项
mysql -u cacti -pzzzzzzz
use cacti;
Database changed
mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
mysql> \q
在Settings->npc中 ,勾上Remote Commands
Nagios Command File Path=/data/www/wwwroot/nagios/var/rw/nagios.cmd
Nagios URL=http://localhost/nagios/
点击 npc 只出图不出数据,检查是否安装了pdo-mysql,编译安装方法如下(路径根据实际情况):
cd /usr/local/src/php-5.2.17/ext/pdo_mysql
/usr/local/php-5.2.17/bin/phpize
./configure --with-php-config=/usr/local/php-5.2.17/bin/php-config --with-pdo-mysql=/usr/local/mysql-5.1.56/
make && make install
vim /usr/local/local/php-5.2.17/etc/php.ini
===================最后加入============================
extension_dir = "/usr/local/php-5.2.17/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "pdo_mysql.so"
============================END=====================================