Cacti与nagios结合所需插件的安装与报错处理
Cacti和Nagios安装这里就不做介绍了
鄂托克ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
我们这里介绍的是nagios与cacti的整合,首先需要安装php json模块和ndoutils,其中Ndoutils是nagios的一个插件,就是可以用来把nagios的获取的数据存入到MySQL数据库中。也可以实现与cacti的插件npc的集成,这个工具的安装是个关键。还需要安装使用npc插件。下面我们来一一介绍安装的方法。
一、安装Php-json
tar xzf json-1.2.1 ;
cd json-1.2.1 ;
/usr/bin/phpize ;
./configure ;
make ;
make install
安装完后,然后执行如下语句添加json模块:
echo "extension=json.so" >/etc/php.d/json.ini
使用php -m|grep json应该可以显示json这个字符
如果没显示这个字符,证明模块没有安装正确
解决方法:yum remove php-common,然后重新安装php-common
二、安装Ndoutils
Ndoutils安装
1.DBI的安装
到官网http://www.cpan.org/modules/by-module/DBI/ 下载
这里下载的是DBI-1.633.tar.gz
tar -zxvf DBI-1.633.tar.gz
cd DBI-1.633
perl Makefile.PL
make
make test
这里出现test错误,不用管他,继续安装。
make install
2. DBD的安装
DBD-mysql-4.025
tar -zxvf DBD-mysql-4.025.tar.gz
cdDBD-mysql-4.025
perl Makefile.PL --libs="-L/usr/lib64/mysql #mysql使用yum装的,检查配置时系统一般能找到头文件和库文件的位置,不用过多配置一些选项
make
make test
make install
3.NDOUTILS安装
编译安装NDOUtils
tar -zxvf ndoutils-2.0.0
cd ndoutils-2.0.0
./configure --prefix=/usr/local/nagios --enable-mysql
make
4.拷贝文件
我的Nagios是3.5.1,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x请拷贝ndomod-2x.o、ndo2db-2x
cd ndoutils-2.0.0
cd src
cp ndo2db-3x ndomod-3x.o file2sock log2ndo /usr/local/nagios/bin
cd /usr/local/nagios/bin
mv ndo2db-3x ndo2db
cd config
cp ndo2db.cfg-sample ndomod.cfg-sample /usr/local/nagios/etc/
cd /usr/local/nagios/etc
mv ndo2db.cfg-sample ndo2db.cfg
mv ndomod.cfg-sample ndomod.cfg
5.编辑ndo2db.cfg配置文件
vim /usr/local/nagios/etc/ndo2db.cfg
lock_file=/usr/local/nagios/var/ndo2db.lock
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
use_ssl=0
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cacti#数据库名称
db_prefix=npc_
db_user=cactiuser#数据库使用者
db_pass=huaxia#数据库密码
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
max_externalcommands_age=44640
debug_level=0
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000
6.配置ndomod.cfg文件
vim /usr/local/nagios/etc/ndomod.cfg
instance_name=default
output_type=tcpsocket
output=127.0.0.1
tcp_port=5668
use_ssl=0
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=15
data_processing_options=-1
config_output_options=2
8.配置nagios.cfg文件
vi /usr/local/nagios/etc/nagios.cfg
#修改下面参数的值为-1(一般默认如此)。
event_broker_options=-1
#复制下面内容粘贴到#broker_module=...下面。
#注意broker_module=和config_file是在一行上
# Uncomment the line below if you're running Nagios 3.x
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
process_performance_data=1#注意该参数修改成启动状态
9.配置启动脚本
cd /usr/local/src/ndoutils-1.5.2
cp daemon-init /etc/init.d/ndo2db
chmod +x ndo2db
10、启动ndo2db服务
Service ndo2db start
11.重启nagios
service nagios restart
12.查看启动日志信息
[root@BestTone-zabbix var]# tail -f nagios.log
[1468292167] Successfully shutdown... (PID=29500)
[1468292167] ndomod: Shutdown complete.
[1468292167] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' deinitialized successfully.
[1468292167] Nagios 3.5.1 starting... (PID=14197)
[1468292167] Local time is Tue Jul 12 10:56:07 CST 2016
[1468292167] LOG VERSION: 2.0
[1468292167] ndomod: NDOMOD 1.5.2 (06-08-2012) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1468292167] ndomod: Could not open data sink! I'll keep trying, but some output may get lost...
[1468292167] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
[1468292167] Finished daemonizing... (New PID=14198)
[1468293079] ndomod: Still unable to connect to data sink. 721 items lost, 5000 queued items to flush.
查看到报错信息ndomod: Could not open data sink! I'll keep trying, but some output may get lost...
[1468293079] ndomod: Still unable to connect to data sink. 721 items lost, 5000 queued items to flush.
从报错的信息可以看到ndomod没有把数据存到cacti数据库里,错误解决方法:
vim /usr/local/nagios/etc/ndo2db.cfg
ndo2db_group=apache#修改数据库的属组为apache
cd /usr/local/nagios/bin
chown nagios:apache ndo*#把两个主程序的属组改为apache
cd ../etc
chown nagios:apache ndo*#把两个配置文件的属组改为apache
13、重启相关服务
service ndo2db restart
service nagios restart
14、再次查看启动日志,发现启动成功,ndomod已经连接上cacti数据库
[root@localhost ~]# tail -f /var/log/messages
Mar 24 09:31:25 localhost nagios: ndomod registered for retention data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact notification data'
Mar 24 09:31:25 localhost nagios: ndomod registered for acknowledgement data'
Mar 24 09:31:25 localhost nagios: ndomod registered for contact status data'
Mar 24 09:31:25 localhost nagios: ndomod registered for adaptive contact data'
Mar 24 09:31:25 localhost nagios: Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
Mar 24 09:31:25 localhost nagios: Finished daemonizing... (New PID=1828)
Mar 24 10:31:25 localhost nagios: Auto-save of retention data completed successfully.
Mar 24 10:47:35 localhost kernel: hrtimer: interrupt took 3738538 ns
三、安装npc软件
tar -vxzf npc-2.0.4.tar.gz ;
mv npc /var/www/html/cacti/plugins/
1、通过界面启动npc
2、在Cacti的"console"的"Settings"里设置好nagios命令文件的主路径和nagios的URL的路径,注意勾上"Romote Commands"项,点击"Save"按钮
3、再cacti数据库里,执行下面的sql语句
mysql里面执行如下sql即可:
mysql> use cacti;
alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
4、执行成功后,重启nagios和ndo2db,下面界面是nagios与cacti的整合效果图:
遇到的问题
1)、假如这里的Nagios的状态是off
我也曾遇到,主要是检查ndo2db连cacti库是否正常,可以查看/var/log/messages
里的日志信息,看不到信息可能是你的ndomod.cfg和ndo2db.cfg配置有错误!建议检查配置文件。同时在cacti数据库里执行上面提示的几条sql语句。
2)、假如nagios状态栏无信息
在cacti的数据库中找到表npc_programstatus,从表中选取programstatus_id、instance_id、status_update_time、last_command_check、last_log_rotation等几个字段并删除前面的一条记录,刷新一会,应该就可以出图。如下图所示:
网站题目:Cacti与nagios结合所需插件的安装与报错处理
本文链接:http://cdiso.cn/article/jcjgos.html