Chinaunix首页 | 论坛 | 博客
  • 博客访问: 844912
  • 博文数量: 63
  • 博客积分: 1317
  • 博客等级: 中尉
  • 技术积分: 686
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-30 22:07
文章分类

全部博文(63)

文章存档

2015年(4)

2014年(1)

2013年(1)

2012年(2)

2011年(54)

2010年(1)

我的朋友

分类: LINUX

2011-06-10 16:56:16

前一阵子,安装CACTI监控系统,顺便记录了安装配置的过程,坎坷呀。把当时纪录的东西放在网上,方便以后查阅。格式比较乱,有空了再好好整理下吧。
 CACTI安装配置
 一、安装

网上有很多CACTI的安装教程,详细程度不一。我在参照安装的时候也是参照了多个文档。这里不进行详细的介绍了。只要目的达到,方法可以有多种。

目的就是依次安装:

Apache

我是编译安装,./configure  --prefix=/cacti/apache  –-enable-so  --enable-rewrite

第一次安装之后没有达到预想的效果,再次安装的时候,指定prefix后编译时报错:install: error: cannot install `libaprutil-1.la' to a directory not ending in /usr/local/apache22/lib

Google一下,把安装文件彻底删除之后重新解压,重新安装,就可以了。

Mysql

我是编译安装,./configure  --prefix=/cacti/mysql  --sysconfdir=/etc

cp support-files/my-medium.cnf  /etc/my.cnf

PHP

我是编译安装:

./configure  --prefix=/cacti/php  --with-apxs2=/cacti/apache/bin/apxs  --with-config-file-path=/cacti/php  --with-freetype-dir=/cacti/freetype   --with-mysql=/cacti/mysql  --with-gd=/cacti/gdpnp4nagios安装需要)  --with-zlib=/cacti/zlib pnp4nagios安装需要) --enable-sockets   --enable-mbstring  --with-pdo-mysqlnpc安装需要)

由于第一次安装后效果没有出来,后来又安装了一次,发现安装之后无法启动apache,报错:Cannot load /usr/lib/apache2/modules/libphp5.so into server:
  /usr/lib/apache2/modules/libphp5.so: undefined symbol: OnUpdateLong

google了一下,把php安装文件整个删除,然后重新解压,重新安装,就可以了。

RRDTool

我是rpm安装,rpm安装时必须一次性安装3个包,否则无论先安装哪一个都会报错。

rrdtool-1.4.1-1.el5.wrl.x86_64.rpm

rrdtool-devel-1.4.1-1.el5.wrl.x86_64.rpm

rrdtool-perl-1.4.1-1.el5.wrl.x86_64.rpm

rpm  -ivh *.rpm

NET-SNMP

我是rpm包安装,需要先装lm_sensors

 

以上各个软件安装的时候可以yumrpm,也可以编译安装。涉及到的依赖包主要取决于你安装操作系统时候的选择。只要能够安装成功即可。

二、配置文件修改 httpd.conf

安装完php之后需要修改httpd.conf,添加如下内容:

LoadModule     php5_module       modules/libphp5.so

dir_module>

    DirectoryIndex  index.php   index.html

AddType   application/x-httpd-php   .php

php.ini

需要修改时区:date.timezone=PRC

如果不修改,会报如下错误:

It is not safe to rely on the system's timezone settings

这是因为PHP所取的时间是格林威治标准时间,所以和你当地的时间会有出入格林威治标准时间和北京时间大概差8个小时左右,我们可以按照下面的方法解决: 2、在php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时取消这一行代码的注释,即去掉前面的分号就可以了。

mysql

创建cacti数据库和导入cacti文件包里的cacti.sql文件
mysqladmin --user=root -p create cacti;
mysql --user=root -p cacti
创建访问cacti数据库的用户.(如果懒得话直接用root)

shell> mysql --user=root mysql
mysql> GRANT ALL ON cacti.* TO
IDENTIFIED BY 'somepassword';
mysql> flush privileges

设置cacti下的rralog目录,让用户具有读写的权限
shell> chown -R cactiuser rra/ log/
设置定时获取snmp数据并生成rrd文件
crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

这里的php最好指定绝对路径

snmpd.conf

配置snmp,,修改snmp的配置文件:
  #vi /etc/snmp/snmpd.conf
 
把第89行前面的注释符号#去掉,变成
  view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
 
62行进行修改:将
  access notConfigGroup "" any noauth exact systemview  
改为
  access notConfigGroup "" any noauth exact mib2 none none
(
注意:snmp默认的弱口令为Public为了安全大家可以更改成自己喜欢的口令,love_forever
修改第41行的community字段..public改成love_forever就可以了,“default”改为你想哪台机器

可以看到你的snmp信息,10.10.10.10)
重启服务service snmpd restart

 

#将下边这行中的default

com2secnotConfigUser default public

#改为127.0.0.1

com2secnotConfigUser 127.0.0.1 public

#将下边这行中的systemview

access notConfigGroup "" any noauth exact systemview none none

#改为all

access notConfigGroup "" any noauth exact all none none

#将下边这行的注释“#”号去掉

#view all included .1 80

配置完毕检测方法

Apache安装成功检测方法:

能够正常启动httpd进程,并能打开默认页面。

 

Mysql安装成功检测方法:

能够执行mysql –u root –p

 

PHP安装成功检测方法:

编辑默认页面index.php

phpinfo();

?>

能够通过浏览器打开。

 

RRDTool安装成功检测方法:

rrdtoolexample目录下直接执行scripts.pl能够生生图形,并能通过浏览器显示。

 

NET-SNMP安装成功检测方法:

Snmpwalk –v 1 –c public ip

能够输出正确内容

三、安装cacti 1、解压

#把解压后的包移动到你的相应的web目录

tar xvf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /var/www/html/cacti

2、在数据库中建库、授权、导入数据库结构

#注意导入cacti.sql时该文件的路径
mysql -p

mysql> create database cacti;
mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;
mysql> use cacti;
mysql> source /var/www/html/cacti/cacti.sql;

#配置cacti以连接数据库

vi /var/www/html/cacti/include/config.php

3、浏览器下配置

#用浏览器打开 ,会显示 cacti的安装指南,设置好就不会再出现了。
#
点击 “Next”
#
选择“New Install”,点击“Next”
#
指定 rrdtool php snmp 工具的 Binary 文件路径,确保所有的路径都是显示“ FOUND”,没有 “NOT FOUND”的,点击 Finish 完成安装。
#Cacti
默认的用户名与密码是 admin,输入用户名与密码,点击 login
#
为了安全的原因,第一次登录成功后,cacti 会强制要求你更改一个新的 password ,输入新密码并确认密码,点击 save ,进入 cacti 控制台界面:
#
点击 graphs ,查看cacti 监控本机的图表:

4、增加入一个计划任务

使得 cacti 每五分钟生成一个监控图表。

crontab -e

#加入如下内容。注意poller.php的路径

*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

#确保 /var/www/html/cacti/rra/目录存在
#
如果暂时未看到图表,可以手工执行,生成图表

#php /var/www/html/cacti/poller.php > /dev/null 2>&1

5、使用 Cacti 监控 Linux 主机

#在被监控的linux主机上安装net-snmp

yum install net-snmp
vi /etc/snmp/snmpd.conf

#更改以下部分

#将下边这行中的default

com2secnotConfigUser default public

#改为10.0.0.52cacti)服务器的地址)

com2secnotConfigUser 10.0.0.52 public

#将下边这行中的systemview

access notConfigGroup "" any noauth exact systemview none none

#改为all

access notConfigGroup "" any noauth exact all none none

#将下边这行的注释“#”号去掉

#view all included .1 80

service snmpd restart

9)如果出现问题请注意一下snmp协议的版本,都用version 1是一种解决方法
如果都用version 1,需要把所有监控机和被监控机的snmpd.conf改一下
#vi /etc/snmp/snmpd.conf
#
将下边这行

view systemview included .1.3.6.1.2.1.1

#改为

view systemview included .1.3.6.1.2.1

6、配置Cacti

所谓的安装cacti也就是把cacti下的目录解压到你的web目录下..设置相应的权限和导入数据库而已
tar xzvf cacti-version.tar.gz
拷贝到你的web目录下
默认用户和密码是admin第一次登陆会强制更改密码..
点击左上角的graphs图片就可以看图片了..
console->configuration->settings->general这里可以配置snmpsnmp community改成自己的snmp的口令就可以了..其他的不用动..snmp version 按照默认的not in use就可以了.console-

>configuration->settings->path设置命令的路径..

如果不能生成图片通过apache的错误日志分析...看看rrd目录下是否有文件生成..以及snmp能否正确抓取信息,开启cactigraph debug mode
console->management->devices->localhost->graph list
任意选择一个graph title进去,点击右上角的turn on graph debug mode..就可以了..同时看看下面的rrdtool says是否是OK如果不是他会给出不能生成图片的原因

如果console->management->devices中的主机状态时 unstatus 而不是up的话很可能是snmp没有设置

..点击主机进去看看左上角的ping results 是否是成功

7、故障解决:

(引用google上的原文)

上下载的源码安装apache2
Redhat AS 4
执行了configure,make
make install
时出错:

/bin/sh /usr/local/httpd-2.2.3/srclib/apr/libtool --mode=install /usr/bin/install -c -m 755 libaprutil-1.la /usr/local/apache2/lib
libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending in /usr/local/apache22/lib
make[2]: *** [install] Error 1

经过折腾之后找到规律:
./configure
make
make install
顺序不会出错

./configure --prefix=/app/apache
make
make install
顺序就会出错...
分析:
apache网站上下载的source code,应该不会有如此不能安装到非/usr/local目录的低级错误。
肯定是自己有疏忽,猜测可能是以前安装用过./configure 来直接安装到/usr/local/apache2
导致安装文件已经不太干净

解决:
删除source code目录,重新tar -zxvf下载的apache安装包,上面的问题解决。

后来google了下面一句:

If some options do not become active after doing a configure; make; make install, try to do a make clean after configure.
看来make clean也是一个解决方式.... 可叹以前重新编译Linux 内核的时候还用过它...四年不用就忘这么干净。

安装php之后,apache无法启动

however, when I try to start Apache I get this.

 # /etc/init.d/apache2 restart
 * Restarting web server apache2      
  apache2: Syntax error on line 185 of /etc/apache2/apache2.conf:
  Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load:
  Cannot load /usr/lib/apache2/modules/libphp5.so into server:
  /usr/lib/apache2/modules/libphp5.so: undefined symbol: OnUpdateLong

 

删了安装文件,重新解压,重新安装

3、不显示图形的故障

装好cacti之后,不能显示图形,在rrdtoolexample目录下直接执行scripts.pl可以生成图形。Rrdtool应该没问题,是php没有获取到数据,检查phpcrontab,发现可以获取数据。但是cacti/rrd下面就是没有任何文件。Debug  grahs,报错:

RRDTool Says:

ERROR: opening '/cacti/apache/htdocs/cacti/rra/xxxx.rrd': No such file or directory.

配置完graphs之后没有图形出现,说debug 图形,有如下报错:

 

ERROR: opening '/cacti/apache/htdocs/cacti/rra/dns-cnc_ucd_load1min_461.rrd': No such file or directory


手动执行rrdtool ,检查snmp,mysql,apache都运行正常,手动执向crontab的内容

Php  /cacti/apache/htdocs/cacti/poller.php

发现图形出现了,但是一直没有数据

检查cacti/log,只有一条执行信息。

再次手动执向crontab的内容

数据有了,不过不连贯…..

很显然,crontab没有执行成功造成数据获取不到,将php改成绝对路径之后,一切ok。

四、安装CACTI插件

1、安装插件框架:
1.解压

1.cd /opt/htdocs/www

2.unzip cacti-plugin-0.8.7e-PA-v2.6.zip

3.chown -R apache:apache cacti-plugin-arch/

4.chmod -R 0775 cacti-plugin-arch

2.导入数据库结构

1.mysql -u cacti -p cacti
3.覆盖文件
方法一:覆盖

1.cp -rf cacti-plugin-arch/files-0.8.7e/* /opt/htdocs/www/cacti

方法二:打补丁

1.cp cacti-plugin-arch/cacti-plugin-0.8.7e-PA-v2.6.diff /opt/htdocs/www/cacti/
2.cd /opt/htdocs/www/cacti/
3.patch -p1 -N 2、配置插件的数据库信息

#cd /opt/htdocs/www/cacti/
#vi include/global.php
#插件数据库需再配置一下

1.$database_type = "mysql";
2.$database_default = "cacti";
3.$database_hostname = "localhost";
4.$database_username = "cactiuser";
5.$database_password = "cacti";

3、配制插件

1.#我的cacti安装在域下的cacti目录,这里也需修改
2.$config['url_path'] = '/cacti/';
3.
4.#为后面安装npc增加变量
5.$plugins[] = 'npc';

将npc解压后拷贝到 cacti/plugins/目录下即可。

启用cacti的插件功能,

以admin用户登陆cacti,在console中的user management里对admin的用户权限进行编辑,
勾选上Plugin Management、NPC、NPC Global Commands
然后到Plugin Management
安装并启用NPC即可。
五、整合Nagios
1、安装nagios

2、安装NDO

Ndoutils

下载,configure

./configure –enable-mysql –with-mysql=/cacti/mysql   --disable-pgmysql

Make

如果make报错,找不到mysql.h和errmsg.h,重新configure,make前修改include/config.h,参考下面的故障解决

 

cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin
cd ../db

mysql –u root –p
create database ndodb;
grant all on ndodb.* to nagios@localhost identified by ‘123qwe’;
flush privileges;

3、故障解决

安装ndoutils-1.4b9时报以下错

# ./configure --enable-mysql --with-mysql=/usr/local/mysql
# make
cd ./src && make
make[1]: Entering directory `/root/nagiosddd/ndoutils-1.4b9/src'
gcc -fPIC -g -O2 -I/usr/local/mysql/include/mysql -DHAVE_CONFIG_H -c -o io.o io.c
In file included from io.c:11:
../include/config.h:261:25: error: mysql/mysql.h: No such file or directory
../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory
make[1]: *** [io.o] Error 1
make[1]: Leaving directory `/root/nagiosddd/ndoutils-1.4b9/src'
make: *** [all] Error 2

解决方法
# vi include/config.h

#include
#include
修改为
#include
#include

4、安装DBI,DBD

DBI rpm安装,DBD也想RPM安装,但是因为mysql版本比较高,所以提示找不到libmysqlclient.so.15(实际上存在libmysqlclient.so.16)

就下载了最新的DBD安装包,编译安装

Perl Makefile.pl

Make

Make install

 

安装好之后执行

./installdb –u nagios –p 123qwe –h localhost –d ndodb

报错:

install_driver(mysql) failed: Can't load '/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so' for
module DBD::mysql: libmysqlclient.so.16: cannot open shared object file: No such file or directory at
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
at (eval 5) line 3

上面错误一看是找不到libmysqlclient.so.16 ,先find

# find /usr/ -name "libmysqlclient.so*"                           
/usr/local/mysql/lib/mysql/libmysqlclient.so.16.0.0
/usr/local/mysql/lib/mysql/libmysqlclient.so.15
/usr/local/mysql/lib/mysql/libmysqlclient.so

解决方法:

echo "/usr/local/mysql/lib/mysql/" >>   /etc/ld.so.conf
ldconfig

完成

5、复制、编辑配置文件

    cd ../config
    cp ndo2db.cfg-sample /usr/local/nagios/etc/
    cp ndomod.cfg-sample /usr/local/nagios/etc/
    mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
    mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
    chmod 644 /usr/local/nagios/etc/ndo*
    chown nagios:nagios /usr/local/nagios/etc/*
    chown nagios:nagios /usr/local/nagios/bin/*
   
在下面的文件中添加:
    vim /usr/local/nagios/etc/nagios.cfg
   
添加(注意一定是在同一行):
   broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
   
另外确保在此文件中有
    event_broker_options=-1
   
执行下面的命令,检查配置文件是否正确
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
3
、编辑ndo2db守护进程和ndomod的配置文件
    vim /usr/local/nagios/etc/ndo2db.cfg
    socket_type=tcp
    db_servertype=mysql
    db_host=localhost
    db_port=3306
    db_name=ndodb
    db_prefix=nagios_
    db_user=ndouser
    db_pass=password
    vim /usr/local/nagios/etc/ndomod.cfg
    output_type=tcpsocket
    output=127.0.0.1
4
、启动ndo2db守护进程
    /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
5
、重启nagios服务(必须这样启动)
    killall -SIGHUP nagios
    rm -f /usr/local/nagios/var/nagios.lock
    /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

 

配置ndo2db.cfg

socket_name=/var/nagios/ndo.sock
db_name=cacti
db_prefix=npc_
db_user=cacti
db_pass=xxxxx
debug_level=1
debug_file=/var/nagios/ndo2db.debug

以上为需要根据自己的实际情况配置的信息,其他配置可以根据自己需求来进行配置。

配置ndomod.cfg

output=/var/nagios/ndo.sock
buffer_file=/var/nagios/ndomod.tmp

Settings->npc
勾上Remote Commands
Nagios Command File Path=/usr/local/nagios/var/rw/nagios.cmd
Nagios URL=
你的地址()

6、故障解决

npc装好之后,获取不到数据,apacheerror_log里面提示:

PHP Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'Couldn't locate driver named mysql' in /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Connection.php:483\nStack trace:\n#0 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Connection/Mysql.php(103): Doctrine_Connection->connect()\n#1 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Connection.php(1009): Doctrine_Connection_Mysql->connect()\n#2 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Connection.php(808): Doctrine_Connection->execute('SELECT COUNT(*)...', Array)\n#3 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Query.php(1894): Doctrine_Connection->fetchAll('SELECT COUNT(*)...', Array)\n#4 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Pager.php(108): Doctrine_Query->count(Array)\n#5 /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Pager.php(570): Doctrine_Pager->_initialize(Array)\n#6 /usr/local/apache2/htdocs/cacti/plugins/npc/controllers/logentries.php(60): Doctrine_Pager->execute( in /usr/local/apache2/htdocs/cacti/plugins/npc/lib/Doctrine/Connection.php on line 483,

 

first check u php pdo support for mysql...

if no mysql in this tab, please reinstall u php with the Configuration option " --with-pdo-mysql" ,and u will find u npc is running ok!

发现没有mysql

重新编译安装php

报错

checking for mysql_config... not found

configure: error:Unable to find your mysql installation

Now fixed.
The npc_* tables are not created correctly by the NPC plugin.
Modified and then loaded the ndoutils mysql.sql file into the cacti database before enabling NPC plugin .

 

另一个错误:

ndomod: Still unable to connect to data sink

ndo没有向mysql写入数据。

Make sure that your ndo2db.cfg and ndomod.cfg files are owned by the same users that runs ndo2db and Nagios.
In my case it is "nagios".

I noticed that ndo.sock was not being created in /usr/local/nagios/var.
On a hunch I checked the permissions on the two config files (mentioned above) and found that they were owned by root, since I was logged in as root when I copied them over from the nod-utils distribution.

As soon as I changed the ownership, restarted ndo2db and nagios, the problem was solved.

Hope this helps someone.

六、PNP4Nagios

Pnp4nagiosnagios的画图工具,一块儿写在这儿吧

 

PHP GD extension PHP GD extension not available PHP function proc_open() Pass

PHP zlib extension PHP zlib extension not available

Rpm –qa|grep gd

Rpm –qa|grep zlib

都已经安装了

重新编译php

增加configure项:--with-gd  --with-zlib

Ok

 

阅读(14515) | 评论(0) | 转发(0) |
0

上一篇:forfiles命令详解

下一篇:AMQ8135 not authorized

给主人留下些什么吧!~~