js333 > 计算机互联网 > 使用NDOUtils将Nagios监控信息存入MySQL,将Nagios监控

原标题:使用NDOUtils将Nagios监控信息存入MySQL,将Nagios监控

浏览次数:194 时间:2019-11-07

一、NDOUtils安装需求:

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

1.Nrpe安装

Nagios:安装方法:http://www.linuxidc.com/Linux/2014-01/94658.htm 

1.NDOUtils安装需求

创建 nagios用户

MySQL:源码安装方法:http://www.linuxidc.com/Linux/2014-04/100758.htm

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

useradd nagios

DBI和DBD-mysql安装方法如下:

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

1.1被监控服务器安装nagios插件

shell> perl -MCPAN -e shell 
cpan> install DBI 
cpan> install DBD::mysql
  1. ln -s /opt/mysql/include/* /usr/include/
  2. ln -s /opt/mysql/lib/* /usr/lib/

  3. echo '/usr/lib' >> /etc/ld.so.conf

  4. ldconfig -v

tar xzvfnagios-plugins-1.4.15.tar.gz

二、关联mysql头文件和库:

3.安装ndoutils

cd nagios-plugins-1.4.15

不做关联可能在config或make时出错

./configure

ln -s /app/mysql/include/* /usr/include/
ln -s /app/mysql/lib/* /usr/lib/

echo '/usr/lib' >> /etc/ld.so.conf
ldconfig -v
  1. wget -c
  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

make

三、安装nodutils:

config时使用以下mysql参数*

make install

tar zxvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql LDFLAGS=-L/app/mysql/lib --with-mysql-inc=/app/mysql/include/mysql --with-mysql-lib=/app/mysql/lib/mysql
make
  1. --with-mysql-inc=/opt/mysql/include --with-mysql-lib=/opt/mysql/lib
  2. #config成功
  3. #make出错

1.2被监控服务器安装nrpe程序

四、拷贝文件:

config时使用以下mysql参数*

tar xzvf  nrpe-2.1.2.tar.gz

cp ./src/ndomod-3x.o /usr/local/nagios/bin
cp ./src/ndo2db-3x /usr/local/nagios/bin
cp ./src/log2ndo /usr/local/nagios/bin
cp ./src/file2sock /usr/local/nagios/bin
chown nagios:nagios /usr/local/nagios/bin/*
  1. --with-mysql-inc=/opt/mysql/include/mysql --with-mysql-lib=/opt/mysql/lib/mysql
  2. #config出错
  3. #make成功并生成文件
  4. #启动ndo2db会出错

cd nrpe-2.1.2

五、拷贝配置文件:

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

./configure --prefix=/usr/local/nagios

cp ./config/ndo* /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/*
  1. <del datetime="2009-05-27T06:58:24+00:00">LDFLAGS=-L/opt/mysql/lib </del>
  2. #ndo2db不能导入到数据库

make all

六、创建ndo的mysql数据库及用户

相关错误

make install-plugin

CREATE DATABASE `nagios` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT select,insert,update,delete ON nagios.* TO nagios@localhost identified by 'nagios';
FLUSH PRIVILEGES ;
  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.

  13. make

  14. ll ./src

make install-daemon

七、导入数据库结构

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

make install-daemon-config

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

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

检查插件安装

如果这里root没有密码的话需要进行修改。
八、修改配置文件

  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/*

ll /usr/local/nagios/libexec/

 

5.拷贝配置文件

1.3修改nrpe配置文件,加入允许的IP

vim /usr/local/nagios/etc/ndo2db.cfg

db_user=nagios
db_pass=nagios
socket_type=tcp

vim /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

vim /usr/local/nagios/etc/ndomod.cfg
output_type=file
output=/usr/local/nagios/var/ndo.dat
  1. cp ./config/ndo* /usr/local/nagios/etc/
  2. chown nagios:nagios /usr/local/nagios/etc/*

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

 

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

allowed_hosts=127.0.0.1,192.169.0.201

九、启动ndo2db

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

启动nrpe

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

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

#/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg –d

十、重启nagios

cpan DBI
cpan DBD::mysql

# netstat -plnt |grep nrpe

 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
service nagios restart
  1. cd ./db/
  2. ./installdb -u root -p 123456 -h localhost -d nagios

tcp        0    0 0.0.0.0:5666              0.0.0.0:*                  LISTEN      16831/nrpe

十一、检查安装是否正确

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

1.4加入开机自启动

tail -f /usr/local/nagios/var/nagios.log

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

echo'/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d'>>/etc/rc.local

涉及的错误:

输入密码

1.5在主Nagios上验证客户端nrpe是否安装好

启动ndo后在日志中出现:nagios ndo2db-3x: Error: mysql_query() failed for 'INSERT INTO nagios_configfilevariables SET instance_id='1', configfile_id='3', varname='cfg_file', varvalue='/usr/local/nagios//etc/objects/localhost.cfg 解决办法是使用:mysql -uroot --password="canada" -h192.168.1.97 -e "alter table nagios.nagios_configfilevariables drop key instance_id;alter table nagios.nagios_configfilevariables add index (instance_id, configfile_id, varname); 需要修改表结构。 alter table nagios.nagios_configfilevariables drop key instance_id; alter table nagios.nagios_configfilevariables add index (instance_id, configfile_id, varname);

成功导入59张表

[root@nagios-server src]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.100

tcp连接Mysql /usr/local/nagios/bin/file2sock -s /usr/local/nagios/var/ndo.dat -d localhost -t tcp -p 5668

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

NRPE v2.12

相关阅读

  1. db_user=nagiosndo
  2. db_pass=password123

若出现版本号,代表nrpe客户端安装成功。

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

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

2主Nagios调用nrpe配置

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

  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

2.1编辑客户端上的nrpe配置文件

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

9.启动ndo2db

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

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

  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. #开机启动

  6. Support for the specified database server is either not yet supported, or was not found on your system.

  7. /usr/local/nagios/bin/ndo2db-3x: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10

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

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

command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20

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

10.重启动nagios

2.2在主Nagios上定义客户端主机

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

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

#vi /usr/local/nagios/etc/objects/hosts.cfg

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-04/100759.htm

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

define host{

金沙js333娱乐场 1

11.检查安装是否正确

        use                    linux-server,host-pnp     

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

        host_name              hostb

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

        alias                    hostb

貌似有点问题

        address                192.168.1.100

先改成输出成文件
#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

  7. service nagios restart

 

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

2.3在主Nagios上配置服务

  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. 金沙js333娱乐场,999
  25.  
  26.  
  27.  
  28. 201:
  29. 1=205
  30. 2=0

#vi /usr/local/nagios/etc/objects/services.cfg

使用file2sock尝试socket方式

define service{

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

        use                      generic-service,srv-pnp

Error while writing to destination socket: Connection reset by peer

        host_name                hostb

尝试tcp方式
vi ndo2db.cfg

        service_description        check_users

  1. #socket_type=unix
  2. socket_type=tcp

        check_command          check_nrpe!check_users

��新载入ndo2db

        max_check_attempts 5

  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

        normal_check_interval 1

Error while writing to destination socket: Connection reset by peer

}

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

define service{

  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. #再执行一下安装过程后,通过

        use                      generic-service,srv-pnp

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

        host_name                hostb

tail /var/log/messages

        service_description        check_load

  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.

        check_command          check_nrpe!check_load

连接不到mysql,重启一下

        max_check_attempts 5

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

        normal_check_interval 1

  1. Could not bind socket: Address already in use

}

ps aux|grep ndo2db
没有

2.4重启主Nagios服务

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

#/etc/init.d/nagios checkconfig

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

#/etc/init.d/nagios restart

tail /var/log/messages

2.5 Nagios界面临控效果图

  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

金沙js333娱乐场 2

解决

 

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

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

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

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

Nginx环境下构建Nagios监控平台 http://www.linuxidc.com/Linux/2011-07/38112.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

在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

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

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

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

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

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-02/113491.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/102151.htm

金沙js333娱乐场 3

金沙js333娱乐场 4

本文由js333发布于计算机互联网,转载请注明出处:使用NDOUtils将Nagios监控信息存入MySQL,将Nagios监控

关键词:

上一篇:游戏之路

下一篇:邮件发送已经说烂了的功能,Core中MailKit无法使用