1. 云栖社区>
  2. PHP教程>
  3. 正文

cacti+nagios 之cacti整合nagios(四)

作者:用户 来源:互联网 时间:2017-12-01 16:07:04

整合cactinagios

cacti+nagios 之cacti整合nagios(四) - 摘要: 本文讲的是cacti+nagios 之cacti整合nagios(四), 一、原理 整合cacti和nagios是利用了cacti的一个插件nagios for cacti;它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti)的库中;然后cacti读取数据库信息将nagios展现出

一、原理


整合cacti和nagios是利用了cacti的一个插件nagios for cacti;它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti)的库中;然后cacti读取数据库信息将nagios展现出来;


一、安装cacti扩展模块


Cacti扩展模块需要下载安装cacti-plugin,cacti-0.8.8a及以后版本已经集成不需要安装(但是我使用的0.8.8b还需要安装很郁闷,如果使用的是老版本cacti,扩展模块安装如下:


Cd /root/cactinagios


Wget http://www.cacti.net/downloads/pia/cacti-plugins-0.8.7h-PA-v3.0.tar.gz


Mv cacti-plugin-0.8.7h-PA-v3.0.tar.gz cacti-plugin-arch.tar.gz


Tar -xf cacti-plugin-arch.tar.gz


Cp cacti-plugin-arch/* /var/www/html/cacti/


Cd /var/www/html/cacti/


Mysql -u cacti –p ‘cacti’ cacti


Patch -p1 –N然后登陆cacti;点击consoleàuser ManagementàadminàPlugin Mangement打开将其勾选上;然后点击保存即可;


安装Ndoutils cd/root/cactinagios wgethttp://jaist.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz tarzxvfndoutils-2.0.0.tar.gz cdndoutils-2.0.0 ./configure–prefix=/var/www/html/nagios/–with-mysql-inc=/usr/include/mysql–with-mysql-lib=/usr/lib64/mysql–enable-mysql–disable-pgsql–with-ndo2db-user=nagios–with-ndo2db-group=nagios make2、准备配置文件 cddb ./installdb-ucactier-p123456-hlocalhost-dcactidb cd.. [[email protected]]#cpsrc/{ndomod-4x.o,ndo2db-4x,log2ndo,file2sock}/usr/local/nagios/bin #nagios是4.x版本的就使用ndomod-4x.o和ndo2db-4x,如果是3.x版本就复制对应的3x文件 [[email protected]]#cpconfig/ndomod.cfg-sample/var/www/html/nagios/etc/ndomod.cfg [[email protected]]#cpconfig/ndo2db.cfg-sample/var/www/html/nagios/etc/ndo2db.cfg [[email protected]]#cd/var/www/html/nagios/etc/ [[email protected]]#chownnagios:nagiosndo2db.cfgndomod.cfg [[email protected]]#chmod664ndo2db.cfgndomod.cfg [[email protected]]#cd/var/www/html/nagios/bin [[email protected]]#mvndo2db-4xndo2db [[email protected]]#mvndomod-4x.ondomod.o [[email protected]]#chownnagios:nagios*3、修改配置文件 [[email protected]]#vi/usr/local/nagios/etc/nagios.cfg #注意,broker_module和config_file放在一行broker_module=/var/www/html/nagios/bin/ndomod.oconfig_file=/var/www/html/nagios/etc/ndomod.cfgevent_broker_options=-1 process_performance_data=1 [[email protected]]#vi/var/www/html/nagios/etc/ndo2db.cfg socket_type=tcp db_servertype=mysql db_host=localhost db_port=3306 db_name=cactidb db_prefix=npc_ db_user=cactier db_pass=123456 [[email protected]]#vi/var/www/html/nagios/etc/ndomod.cfg output_type=tcpsocketoutput=127.0.0.1 4、启动守护进程 [[email protected]]#/var/www/html/nagios/bin/ndo2db-c/var/www/html/etc/ndo2db.cfg [[email protected]]#cd/root/cactinagios/ndoutils-2.0.0 [[email protected]]#cp./daemon-init/etc/init.d/ndo2db [[email protected]]#chmod+x/etc/init.d/ndo2db [[email protected]]#servicendo2dbstatus [[email protected]]#chkconfig–addndo2db [[email protected]]#chkconfigndo2dbon


四、安装NPC插件


介绍:全称Nagios Plugin for Cacti,将nagios的数据通过ndo2db导入到mysql数据库(前面设置的npc_开头的表),然后cacti读取数据库信息将nagios的结果通过NPC展示出来。1、安装npc [[email protected]]#cd/root/cactinagios [[email protected]]#wgethttp://down.drv5.cn/www.drv5.cn/npc-2.0.4.tar.gz [[email protected]]#tarzxvfnpc-2.0.4.tar.gz [[email protected]]#mvnpc/var/www/html/cacti/plugins/ [[email protected]]#vi/var/www/html/cacti/include/config.php $plugins[]=‘npc’; 2、页面设置npc (1)user management–>admin–>勾上Plugin Management (2)Plugin Management–>点击install图标、点击enable图标 (3)settings–>NPC–>如下所示: Remote Commands: /var/www/html/nagios/var/rw/nagios.cmd http://192.168.10.16/nagios


3、安装json:支持npc JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。 注意:先执行第4步的php -m查看是否加载了json,有则跳过3、4步我这里有;


查看是否有json被加载: [[email protected]]#php-m 修改数据库:


[[email protected]]#mysql-ucacti-pcacti mysql>usecacti; mysql>ALTERTABLEnpc_eventhandlersADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_hostchecksADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_hoststatusADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_notificationsADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_servicechecksADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_servicestatusADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_statehistoryADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_systemcommandsADDlong_outputTEXTNOTNULLDEFAULT”AFTERoutput; mysql>ALTERTABLEnpc_servicesADDimportancesmallint(6)NOTNULLDEFAULT’0′; mysql>ALTERTABLEnpc_hostsADDimportancesmallint(6)NOTNULLDEFAULT’0′; mysql>ALTERTABLEnpc_contactsADDminimum_importancesmallint(6)NOTNULLDEFAULT’0′; mysql>quit 6、重启服务 [[email protected]~]#servicemysqldrestart [[email protected]~]#servicehttpdrestart [[email protected]~]#servicendo2dbrestart [[email protected]~]#servicenagiosrestart 7、观察日志 [[email protected]~]#tail/var/log/html/nagios/var/nagios.log [[email protected]~]#tail/var/www/html/cacti/log/cacti.log [[email protected]~]#tail/var/log/mysqld.log [[email protected]~]#tail/var/log/messages



以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索整合 , cacti nagios ,以便于您获取更多的相关知识。