打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Nagios Plugin for Cacti 安装使用篇
userphoto

2010.03.03

关注

前言:
Nagios Plugin for Cacti 简称 npc,是cacti的一个插件,这篇文章主要介绍如何在cacti中使用npc插件。


测试环境:
操作系统:rhel4u4 php4.4.4 mysql-4.1.22 httpd-2.2.4
npc主页:http://www.divagater.com/npc/
npc 当前版本:NPC 0.1.1a
nagios 主页:http://www.nagios.org
nagios 当前版本:nagios-2.7
nagios 插件当前版本:nagios-plugins-1.4.6
fruity:图形化配置nagios的工具,需要php5.x版本才能运行
http://fruity.sourceforge.net/
http://heanet.dl.sourceforge.net/sourceforge/fruity/
http://pear.php.net/get/HTML_TreeMenu-1.2.0.tgz
http://puzzle.dl.sourceforge.net/sourceforge/adodb/adodb471-1.tgz
将HTML_TreeMenu-1.2.0.tgz和adodb471-1.tgz直接解压复制到fruity 下 分别改名为HTML 和adodb 其他不做修改
修改 fruity/includes下的config.ifg,需要更改的地方有,路径,mysql信息
mysql 添加fruity 数据库和user,password.
这样,就可以用fruity来进行配置了。
注意:
在cacti服务器上的mysql版本必须是4.1以上,因为npc是以mysql4.1为基础进行开发的。

第一章:安装nagios
我们在cacti中使用nagios,首先我们要安装nagios环境,安装过程如下:
# tar –xvzf nagios-2.7.tar.gz
# mkdir /usr/local/nagios
# useradd nagios –d /usr/local/nagios
# passwd nagios 1qazSE$
# chmod 755 /usr/local/nagios
# grep "^User" /etc/httpd/conf/httpd.conf //查找apache的承托用户
我这里是daemon。2.2.0以前的apache版本可能会是nobody
# /usr/sbin/groupadd nagcmd

# /usr/sbin/usermod -G nagcmd daemon-----这个地方就是前面的aapche承托用户

# /usr/sbin/usermod -G nagcmd nagios


# cd nagios-2.7
#./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include --enable-event-broker
# make all
# make install
# make install-init 安装启动脚本到/etc/init.d/
# make install-commandmode
# make install-config 安装初始配置文件到/usr/local/nagios

nagios-plugins的安装
tar –xvzf nagios-plugins-1.4.6.tar.gz
cd nagiso-plugins-1.4.6
./configure --prefix=/usr/local/nagios-plugins
make all
make install
注意:
nagios-plugins 1.4.6编译安装时出错修正:
Making install in po
make[1]: Entering directory `/opt/software/nagios/nagios-plugins-1.4.6/po'
/bin/sh @MKINSTALLDIRS@ /usr/local/nagios-plugins/share
/bin/sh: @MKINSTALLDIRS@: No such file or directory
make[1]: *** [install-data-yes] Error 127
make[1]: Leaving directory `/opt/software/nagios/nagios-plugins-1.4.6/po'
make: *** [install-recursive] Error 1

需要修改一下po/Makefile文件:

MKINSTALLDIRS = @MKINSTALLDIRS@
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
替换为:
MKINSTALLDIRS = $(top_builddir)/./mkinstalldirs
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
安装完成以后在/usr/local/nagios-plugins-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下即可。 如下:
# mv /usr/local/nagios-plugins/libexec /usr/local/nagios
到此,两个基本的TAR包安装完成

配置apache过程:

在apache的httpd.conf文件中加入如下字段:

ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/

<Directory "/usr/local/nagios/sbin/">

AllowOverride AuthConfig

Options ExecCGI

Order allow,deny

Allow from all

</Directory>

Alias /nagios/ /usr/local/nagios/share/

<Directory "/usr/local/nagios/share">

Options None

AllowOverride AuthConfig

Order allow,deny

Allow from all

</Directory>

注意:

如果你的apache版本是2.2.0,那么你需要把以上这段加到

<IfModule alias_module>和 </IfModule> 之间。

配置页面访问权限:

在/usr/local/nagios/share目录下

# cd /usr/local/nagios/share

# vi .htaccess

AuthName "Nagios Access"

AuthType Basic

AuthUserFile /usr/local/nagios/etc/.htpasswd

require valid-user

然后在/usr/local/nagios/sbin编辑.htaccess

#vi .htaccess

AuthName "Nagios Access"

AuthType Basic

AuthUserFile /usr/local/nagios/etc/.htpasswd

require valid-user

#/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/.htpasswd nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

这个apache目录根据安装目录的不同而不同,用htpasswd命令生成用户名和密码以控制访问权限。

配置和启动nagios过程

# cd /usr/local/nagios/etc

把目录里的.cfg-sample文件全部拷贝成.cfg

例如:

# cp nagios.cfg-sample nagios.cfg

修改cgi.cfg,把use_authentication=1改为use_authentication=0,即不用验证.不然有一些页面不会显示。

修改后用如下命令检查配置文件是否正常:

#/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg

Nagios 2.7

Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)

Last Modified: 01-19-2007

License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Checking services...

