cacti

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具

Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。界面友好。

CACTI

CACTI

软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了基本的 Snmp 流量跟系统资讯监控外,Cacti 也可外挂 Scripts 及加上 Templates 来作出各式各样的监控图。

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),它能够存储的数据笔数在创建时就已经定义。


实验环境

centos 5.5


需要软件包

cacti-0.8.8a.tar.gz

cacti-spine-0.8.8a.tar.gz

rrdtool-1.3.8.tar.gz


yum install httpd* -y

yum install mysql* php php-mysql* mod_ssl mod_mod_auth_mysql mod_auth_mysql mod_perl php-gd php-xml xml php-mbstring php-ldap php-pear php-xmlrpc -y

yum install mysql-connector-odbc mysql-devel libdbi-dbd-mysql -y

yum install net-snmp* -y

yum install pango-devel* cairo-devel* intltool -y

yum install zlib libpng freetype libart_lgpl libart_lgpl-devel libxml* pango*  -y


chkconfig --level 35 httpd on  

chkconfig --level 35 snmpd on  

chkconfig --level 35 mysqld on

setenforce 0   


tar zxvf cacti-0.8.8a.tar.gz

mv cacti-0.8.8a /var/www/html/cacti


tar zxvf rrdtool-1.3.8.tar.gz

mv rrdtool-1.3.8 /usr/local/rrdtool

cd /usr/local/rrdtool/

./configure

make make install

 

tar zxvf cacti-spine-0.8.8a.tar.gz

mv cacti-spine-0.8.7h /usr/local/spine

cd /usr/local/spine/

./configure

make

make install


cd /var/www/html/cacti/

mysqladmin -uroot password  数据库密码

mysqladmin -uroot -p create cacti character set utf8;  utf8为中文需要汉化的可以选择这一步

mysqladmin -uroot -p flush privileges;                 刷新权限

mysql -uroot -p cacti < cacti.sql                      导入cacti数据库


vim include/config.php

修改内容如下:

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "root";

$database_password = "******";

$database_port = "3306";

$database_ssl = false;


vim include/global.php

修改内容如下:

/* Default database settings*/

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "root";

$database_password = "******";  数据库密码


vim /etc/crontab                       添加计划任务

添加 */5 * * * * root php /var/www/html/cacti/poller.php


cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf

vi /etc/spine.conf

DB_Host         localhost

DB_Database     cacti

DB_User         cactiuser

DB_Pass         cactiuser

DB_Port         3306

DB_PreG         0


http://服务器ip/cacti


163959950.png


164114646.png


164349166.png

find /usr/local/ -name rrdtool

/usr/local/rrdtool-1.3.8/bin/rrdtool 复制路径刷新即可


164527663.png

默认用户名  admin  admin


164644348.png

修改密码 给为 新的密码


164809181.png

cacti搭建完毕

cacti搭建完成,为了能更好使用需要修改snmp配置文件

vim  /etc/snmp/snmpd.conf

找到

com2sec notConfigUser  default       public

更改为

com2sec notConfigUser  all           public  

找到

access  notConfigGroup ""      any       noauth    exact  systemview none none

更改为

access  notConfigGroup ""      any       noauth    exact  all none none

找到

#view all    included  .1                               80

更改为

view all    included  .1                               80

找到

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

改为

view mib2   included  .iso.org.dod.internet.mgmt.mib-2  fc


/etc/rc.d/init.d/crond restart

Stopping crond: [  OK  ]

Starting crond: [  OK  ]


vim /etc/php.ini

找到 ;date.timezone =

改为 date.timezone = Asia/shanghai



测试rrdtool,是否生成图片的命令

php /var/www/html/cacti/poller.php

05/23/2013 10:39:23 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval!  The Poller Interval is '60' seconds, with a maximum of a '300' second Cron, but 262 seconds have passed since the last poll!

OK u:0.00 s:0.01 r:7.62

OK u:0.00 s:0.01 r:7.62

OK u:0.00 s:0.01 r:10.25

05/23/2013 10:39:34 PM - SYSTEM STATS: Time:10.9177 Method:spine Processes:1 Threads:1 Hosts:17 HostsPerProcess:17 DataSources:20 RRDsProcessed:10

OK u:0.00 s:0.01 r:10.82

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.84

OK u:0.00 s:0.01 r:10.84

看到这个提示,证明rrdtool已经获得了数据


检查snmp获得数据是否正常可以使用

snmpwalk -v 2c -c public 127.0.0.1 if

IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifIndex.4 = INTEGER: 4
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: eth1
IF-MIB::ifDescr.4 = STRING: sit0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.3 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.4 = INTEGER: tunnel(131)
IF-MIB::ifMtu.1 = INTEGER: 16436
IF-MIB::ifMtu.2 = INTEGER: 1500
IF-MIB::ifMtu.3 = INTEGER: 1500
IF-MIB::ifMtu.4 = INTEGER: 1480
IF-MIB::ifSpeed.1 = Gauge32: 10000000
IF-MIB::ifSpeed.2 = Gauge32: 1000000000
IF-MIB::ifSpeed.3 = Gauge32: 1000000000
IF-MIB::ifSpeed.4 = Gauge32: 0
IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING: 0:50:56:b2:dd:6a
IF-MIB::ifPhysAddress.3 = STRING: 0:50:56:b2:4a:bf
IF-MIB::ifPhysAddress.4 = STRING:
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifAdminStatus.3 = INTEGER: down(2)
IF-MIB::ifAdminStatus.4 = INTEGER: down(2)
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.3 = INTEGER: down(2)
IF-MIB::ifOperStatus.4 = INTEGER: down(2)
IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.3 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.4 = Timeticks: (0) 0:00:00.00
IF-MIB::ifInOctets.1 = Counter32: 456696
IF-MIB::ifInOctets.2 = Counter32: 13011691
IF-MIB::ifInOctets.3 = Counter32: 0
IF-MIB::ifInOctets.4 = Counter32: 0
IF-MIB::ifInUcastPkts.1 = Counter32: 3736
IF-MIB::ifInUcastPkts.2 = Counter32: 82264
IF-MIB::ifInUcastPkts.3 = Counter32: 0
IF-MIB::ifInUcastPkts.4 = Counter32: 0
IF-MIB::ifInNUcastPkts.1 = Counter32: 0
IF-MIB::ifInNUcastPkts.2 = Counter32: 0
IF-MIB::ifInNUcastPkts.3 = Counter32: 0
IF-MIB::ifInNUcastPkts.4 = Counter32: 0
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInDiscards.2 = Counter32: 0
IF-MIB::ifInDiscards.3 = Counter32: 0
IF-MIB::ifInDiscards.4 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0
IF-MIB::ifInErrors.2 = Counter32: 119
IF-MIB::ifInErrors.3 = Counter32: 0
IF-MIB::ifInErrors.4 = Counter32: 0
IF-MIB::ifInUnknownProtos.1 = Counter32: 0
IF-MIB::ifInUnknownProtos.2 = Counter32: 0
IF-MIB::ifInUnknownProtos.3 = Counter32: 0
IF-MIB::ifInUnknownProtos.4 = Counter32: 0
IF-MIB::ifOutOctets.1 = Counter32: 456696
IF-MIB::ifOutOctets.2 = Counter32: 38508110
IF-MIB::ifOutOctets.3 = Counter32: 0
IF-MIB::ifOutOctets.4 = Counter32: 0
IF-MIB::ifOutUcastPkts.1 = Counter32: 3736
IF-MIB::ifOutUcastPkts.2 = Counter32: 70719
IF-MIB::ifOutUcastPkts.3 = Counter32: 0
IF-MIB::ifOutUcastPkts.4 = Counter32: 0
IF-MIB::ifOutNUcastPkts.1 = Counter32: 0
IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
IF-MIB::ifOutNUcastPkts.3 = Counter32: 0
IF-MIB::ifOutNUcastPkts.4 = Counter32: 0
IF-MIB::ifOutDiscards.1 = Counter32: 0
IF-MIB::ifOutDiscards.2 = Counter32: 0
IF-MIB::ifOutDiscards.3 = Counter32: 0
IF-MIB::ifOutDiscards.4 = Counter32: 0
IF-MIB::ifOutErrors.1 = Counter32: 0
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifOutErrors.3 = Counter32: 0
IF-MIB::ifOutErrors.4 = Counter32: 0
IF-MIB::ifOutQLen.1 = Gauge32: 0
IF-MIB::ifOutQLen.2 = Gauge32: 0
IF-MIB::ifOutQLen.3 = Gauge32: 0
IF-MIB::ifOutQLen.4 = Gauge32: 0
IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.4 = OID: SNMPv2-SMI::zeroDotZero

如果出现这一些,证明snmp可以正常抓取数据



120148262.png



如果出现这个,证明cacti正常工作



配置客户端,客户端以windows xp为例

1 控制面板-添加删除程序-添加删除windows组件-管理与监视工具-snmp有两个选项,全部勾线安装

2 cmd-services.msc

3 找到snmp服务

101956333.png

右键-属性

101956361.png




101956383.png

团体名字默认为public(可以更改),但是要和服务器端名字相同

接收来自snmp包的ip地址为服务器端ip地址,点击应用-确定

重启客户端snmp服务

102339334.png

右键-重启服务


102505945.png

这样windows xp客户端配置就完成了


介绍如何,配置客户端,客户端以linux(centos) 为例

yum -y install net-snmp

vim  /etc/snmp/snmpd.conf

找到

com2sec notConfigUser  default       public

更改为

com2sec notConfigUser  cacti服务端ip          public  

找到

access  notConfigGroup ""      any       noauth    exact  systemview none none

更改为

access  notConfigGroup ""      any       noauth    exact  all none none

找到

#view all    included  .1                               80

更改为

view all    included  .1                               80

找到

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

改为

view mib2   included  .iso.org.dod.internet.mgmt.mib-2  fc


/etc/rc.d/init.d/crond restart

Stopping crond: [  OK  ]

Starting crond: [  OK  ]

如果监控Linux客户端出现snmp检测不到网卡,处理方法是,添加主机选择 ccd/netSNMPHost 这个模版

本文出自 “mailfile” 博客,谢绝转载!

你可能感兴趣的:(CACTI搭建)