AIOps 一场颠覆传统运维的盛筵
853
2023-03-15
Cacti+Nagios(四):Cacti整合Nagios
一、原理
整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。
二、安装cacti扩展模块
cacti扩展模块需要下载安装cacti-plugin,cacti-0.8.8a及以后版本已集成此扩展模块不需要再单独安装,如果使用的是老版本cacti,扩展模块安装如下:
从web进入cacti,启用cacti plugin扩展
三、安装Ndoutils插件
1、安装Ndoutils
2、准备配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@nagios ndoutils-2.0.0]# cd db [root@nagios db]# ./installdb -u cactier -p 123456 -h localhost -d cactidb [root@nagios ndoutils-2.0.0]# cd .. [root@nagios ndoutils-2.0.0]# cp src/{ndomod-4x.o,ndo2db-4x,log2ndo,file2sock} /usr/local/nagios/bin #nagios是4.x版本的就使用ndomod-4x.o和ndo2db-4x,如果是3.x版本就复制对应的3x文件 [root@nagios ndoutils-2.0.0]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg [root@nagios ndoutils-2.0.0]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg [root@nagios ndoutils-2.0.0]# cd /usr/local/nagios/etc/ [root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg [root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg [root@nagios etc]# cd /usr/local/nagios/bin [root@nagios bin]# mv ndo2db-4x ndo2db [root@nagios bin]# mv ndomod-4x.o ndomod.o [root@nagios bin]# chown nagios:nagios * |
1234567891011121314[root@nagios ndoutils-2.0.0]# cd db[root@nagios db]# ./installdb -u cactier -p 123456 -h localhost -d cactidb[root@nagios ndoutils-2.0.0]# cd ..[root@nagios ndoutils-2.0.0]# cp src/{ndomod-4x.o,ndo2db-4x,log2ndo,file2sock} /usr/local/nagios/bin#nagios是4.x版本的就使用ndomod-4x.o和ndo2db-4x,如果是3.x版本就复制对应的3x文件[root@nagios ndoutils-2.0.0]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg[root@nagios ndoutils-2.0.0]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg[root@nagios ndoutils-2.0.0]# cd /usr/local/nagios/etc/[root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg[root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg[root@nagios etc]# cd /usr/local/nagios/bin[root@nagios bin]# mv ndo2db-4x ndo2db[root@nagios bin]# mv ndomod-4x.o ndomod.o[root@nagios bin]# chown nagios:nagios *
3、修改配置文件
1 2 3 4 | [root@nagios bin]# vi /usr/local/nagios/etc/nagios.cfg #注意,broker_module和config_file放在一行 broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfgevent_broker_options=-1 process_performance_data=1 |
1234[root@nagios bin]# vi /usr/local/nagios/etc/nagios.cfg#注意,broker_module和config_file放在一行broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfgevent_broker_options=-1process_performance_data=1
1 2 3 4 5 6 7 8 9 | [root@nagios bin]# vi /usr/local/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 |
123456789[root@nagios bin]# vi /usr/local/nagios/etc/ndo2db.cfgsocket_type=tcpdb_servertype=mysqldb_host=localhostdb_port=3306db_name=cactidbdb_prefix=npc_db_user=cactierdb_pass=123456
1 2 3 | [root@nagios bin]# vi /usr/local/nagios/etc/ndomod.cfg output_type=tcpsocket output=127.0.0.1 |
123[root@nagios bin]# vi /usr/local/nagios/etc/ndomod.cfgoutput_type=tcpsocketoutput=127.0.0.1
4、启动守护进程
1 2 3 4 5 6 7 | [root@nagios bin]# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg [root@nagios bin]# cd /home/nagios/ndoutils-2.0.0 [root@nagios ndoutils-2.0.0]# cp ./daemon-init /etc/init.d/ndo2db [root@nagios ndoutils-2.0.0]# chmod +x /etc/init.d/ndo2db [root@nagios ndoutils-2.0.0]# service ndo2db status [root@nagios ndoutils-2.0.0]# chkconfig --add ndo2db [root@nagios ndoutils-2.0.0]# chkconfig ndo2db on |
1234567[root@nagios bin]# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg[root@nagios bin]# cd /home/nagios/ndoutils-2.0.0[root@nagios ndoutils-2.0.0]# cp ./daemon-init /etc/init.d/ndo2db[root@nagios ndoutils-2.0.0]# chmod +x /etc/init.d/ndo2db[root@nagios ndoutils-2.0.0]# service ndo2db status[root@nagios ndoutils-2.0.0]# chkconfig --add ndo2db[root@nagios ndoutils-2.0.0]# chkconfig ndo2db on
四、安装NPC插件
介绍:全称Nagios Plugin for Cacti,将nagios的数据通过ndo2db导入到mysql数据库(前面设置的npc_开头的表),然后cacti读取数据库信息将nagios的结果通过NPC展示出来。
1、安装npc
2、页面设置npc
(1)user management-->admin-->勾上Plugin Management
(3)settings-->NPC-->照下图设置
3、安装json:支持npc
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。
注意:先执行第4步的php -m查看是否加载了json,有则跳过3、4步,
4、配置php以支持json
查看是否有json被加载:
1 | [root@nagios json-1.2.1]# php -m |
1[root@nagios json-1.2.1]# php -m
查看是否有导入信息:
1 | [root@nagios json-1.2.1]# php -i | grep php.ini |
1[root@nagios json-1.2.1]# php -i | grep php.ini
5、修改数据库(缺少个别字段)
6、重启服务
7、观察日志
五、遇到的问题
1、NPC页面上显示Nagios为Off
错误:
1 2 | [root@nagios ~]#tail /usr/local/nagios/var/nagios.log ndomod: Could not open data sink! I'll keep trying, but some output may get lost... |
12[root@nagios ~]#tail /usr/local/nagios/var/nagios.logndomod: Could not open data sink! I'll keep trying, but some output may get lost...
解决:
1 2 3 4 5 | [root@nagios ~]# cd /usr/local/nagios/etc/ [root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg [root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg [root@nagios etc]# service ndo2db restart [root@nagios etc]# service nagios restart |
12345[root@nagios ~]# cd /usr/local/nagios/etc/[root@nagios etc]# chown nagios:nagios ndo2db.cfg ndomod.cfg[root@nagios etc]# chmod 664 ndo2db.cfg ndomod.cfg[root@nagios etc]# service ndo2db restart[root@nagios etc]# service nagios restart
2、ndo2db服务启动失败
错误:
1 | Could not bind socket: Address already in use |
1Could not bind socket: Address already in use
解决:
1 2 3 | [root@nagios ~]# ps aux|grep ndo2db 看到多个ndo2db的进程 [root@nagios ~]# kill-9 进程id 杀掉进程,再重新运行 [root@nagios ~]# sudo /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg |
123[root@nagios ~]# ps aux|grep ndo2db 看到多个ndo2db的进程[root@nagios ~]# kill-9 进程id 杀掉进程,再重新运行[root@nagios ~]# sudo /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
3、消息发送失败
错误:
1 2 | [root@nagios ~]# tail /var/log/message ndo2db: Warning: queue send error, retrying... ndo2db: Message sent to queue. |
12[root@nagios ~]# tail /var/log/messagendo2db: Warning: queue send error, retrying... ndo2db: Message sent to queue.
解决:
1 2 3 4 | [root@nagios ~]# vi /etc/sysctl.conf kernel.msgmax = 131072000 kernel.msgmnb = 131072000 kernel.msgmni = 65536000 |
1234[root@nagios ~]# vi /etc/sysctl.confkernel.msgmax = 131072000kernel.msgmnb = 131072000kernel.msgmni = 65536000
发表评论
暂时没有评论,来抢沙发吧~