使用NDOUtils将Nagios监控信息存入数据库 ZT

1.NDOUtils安装需求:

Nagios正确安装运行,版本>=2.0安装目录:/usr/local/nagios

MySQL正确安装并运行,我用的是二进制安装包,安装目录:/usr/local/mysql

2.安装

下载安装包:http://www.nagios.org/download/

# 确认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中数据库连接的相关配置。

 

转自:http://blog.sina.com.cn/s/blog_4e424e210100b6vu.html 

 

=====

启动ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
========================
对于不同Nagios版本,NDOUtils有不同的启动程序,ndo2db-2x对应Nagios的2.X版本,ndo2db-3x对应Nagios的3.X版本,
我安装时Nagios3.0.3版,所以选用ndo2db-3x。
# cd /usr/local/nagios/bin
# ./ndo2db-3x -c ../etc/ndo2db.cfg
运行上述命令启动NDOUtils,查看后台日志看是否有问题。
注意,如果要停止ndo2db-3x进程,再使用kill命令杀掉对应的进程号后,还必须删除
/usr/local/nagios/var下的ndo.sock,
否则下次NDOUtils不能正常启动。
重启Nagios,并观察Nagios的后台日志,观察是否有异常。 

 

  • Download the NDOUtils
    wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-1.4b8.tar.gz 
  • Install MySQL lib
    yum install mysql-devel 
  • Compile
    tar zxvf ndoutils-1.4b8.tar.gz -C /tmp cd /tmp/ndoutils-1.4b8 ./configure --with-mysql-libs=/usr/lib/mysql make 
  • Probably need to remove "mysql" in the include line of a certain source file, in case make reports error.
  • Install
    cd src cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/ 
  • Create database
          
            
    GRANT ALL PRIVILEGES ON nagios.* TO 'nagios'@'localhost' identified by "123456";
  • Initialize database
    cd ../db ./installdb -u nagios -p 123456s -h localhost -d nagios 
  • Configure NDO
    cd ../config # copy the lines related NDO3.x in nagios.cfg to /usr/local/nagios/etc  cp ndo2db.cfg ndomod.cfg /usr/local/nagios/etc # Modify /usr/local/nagios/etc/ndo2db.cfg, change the database connection info 
  • Start the service
    /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg /etc/init.d/nagios reload

你可能感兴趣的:(nagios)