wangwengwu 发表于 2015-11-23 09:36:55

使用NDOUtils将Nagios监控信息存入mysql

  环境介绍:   
系统:红帽企业版5.4   
Nagios正确安装运行,版本3.0.6 安装目录:/usr/local/nagios   
MySQL正确安装并运行,安装目录:/usr/local/mysql   
1:安装DBI包   
# cd /usr/local/src/tarbag/   
# wget http://www.cpan.org/modules/by-module/DBI/DBI-1.605.tar.gz   
# tar zxvf DBI-1.605.tar.gz -C ../software/   
# cd ../software/DBI-1.605/   
# perl Makefile.PL   
# make && make install   
2:安装DBD-mysql   
# cd -   
/usr/local/src/tarbag   
# wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-3.0008.tar.gz   
# tar -zxvf DBD-mysql-3.0008.tar.gz -C ../software/   
# cd ../software/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/mysql --mysql_config=/usr/local/mysql/bin/mysql_config -testhost=127.0.0.1 --testsocket=/tmp/mysql.sock --testdb=nagios --testuser=root --testpassword=password   
………………………………………………………输出省略………………………………………………   
I will use the following settings for compiling and testing:   
cflags (User's choice) = -I/usr/local/mysql/include/mysql   
embedded (mysql_config ) =   
libs (User's choice) = -L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr/lib -lz   
mysql_config (Users choice ) = /usr/local/mysql/bin/mysql_config   
nocatchstderr (default ) = 0   
nofoundrows (default ) = 0   
ssl (guessed ) = 0   
testdb (User's choice) = nagios   
testhost (User's choice) = 127.0.0.1   
testpassword (default ) = password   
testsocket (User's choice) = /tmp/mysql.sock   
testuser (User's choice) = root   
To change these settings, see 'perl Makefile.PL --help' and   
'perldoc INSTALL'.   
Using DBI 1.605 (for perl 5.008008 on i386-linux-thread-multi) installed in /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/DBI/   
Writing Makefile for DBD::mysql   
# make && make install   
3:创建mysql头文件和库文件的链接到/usr相关目录下   
# cd   
# ln -s /usr/local/mysql/include/* /usr/include/   
# ln -s /usr/local/mysql/lib/* /usr/lib/   
4:安装ndoutils   
# cd /usr/local/src/tarbag/   
# wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz/download   
--00:56:40-- http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz/download   
# tar -zxvf ndoutils-1.4b7.tar.gz -C ../software/   
# cd ../software/ndoutils-1.4b7/   
# ./configure --prefix=/usr/local/nagios --enable-mysql   
………………………………………………………输出省略………………………………………………   
MySQL library and include file(s) were found!   
configure: creating ./config.status   
config.status: creating Makefile   
config.status: creating src/Makefile   
config.status: creating subst   
config.status: creating include/config.h   
*** Configuration summary for ndoutils 1.4b7 10-31-2007 ***:   
General Options:   
-------------------------   
NDO2DB user: nagios   
NDO2DB group: nagios   
Review the options above for accuracy. If they look okay,   
type 'make' to compile the NDO utilities.   
# make   
# cd src/   
# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/   
# cd ../db   
# mysql   
Welcome to the MySQL monitor. Commands end with ; or /g.   
Your MySQL connection id is 6   
Server version: 5.1.36-log Source distribution   
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.   
mysql> create database nagios;   
Query OK, 1 row affected (0.06 sec)   
# ./installdb -u root -p password -d nagios   
install_driver(mysql) failed: Can't load '/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.16: cannot open shared object file   
出现上面的错误,是因为找不到libmysqlclient.so.16这个库文件,解决办法如下:   
# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib   
# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib64/ (针对服务器64位系统)   
# ./installdb -u root -p 123456 -d nagios   
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.   
** Creating tables for version 1.4b7   
Using mysql.sql for installation...   
** Updating table nagios_dbversion   
Done!   
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51(这个错误可以忽略…)   
若出现错误提示“failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at ./installdb line 41“,原因是找不到mysql.sock,编译安装的msyql一般sock的位置是在/tmp下,解决办法有两个,一是修改/etc/my.cnf文件中sock的位置,二是创建一个软链接到/var/lib/mysql下面   
# cd ../config   
# cp ndo* /usr/local/nagios/etc/   
修改/usr/local/nagios/etc/ndo2db.cfg文件的数据库信息   
# grep -v '^#' /usr/local/nagios/etc/ndo2db.cfg |sort |uniq   
db_host=localhost   
db_name=nagios   
db_pass=password   
db_port=3306   
db_prefix=nagios_   
db_servertype=mysql   
db_user=root   
debug_file=@localstatedir@/ndo2db.debug   
debug_level=0   
debug_verbosity=1   
max_debug_file_size=1000000   
max_eventhandlers_age=44640   
max_hostchecks_age=10080   
max_servicechecks_age=10080   
max_systemcommands_age=10080   
max_timedevents_age=1440   
ndo2db_group=nagios   
ndo2db_user=nagios   
socket_name=/usr/local/nagios/var/ndo.sock   
socket_type=unix   
tcp_port=5668   
修改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(一般默认如此)。   
# grep 'broker' /usr/local/nagios/etc/nagios.cfg |grep -v '^#'   
event_broker_options=-1   
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg   
# 启动ndo2db   
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg   
若出现提示信息“Support for the specified database server is either not yet supported, or was not found on your system“ 应该是没找到mysql.h等头文件导致的,请确保所必须的库已安装,并在./configure时指定头文件目录!
  解决方法:确保vim /etc/ld.so.conf文件内容
  include ld.so.conf.d/*.conf
  /usr/local/mysql/lib/mysql
  /usr/local/mysql/include/mysql
  问题描述:Could not bind socket:Address already in use
  解决方法:rm /usr/local/nagios/var/ndo.sock   
重启nagios服务   
# service nagios restart   
Running configuration check...done.   
Stopping nagios: .done.   
Starting nagios: done.   
查看日志   
# tail -f /usr/local/nagios/var/nagios.log   
Caught SIGTERM, shutting down...   
Successfully shutdown... (PID=17653)   
Nagios 3.2.0 starting... (PID=19072)   
Local time is Wed Jan 27 02:01:31 EST 2010   
LOG VERSION: 2.0   
ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)   
ndomod: Successfully connected to data sink. 0 queued items to flush.   
Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.   
Finished daemonizing... (New PID=19075)
页: [1]
查看完整版本: 使用NDOUtils将Nagios监控信息存入mysql