cacti 安装配置

【基本介绍】-> 百科
cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。
snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。

【依赖软件】
web服务器:Apache 或者 nginx 等
Mysql : 用了存储相应的数据
Php : 用来解析cacti
rrdtool :用来生成和存储图表和数据 http://oss.oetiker.ch/rrdtool/
net-snmp : 用来抓取网络数据 http://www.net-snmp.org/
cacti : 用来整合各个软件并呈现 http://www.cacti.net/

【安装环境】
以下的软件在CentOS5.8测试通过
mysql5.1.73
php5.4.24
apache2.2
rrdtool1.4.8
netsnmp5.5
cacti0.8.7

【安装配置net-snmp】
安装# yum install -y net-snmp net-snmp-libs net-snmp-utils
配置# vi /etc/snmp/snmpd.conf
# First, map the community name "public" into a "security name"

# sec.name source community

com2sec notConfigUser [color=red]127.0.0.1[/color] public

####

# Finally, grant the group read-only access to the systemview view.

# group context sec.model sec.level prefix read write notif

access notConfigGroup "" any noauth exact [color=red]all [/color]none none


## incl/excl subtree mask

view all included .1 80 (去掉前面的注释 “#”)

检测snmp,如果一下命令没有数据在检查snmp配置
# snmpwalk -c public -v 2c localhost
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex


【安装rrdtool】
这里用编译安装源码方式
检测rrdtool命令是否成功
RRDtool 1.4.8 Copyright 1997-2013 by Tobias Oetiker <tobi@oetiker.ch>
Compiled Jun 18 2014 03:06:44

Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, info, fetch, tune,
resize, xport, flushcached

RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)

For more information read the RRD manpages

【安装cacti】
解压源码到web的documentroot下面(例如/var/www/html/cacti)

【mysql安装配置】
mysql安装省略
创建cacti数据库
# mysqladmin -u root -p create cacti

给cacti数据库的用户权限
mysql> grant all on cacti.* to cactiuser@localhost identified by 'cacti123!@#';
mysql> flush privileges;
mysql> quit

导入cacti的数据,cacti.sql在源码的根目录下面
# mysql -uroot -pNCroot cacti<cacti.sql

为cacti配置数据库连接
# vim /var/www/html/cacti/include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cacti123!@#";
$database_port = "3306";
$database_ssl = false;

【apache/nginx php】
apache+php : php是作为apache的一个模块来使用的。在编译的时候要注意参数,使他们支持相应的模块
nginx+php+fpm : nginx使用php是通过fpm来实现的。相应配置php-fpm

【后续】
首次登入cacti会进入cacti installation guide,进行相应的配置。
初始用户名和密码是admin,登入成功后强制修改

制定cron,持续生成相应的rrd文件
*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1

【错误总结】
1.很大部分是跟php有关系,本来对Php语言不是很熟悉大部分百度
例如:
(1)It is not safe to rely on the system's timezone settings.
在php.ini里面配置时区 date.timezone ="Asia/Shanghai"
(2)PHP Strict Standards: Only variables should be passed by reference in /usr/local/nginx/html/cacti/lib/ping.php on line 382
好似跟php版本有关系
socket_select($r = array($this->socket), $w = NULL, $f = NULL, $to_sec, $to_usec)
->>>>>>改为
$r = array($this->socket);
$w = NULL;
$f = NULL;
socket_select($r, $w, $f, $to_sec, $to_usec)


2.使用rrdtool的问题主要是对perl的支持问题
(1) Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.BEGIN failed--compilation aborted at Makefile.PL line 3.
安装perl扩展: yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker


3.不能生成rrd文件(页面上没有图片生成)
页面没有图片检查相应的rrd文件是否生成。可以手动执行(根据情况添加参数--debug --force)并解决相应的错误。这里忽略cron和执行时间间隔太短的问题
/usr/local/php5.4.24/bin/php /var/www/html/cacti/poller.php

4.页面有图片但是没有数据
还是去检查rrd文件是否更新和是否有数据(没数据的话都是nan)
列如:
rrdtool fetch localhost_users_6.rrd AVERAGE | grep -v nan
users
1403174100: 2.0000000000e+00
1403174400: 2.0000000000e+00
数据都是nan的话在页面上开启debug模式查看cacti的log看具体问题

5.权限问题
我一般是把rra plugins log这3个文件夹权限弄成777.cmd.php添加执行权限。关于用户名,这里并没有设置全部都是root

6.log里面执行语句都正常但是rrd文件就是没数据
我是手动执行update后就都有数据产生了
/usr/local/bin/rrdtool update /usr/local/nginx/html/cacti/rra/localhost_cpu_system_17.rrd --template cpu_system N:12377

【参考】
[url]http://blog.sina.com.cn/s/blog_4e424e2101000b5y.html[/url]
[url]http://oss.oetiker.ch/rrdtool/pub/?M=D[/url]
[url]http://www.cacti.net/downloads/[/url]
[url]http://88fly.blog.163.com/blog/static/1226803902011290280920/?suggestedreading[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值