免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7082 | 回复: 13
打印 上一主题 下一主题

庆祝07情人节到来,发原创Nagios Plugin for Cacti 安装使用篇 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-13 14:45 |只看该作者 |倒序浏览
cacti中文论坛需要免费带宽,有能提供的朋友感激不尽!!
关于以下文章图形看不到的问题可以去我的BLOG里下载PDF格式。
Nagios Plugin for Cacti 安装使用篇
作者:Mars_angels(CU之初学vb)
来源:cacti 中文论坛

前言:
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.tgzadodb471-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的承托用户
我这里是daemon2.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

论坛徽章:
0
2 [报告]
发表于 2007-02-13 14:46 |只看该作者
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包安装完成

论坛徽章:
0
3 [报告]
发表于 2007-02-13 14:46 |只看该作者
配置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.

Make sure you've compiled the main program and the CGIs to use the same object data storage options (i.e. default text file or template-based file).



Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing 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 go to a pending state until rechecked by Nagios. Without this setting the inserter module will never update any data in NPC. Its a minor inconvenience 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也可以提供相应的监控界面来帮助你整合资源。

论坛徽章:
0
4 [报告]
发表于 2007-02-13 14:50 |只看该作者
如果有问题请去我的BLOG中问即可,欢迎有提供免费的带宽XD合作。

论坛徽章:
0
5 [报告]
发表于 2007-02-14 08:50 |只看该作者
大家好像对监控不太热情啊!

论坛徽章:
0
6 [报告]
发表于 2007-02-14 17:13 |只看该作者
请问对文件流的传输有比较好的监控方案吗?
比如监控某个文件是否在指定时间段内传输到指定地点,并有每日的报表生成。

论坛徽章:
0
7 [报告]
发表于 2007-02-21 09:34 |只看该作者
我有带宽资源,如果你在北京,可以放一台主机过来,给你2m左右的带宽,长期且稳定
q:1851733

论坛徽章:
0
8 [报告]
发表于 2007-02-27 15:12 |只看该作者
修改cgi.cfg,把use_authentication=1改为use_authentication=0,即不用验证.不然有一些页面不会显示。

上面这个应该改成1,启用验证,而且这个文件有好几个地方需要修改,以便指定相关用户权限,否则,将出现在web下不能执行"Comments"
"Downtime"
  "Process Info"---重启nagios服务.
"Performance Info"
"Scheduling Queue"
等操作,网上的文章老忽略这样的问题,看来大家没有真正使用这个工具!!

论坛徽章:
0
9 [报告]
发表于 2007-02-27 19:39 |只看该作者
在客户端怎么也打不开 http://ip/nagios/
这时怎么回事啊?
/var/log/httpd/error_log

********************************************************************************************
[Tue Feb 27 20:54:55 2007] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Tue Feb 27 20:54:55 2007] [notice] Apache/2.0.52 (Red Hat) configured -- resuming normal operations
[Tue Feb 27 20:55:00 2007] [error] [client 192.168.1.123] MySQL ERROR: Table 'test.user_info' doesn't exist: /nagios/
[Tue Feb 27 20:55:00 2007] [error] [client 192.168.1.123] MySQL user nagios not found: /nagios/
[Tue Feb 27 20:55:03 2007] [error] [client 192.168.1.123] MySQL ERROR: Table 'test.user_info' doesn't exist: /nagios/
[Tue Feb 27 20:55:03 2007] [error] [client 192.168.1.123] MySQL user nagios not found: /nagios/
[Tue Feb 27 20:55:04 2007] [error] [client 192.168.1.123] MySQL ERROR: Table 'test.user_info' doesn't exist: /nagios/
[Tue Feb 27 20:55:04 2007] [error] [client 192.168.1.123] MySQL user nagios not found: /nagios/
[Tue Feb 27 20:55:05 2007] [error] [client 192.168.1.123] MySQL ERROR: Table 'test.user_info' doesn't exist: /nagios/
[Tue Feb 27 20:55:05 2007] [error] [client 192.168.1.123] MySQL user nagios not found: /nagios/



高手指点啊

论坛徽章:
0
10 [报告]
发表于 2007-02-28 10:51 |只看该作者
nagios目录定义不对???
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP