设为首页 收藏本站
查看: 2698|回复: 0

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

[复制链接]

尚未签到

发表于 2015-11-23 09:36:55 | 显示全部楼层 |阅读模式
  环境介绍:   
系统:红帽企业版5.4   
Nagios正确安装运行,版本3.0.6 安装目录:/usr/local/nagios   
MySQL正确安装并运行,安装目录:/usr/local/mysql   
1:安装DBI包   
[iyunv@server2 ~]# cd /usr/local/src/tarbag/   
[iyunv@server2 tarbag]# wget http://www.cpan.org/modules/by-module/DBI/DBI-1.605.tar.gz   
[iyunv@server2 tarbag]# tar zxvf DBI-1.605.tar.gz -C ../software/   
[iyunv@server2 tarbag]# cd ../software/DBI-1.605/   
[iyunv@server2 DBI-1.605]# perl Makefile.PL   
[iyunv@server2 DBI-1.605]# make && make install   
2:安装DBD-mysql   
[iyunv@server2 DBI-1.605]# cd -   
/usr/local/src/tarbag   
[iyunv@server2 tarbag]# wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-3.0008.tar.gz   
[iyunv@server2 tarbag]# tar -zxvf DBD-mysql-3.0008.tar.gz -C ../software/   
[iyunv@server2 tarbag]# cd ../software/DBD-mysql-3.0008/   
[iyunv@server2 DBD-mysql-3.0008]# unset LANG   
[iyunv@server2 DBD-mysql-3.0008]# 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   
[iyunv@server2 DBD-mysql-3.0008]# make && make install   
3:创建mysql头文件和库文件的链接到/usr相关目录下   
[iyunv@server2 DBD-mysql-3.0008]# cd   
[iyunv@server2 ~]# ln -s /usr/local/mysql/include/* /usr/include/   
[iyunv@server2 ~]# ln -s /usr/local/mysql/lib/* /usr/lib/   
4:安装ndoutils   
[iyunv@server2 ~]# cd /usr/local/src/tarbag/   
[iyunv@server2 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   
[iyunv@server2 tarbag]# tar -zxvf ndoutils-1.4b7.tar.gz -C ../software/   
[iyunv@server2 tarbag]# cd ../software/ndoutils-1.4b7/   
[iyunv@server2 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.   
[iyunv@server2 ndoutils-1.4b7]# make   
[iyunv@server2 ndoutils-1.4b7]# cd src/   
[iyunv@server2 src]# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/   
[iyunv@server2 src]# cd ../db   
[iyunv@server2 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)   
[iyunv@server2 db]# ./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这个库文件,解决办法如下:   
[iyunv@server2 db]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib   
[iyunv@server2 db]# ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib64/ (针对服务器64位系统)   
[iyunv@server2 db]# ./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下面   
[iyunv@server2 db]# cd ../config   
[iyunv@server2 config]# cp ndo* /usr/local/nagios/etc/   
修改/usr/local/nagios/etc/ndo2db.cfg文件的数据库信息   
[iyunv@server2 ~]# 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(一般默认如此)。   
[iyunv@server2 ~]# 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服务   
[iyunv@server2 ~]# service nagios restart   
Running configuration check...done.   
Stopping nagios: .done.   
Starting nagios: done.   
查看日志   
[iyunv@server2 ~]# tail -f /usr/local/nagios/var/nagios.log     
[1264575689] Caught SIGTERM, shutting down...   
[1264575689] Successfully shutdown... (PID=17653)   
[1264575691] Nagios 3.2.0 starting... (PID=19072)   
[1264575691] Local time is Wed Jan 27 02:01:31 EST 2010   
[1264575691] LOG VERSION: 2.0   
[1264575691] ndomod: NDOMOD 1.4b7 (10-31-2007) Copyright (c) 2005-2007 Ethan Galstad (nagios@nagios.org)   
[1264575691] ndomod: Successfully connected to data sink. 0 queued items to flush.   
[1264575691] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.   
[1264575691] Finished daemonizing... (New PID=19075)
DSC0000.gif

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-142442-1-1.html 上篇帖子: Nagios3.0 NRPE 安装 监控远程Linux服务 下篇帖子: Nagios监控window主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表