资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

将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
标题URL:http://www.cdkjz.cn/article/ghpihj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220