分类: LINUX
2009-12-29 11:09:07
使用NDOUtils将Nagios监控信息存入数据库
1.NDOUtils安装需求:
Nagios正确安装运行,版本>=2.0安装目录:/usr/local/nagios
MySQL正确安装并运行,我用的是二进制安装包,安装目录:/usr/local/mysql
2.安装
下载安装包:
# 确认DBD-mysql包安装,如没有安装,请先安装。
# 如果DBI包没安装DBD-mysql前需要先安装DBI包
tar xzvf DBI-1.605.tar.gz
cd DBI-1.605
perl Makefile.PL
make
make install
tar xzvf DBD-mysql-3.0008.tar.gz
cd DBD-mysql-3.0008
unset LANG
perl Makefile.PL –libs=”-L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr/lib -lz ” –cflags=”-I/usr/local/mysql/include” –testhost=127.0.0.1 –mysql_config=/usr/local/mysql/bin/mysql_config –testuser=root –testpassword=baihe.com
make
make install
# 做好MySQL库文件lib和include文件的连接(这点很重要)。
ln -s /usr/local/mysql/include/* /usr/include/
mkdir /usr/include/mysql
ln -s /usr/local/mysql/include/* /usr/include/mysql/
ln -s /usr/local/mysql/lib/* /usr/lib/
mkdir /usr/lib/mysql
ln -s /usr/local/mysql/lib/* /usr/lib/mysql
tar xzvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure –enable-mysql
# 执行完成后,注意向上看看打印出的信息,看看是否找到了MySQL的库文件和include文件。
make
cd src/
# 我的Nagios是3.0.5,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x请拷贝ndomod-2x.o、ndo2db-2x
cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin
cd ../db
# 创建数据库,使用root用户,密码是baihe.com
mysqladmin -u root -pbaihe.com create nagios
./installdb -u root -p baihe.com -d nagios
# 拷贝配置文件
cd ../config
cp ndo* /usr/local/nagios/etc/
# 修改/usr/local/nagios/etc/ndo2db.cfg文件的数据库信息。
vi /usr/local/nagios/etc/ndo2db.cfg
vi nagios.cfg
# 复制下面内容粘贴到/usr/local/nagios/etc/nagios.cfg配置文件的#broker_module=…下面。
# Uncomment the line below if you’re running Nagios 3.x
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
# 修改/usr/local/nagios/etc/nagios.cfg配置文件下面参数的值为-1(一般默认如此)。
event_broker_options=-1
# 启动ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# 查看系统日志是否有错误信息:
tail -30 /var/log/messages
Nov 27 14:09:26 tech nagios: ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)
Nov 27 14:09:26 tech nagios: ndomod: Successfully connected to data sink. 0 queued items to flush.
Nov 27 14:09:26 tech nagios: Event broker module ‘/usr/local/nagios/bin/ndomod-3x.o’ initialized successfully.
Nov 27 14:09:26 tech nagios: Finished daemonizing… (New PID=18848)
# 重启Nagios
service nagios restart
# 查看Nagios日志,看是否正常启动。
tail -20 /usr/local/nagios/var/nagios.log
[1227766166] ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)
[1227766166] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1227766166] Event broker module ‘/usr/local/nagios/bin/ndomod-3x.o’ initialized successfully.
[1227766166] Finished daemonizing… (New PID=18848)
3.如何用NDOUtils将多个Nagios实例的性能数据写入一个数据库?
配置方法类似于上面的单实例单数据库模式,只是在装第二个实例时省去安装DB一步,并需要修改/usr/local/nagios/etc/ndomod.cfg中的实例名。
实例名默认为instance_name=default,如果有多个实例必需修改成不同的实例名。
如:instance_name=nagios1
注意修改/usr/local/nagios/etc/ndo2db.cfg中数据库连接的相关配置。