重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

将Nagios监控信息存入MySQL

一、NDOUtils安装需求:
Nagios:安装方法:http://www.linuxidc.com/Linux/2014-01/94658.htm 
MySQL:源码安装方法:http://www.linuxidc.com/Linux/2014-04/100758.htm

DBI和DBD-mysql安装方法如下:
shell> perl -MCPAN -e shell 
cpan> install DBI 
cpan> install DBD::mysql

二、关联mysql头文件和库:
不做关联可能在config或make时出错
ln -s /app/mysql/include/* /usr/include/
ln -s /app/mysql/lib/* /usr/lib/
echo '/usr/lib' >> /etc/ld.so.conf
ldconfig -v

三、安装nodutils:
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 && make install

四、拷贝文件:
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/*

五、拷贝配置文件:
cp ./config/ndo* /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/*

六、创建ndo的mysql数据库及用户
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 ;

七、导入数据库结构
cd ./db/
./installdb -u root -p 123456 -h localhost -d nagios
如果这里root没有密码的话需要进行修改。

八、修改配置文件
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
 
九、启动ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

十、重启nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
service nagios restart

十一、检查安装是否正确
tail -f /usr/local/nagios/var/nagios.log

涉及的错误:
启动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" -h292.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);

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

名称栏目:将Nagios监控信息存入MySQL
本文地址:http://cqcxhl.com/article/ghpihj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP