Nagios Cacti完全安装与整合(6)

------------第四部分:整合nagios与cacti--------------


整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。

1.首先需要安装ndoutils以将nagios的数据能导入到mysql数据库中
yum -y install mysql-devel

下载并安装ndoutils
wget
tar zxvf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9

./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/lib64 --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
make

2.建立配置文件
cp src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin
cd db
./installdb -ucacti -pcacti -d cacti
cd ..
cp config/{ndo2db.cfg-sample,ndomod.cfg-sample} /usr/local/nagios/etc
mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chmod 644 /usr/local/nagios/etc/ndo*
chown nagios:nagios /usr/local/nagios/etc/*
chown nagios:nagios /usr/local/nagios/bin/*

3.修改nagios.cfg配置文件以适应当前环境
vi /usr/local/nagios/etc/nagios.cfg
在文件中添加如下内容:
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

4.修改ndo2db.cfg以适应当前环境
vi /usr/local/nagios/etc/ndo2db.cfg
把与下面相关的参数修改成如下形式(有此不用改):
socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cacti
db_prefix=nagios_
db_user=cacti
db_pass=cacti

5.修改ndomod.cfg以适应当前环境
vi /usr/local/nagios/etc/ndomod.cfg
把与下面相关的参数修改成如下形式:
output_type=tcpsocket
output=127.0.0.1

6.让ndo2db开机启动
方法一:
加入到开机启动配置文件:
echo 'rm -f /usr/local/nagios/var/ndo.sock' >> /etc/rc.local
echo '/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg' >> /etc/rc.local

方法二:
cd /usr/local/src/ndoutils-1.4b9
cp ./daemon-init /etc/init.d/ndo2db
vi /etc/init.d/ndo2db
把Ndo2dbBin=/usr/local/nagios/bin/ndo2db改成
Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x

chmod +x /etc/init.d/ndo2db
service ndo2db start
启动时出现如下错误:
Starting ndo2db:Support for the specified database server is either not yet supported, or was not found on your system.
 done.
这个是由于没有安装mysql-devel这个包造成的@!@@@@
解决办法:
yum -y install mysql-devel
./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/lib64 --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
make
alias cp=cp
cp src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin
alias cp="cp -i'


7..npc安装
tar zxvf npc-2.0.4.tar.gz
mv npc /usr/local/cacti/plugins/

修改 cacti 配置文件,添加npc 插件
vi /usr/local/cacti/include/config.php
加入:
$plugins[] = 'npc';
启用方法同其它插件方法一样!!!!!!!!!!!!!!!!!
回到控制台,我们会发现多了一个“npc”选项

安装 npc支持:json
wget
tar zxvf json-1.2.1.tgz
cd json-1.2.1
phpize
./configure ;make ;make install

查看是否安装成功:
root@nagios_cacti json-1.2.1]# ll /usr/lib64/php/modules
总计 840
-rwxr-xr-x 1 root root  32344 2010-01-14 dbase.so
-rwxr-xr-x 1 root root 337768 2010-01-14 gd.so
-rwxr-xr-x 1 root root  92798 03-14 06:05 json.so
-rwxr-xr-x 1 root root 119568 2010-01-14 mysqli.so
-rwxr-xr-x 1 root root  53008 2010-01-14 mysql.so
-rwxr-xr-x 1 root root  28264 2010-01-14 pdo_mysql.so
-rwxr-xr-x 1 root root  92464 2010-01-14 pdo.so
-rwxr-xr-x 1 root root  24200 2010-01-14 pdo_sqlite.so
-rwxr-xr-x 1 root root  15416 2009-09-04 phpcups.so
-rwxr-xr-x 1 root root  28568 2010-01-14 snmp.so

修改php.ini文件添加对json的支持
vi /etc/php.ini
添加如下内容:
extension=json.so

重新启动apache
service httpd restart

查看是否加载了这个模块:
php -m |grep json

接着在右侧栏目中选择settings,点选npc的标签
钩选Remote Commands
Nagios Command File Path: /usr/local/nagios/var/rw/nagios.cmd
<这个文件启动nagios后会产生,根据实际的位置写>
Nagios URL:   (这里ip为nagios服务器IP)
保存就可以了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6c3d69c5560e55fe936d144eb79b473f.html