Checked 5 services.

Checking hosts...

Checked 1 hosts.

Checking host groups...

Checked 1 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 22 commands.

Checking time periods...

Checked 4 time periods.

Checking extended host info definitions...

Checked 0 extended host info definitions.

Checking extended service info definitions...

Checked 0 extended service info definitions.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

Total Warnings: 0

Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check

如上红色字标注,两个为0就是正常的,如果出错,那一定是你修改的配置文件有问题,请返回修改。

这时候你访问http://your IP/nagios/可以看到如下图

但点击其他按钮只能看到

Whoops!

Error: Could not read object configuration data!

Here are some things you should check in order to resolve this error:

Verify configuration options using the -v command-line option to check for errors.

Check the Nagios log file for messages relating to startup or status data errors.

Makesure you've compiled the main program and the CGIs to use the sameobject data storage options (i.e. default text file or template-basedfile).

Make sure you read the documentation oninstalling, configuring and running Nagios thoroughly beforecontinuing. If all else fails, try sending a message to one of themailing lists. More information can be found at http://www.nagios.org.

提示,这是因为你还没有启动nagios后台进程,按如下命令启动nagios

# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

# /usr/local/etc/rc.d/nagios start

这个时候你返回刚才的URL,点击Tactical Overview


证明你已经配置成功nagios了。使用我就不在这里讲了,网上有一些文章专门介绍。让我们开始进入cacti的世界。

第二章:npc插件的安装

就和其他插件的安装一样

# tar xzvf npc-0.1.1a.tar.gz //这会出现一个npc目录

# mv npc <cacti install folder>/plugins/

# vi <cacti install folder>/plugins/npc/neb/inserter.c

修改第143行

&mysql,"localhost","USERNAME","PASSWORD","DATABASE",3306,NULL,CLIENT_MULTI_STATEMENTS

把以上几个大写字母地方改成你自己实际情况,不会改的看我下面的例子

&mysql,"localhost","***","***","cactidb",3306,"/tmp/mysql.sock",0

否则make 会出现如下错误

# make

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/include/mysql -lmysqlclient -fPIC

inserter.c: In function `nebmodule_init':

inserter.c:143: error: `CLIENT_MULTI_STATEMENTS' undeclared (first use in this function)

inserter.c:143: error: (Each undeclared identifier is reported only once

inserter.c:143: error: for each function it appears in.)

make: *** [all] Error 1

# cp <cacti install folder>/plugins/npc/neb/* <nagios source code>/modules/

# cd <nagios source code>/modules/

# make

这里做的主要是编译inserter.o文件,要注意的问题:

gcc -g -O2 -Wall -o inserter.o inserter.c -shared -I../include -I/usr/local/mysql/include/mysql -lmysqlclient -fPIC

/usr/bin/ld: cannot find -lmysqlclient

collect2: ld returned 1 exit status

make: *** [all] Error 1

这个错误是不能找到libmysqlclient,这个其实是mysql版本问题,我们当前环境下没有能包含mysql早期版本的库,就会出现这个问题,好在mysql官方已经给我想到了解决方法,你下载一个和你当前用的版本一致的MySQL-shared-compat-***.i386.rpm包,它就是原来解决这个问题的。(***是你的版本)

编译后会发现有个inserter.o文件

# cp insert.o /usr/local/nagios/modules/

如果没有modules文件夹,你要自己建立一个。

# vi /usr/local/nagios/etc/nagios.cfg

设置如下

retain_state_information=0

event_broker_options=-1 and

broker_module=/usr/local/nagios/modules/inserter.o

原因作者写得很清楚:

NOTE:Setting retain_state_information=0 causes all hosts and services to goto a pending state until rechecked by Nagios. Without this setting theinserter module will never update any data in NPC. Its a minorinconvenience that I will try to fix in the inserter module.

# vi <cacti install folder>/include/config.php

加入$plugins[] = 'npc';到$plugins = array();下面,完成后如下:

$plugins = array();

$plugins[] = 'thold';

$plugins[] = 'monitor';

$plugins[] = 'npc'; //这个需要你自己添加的,如果不是很理解请参考我写的 插件安装

$plugins[] = 'reports';

$plugins[] = 'haloe';

$plugins[] = 'update';

登陆你的cacti

点击--Console--User Management--admin

向下拉看到

Realm permissions control which sections of Cacti this user will have access to.

找到View NPC 副选框,点上钩,如下图,为了看得方便我把它圈起来了。


这样,我们就可以看到如下


NPC插件出现了!!这个时候你还要检查你的cactidb中是否多了npc开头的数据库,如果没有,请重新登陆cacti界面。

我们点击npc,就可以看到相应的情况了,如下图


那么恭喜你,整合安装结束了,你想扩展什么,直接按原来的nagios方法进行就可以了,但不同的是cacti也可以提供相应的监控界面来帮助你整合资源。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Nagios 整合Cacti
手把手实现企业级开源监控软件cacti nagios ntop整合(图解)
【博文推荐】Cacti+Nagios监控平台完美整合(2)
nagios+cacti整合文档
centreon+nagios安装配置操作手册(6)-常见监控配置
也谈cacti整合nagios(centos)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服