阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

238次阅读
没有评论

共计 5775 个字符,预计需要花费 15 分钟才能阅读完成。

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

1.NDOUtils 安装需求

nagios
mysql
cpan DBI #非必需
cpan DBD::mysql #非必需

2. 关联 mysql 头文件和库
不做关联可能在 config 或 make 时出错

  1. ln -s /opt/mysql/include/* /usr/include/
  2. ln -s /opt/mysql/lib/* /usr/lib/
  1. echo ‘/usr/lib’ >> /etc/ld.so.conf
  2. ldconfig -v

3. 安装 ndoutils

http://sourceforge.net/project/showfiles.php?group_id=26589

  1. wget -c http://nchc.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b7.tar.gz
  2. tar zxvf ndoutils-1.4b7.tar.gz
  3. cd ndoutils-1.4b7
  4. ./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql

*config 时使用以下 mysql 参数

  1. –with-mysql-inc=/opt/mysql/include –with-mysql-lib=/opt/mysql/lib
  2. #config 成功
  3. #make 出错

*config 时使用以下 mysql 参数

  1. –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql
  2. #config 出错
  3. #make 成功并生成文件
  4. # 启动 ndo2db 会出错

* 没有 LDFLAGS=-L/opt/mysql/lib

  1. <del datetime=”2009-05-27T06:58:24+00:00″>LDFLAGS=-L/opt/mysql/lib </del>
  2. #ndo2db 不能导入到数据库

相关错误

  1. In file included from io.c:10:
  2. ../include/config.h:261:25: mysql/mysql.h: 没有那个文件或目录
  3. ../include/config.h:262:26: mysql/errmsg.h: 没有那个文件或目录
  4. make[1]: *** [io.o] 错误 1
  5. checking for mysql/mysql.h… no
  6.  
  7. *** MySQL include file could not be located… **********************
  8.  
  9. You chose to compile NDBXT with MySQL support, but I was unable to
  10. locate on your system. If the include file is
  11. installed, use the –with-mysql-inc argument to specify the location
  12. of the MySQL include file.
  1. make
  2. ll ./src

看看是否有以下文件
ndo2db-2x
ndo2db-3x
ndomod-2x.o
ndomod-3x.o

4. 拷贝文件
# 我的 Nagios 是 3.0.6,所以拷贝的是 ndomod-3x.o、ndo2db-3x,如果你的是 2.X.x 请拷贝 ndomod-2x.o、ndo2db-2x

  1. cp ./src/ndomod-3x.o /usr/local/nagios/bin
  2. cp ./src/ndo2db-3x /usr/local/nagios/bin
  3. cp ./src/log2ndo /usr/local/nagios/bin
  4. cp ./src/file2sock /usr/local/nagios/bin
  5. chown nagios:nagios /usr/local/nagios/bin/*

5. 拷贝配置文件

  1. cp ./config/ndo* /usr/local/nagios/etc/
  2. chown nagios:nagios /usr/local/nagios/etc/*

6. 创建 ndo 的 mysql 数据库及用户

  1. CREATEDATABASE`nagios`DEFAULTCHARACTERSETutf8COLLATEutf8_general_ci;
  2. GRANT select,insert,update,deleteONnagios.* TOnagiosndo@localhostidentifiedbypassword123;
  3. FLUSH PRIVILEGES ;

7. 导入数据库结构
使用 db/installdb 脚本
需要以下支持

cpan DBI
cpan DBD::mysql

  1. cd ./db/
  2. ./installdb -u root -p 123456 -h localhost -d nagios

用命令导入(其实和用脚本是一回事, 也可以用 phpmyadmin 来导入)

  1. /opt/mysql/bin/mysql -u root -p -D nagios -h localhost < ./db/mysql.sql

输入密码

成功导入 59 张表

8. 修改配置文件
vi /usr/local/nagios/etc/ndo2db.cfg

  1. db_user=nagiosndo
  2. db_pass=password123

vi /usr/local/nagios/etc/nagios.cfg

  1. # 修改下面参数的值为 -1(一般默认如此)。
  2. event_broker_options=-1
  3. # 复制下面内容粘贴到 #broker_module=… 下面。
  4. # 注意 broker_module= 和 config_file 是在一行上
  5. # Uncomment the line below if you’re running Nagios 3.x
  6. broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

9. 启动 ndo2db

  1. /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
  2.  
  3. echo ‘rm -f /usr/local/nagios/var/ndo.sock’ >> /etc/rc.local
  4. echo ‘/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg’ >> /etc/rc.local
  5. # 开机启动
  1. Support for the specified database server is either not yet supported, or was not found on your system.
  1. /usr/local/nagios/bin/ndo2db-3x: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

出现以上错误请执行第 2 步

10. 重启动 nagios

  1. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  2. service nagios restart

一般情况下到此已完成安装,可以去数据库里看下记录有无增加

11. 检查安装是否正确

  1. tail -20 /usr/local/nagios/var/nagios.log

[1242971625] ndomod: Successfully flushed 80 queued items to data sink.
[1242971625] ndomod: Error writing to data sink! Some output may get lost…

貌似有点问题

先改成输出成文件
#vi ndomod.cfg

  1. instance_name=default
  2. #output_type=tcpsocket
  3. #output=127.0.0.1
  4.  
  5. output_type=file
  6. output=/usr/local/nagios/var/ndo.dat
  1. service nagios restart

看看有没有 /usr/local/nagios/var/ndo.dat 文件,ok,发现文件,说明第一步可以生成文件
查看文件内容

  1. cd /usr/local/nagios/var/
  2. head -30 ndo.dat
  3.  
  4. HELLO
  5. PROTOCOL: 2
  6. AGENT: NDOMOD
  7. AGENTVERSION: 1.4b7
  8. STARTTIME: 1243393299
  9. DISPOSITION: REALTIME
  10. CONNECTION: FILE
  11. CONNECTTYPE: INITIAL
  12. INSTANCENAME: default
  13. STARTDATADUMP
  14.  
  15.  
  16. 202:
  17. 1=300
  18. 2=0
  19. 3=0
  20. 4=1243393292.450675
  21. 73=1243393292
  22. 74=262144
  23. 72=ndomod: Error writing to data sink!  Some output may get lost…
  24. 999
  25.  
  26.  
  27.  
  28. 201:
  29. 1=205
  30. 2=0

使用 file2sock 尝试 socket 方式

  1. ../bin/file2sock -s /usr/local/nagios/var/ndo.dat -d /usr/local/nagios/var/ndo.sock -t unix -p 5668

Error while writing to destination socket: Connection reset by peer

尝试 tcp 方式
vi ndo2db.cfg

  1. #socket_type=unix
  2. socket_type=tcp

重新载入 ndo2db

  1. ps aux|grep ndo2db
  2. kill $pid
  3. /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
  4.  
  5. ../bin/file2sock -s ndo.dat -d localhost -t tcp -p 5668

Error while writing to destination socket: Connection reset by peer

依然不行,重新编译 ndoutils 并加上 LDFLAGS=-L/opt/mysql/lib

  1. ./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql
  2. make
  3. # 再执行一下安装过程后,通过

=================
200912-07 更新

tail /var/log/messages

  1. Dec  7 14:09:13 localhost nagios: ndomod: Still unable to connect to data sink.  10547 items lost, 5000 queued items to flush.
  2. Dec  7 14:09:29 localhost nagios: ndomod: Still unable to connect to data sink.  10746 items lost, 5000 queued items to flush.

连接不到 mysql, 重启一下

/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

  1. Could not bind socket: Address already in use

ps aux|grep ndo2db
没有

查看套接字文件是否存在, 删除之
ll /usr/local/nagios/var/ndo.sock
rm /usr/local/nagios/var/ndo.sock

重启
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

tail /var/log/messages

  1. Dec  7 14:09:45 localhost nagios: ndomod: Successfully connected to data sink.  10861 items lost, 5000 queued items to flush.
  2. Dec  7 14:09:45 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.
  3. Dec  7 14:09:45 localhost ndo2db-3x: Successfully connected to MySQL database

解决

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计5775字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中