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


实验环境

centos6.5_x64


实验软件

cacti-0.8.8a.tar.gz

cacti-spine-0.8.8a.tar.gz

rrdtool-1.3.8.tar.gz


软件安装

yum install httpd* 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* pango-devel* cairo-devel* intltool -y

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


service httpd restart

service mysqld restart

service snmpd restart

chkconfig --level 35 httpd on  

chkconfig --level 35 snmpd on  

chkconfig --level 35 mysqld on

cp -pv  /etc/sysconfig/selinux   /etc/sysconfig/selinux.bak

echo >  /etc/sysconfig/selinux 

echo SELINUX=disabled  >  /etc/sysconfig/selinux 

cp -pv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

sed -i  's/#ServerName www.example.com:80/ServerName  *:80/g'  /etc/httpd/conf/httpd.conf

sed -i  "s/#AddType application/AddType application/g"   /etc/httpd/conf/httpd.conf

sed -i  "37 aAddType application/x-httpd-php .php"    /etc/httpd/conf/httpd.conf   配置文件37行插入配置

echo welcome to apache server  > /var/www/html/index.html

curl  http://localhost/index.html

welcome to apache server


touch /var/www/html/test.php

echo  "<?php phpinfo(); ?>"  > /var/www/html/test.php 


curl http://localhost/index.html

welcome to apache server


http://服务器ip/test.php

wKiom1nfi6ORP8U6AAFFA2PazDg957.jpg-wh_50


netstat -tuplna | grep httpd

tcp        0      0 :::80                       :::*                        LISTEN      16796/httpd         

tcp        0      0 :::443                      :::*                        LISTEN      16796/httpd   

      

netstat -tuplna | grep mysqld

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17003/mysqld


ps -aux | grep httpd

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     16796  0.0  1.3 313176 13284 ?        Ss   22:58   0:00 /usr/sbin/httpd

apache   16798  0.0  0.6 313176  6924 ?        S    22:58   0:00 /usr/sbin/httpd


ps -aux | grep mysqld

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     16901  0.0  0.1 108188  1596 pts/3    S    22:58   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

mysql    17003  0.0  3.1 367516 32380 pts/3    Sl   22:58   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

root     27873  0.0  0.0 103324   888 pts/5    S+   23:19   0:00 grep mysqld



mysqladmin -uroot password 数据库密码

mysql -uroot -p数据库密码


mysql> create database cacti;  创建数据库

mysql> grant all privileges on  cacti.*to  cacti@localhost identified by 'cacti'; 授权用户保留root最高权限

mysql> select host,user from mysql.user; 查看用户以及权限

| localhost | cacti |

mysql> flush privileges; 刷新权限


mysql -ucacti -pcacti   查看授权用户是否可以登入数据库

mysql> show databases;

| cacti              |


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 

cd rrdtool-1.3.8

./configure --prefix=/usr/local/rrdtool  && make && make install 


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

cd cacti-spine-0.8.8a

./configure  --prefix=/usr/local/spine  && make && make install


mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql 导入sql文件

mysql -ucacti -pcacti 

mysql> show databases; 

| cacti              |


cp -pv   /var/www/html/cacti/include/config.php   /var/www/html/cacti/include/config.php.bak

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

$database_username = "cacti";  授权用户

$database_password = "cacti";  授权用户密码


cp -pv /var/www/html/cacti/include/global.php  /var/www/html/cacti/include/global.php.bak

vim /var/www/html/cacti/include/global.php 

$database_username = "cacti"; 授权用户

$database_password = "cacti"; 授权用户密码


crontab   -e             

*/5 * * * *    root  /bin/php   /var/www/html/cacti/poller.php


cp  -pv  /usr/local/spine/etc/spine.conf.dist /etc/spine.conf  /usr/local/spine/etc/spine.conf.dist /etc/spine.conf.bak

vim /etc/spine.conf 

DB_User       cacti  授权用户

DB_Pass       cacti  授权用户密码


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


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


vim  /etc/php.ini

找到 ;date.timezone =

改为 date.timezone = Asia/shanghai


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


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


120148262.png


windows客户端配置

cmd-services.msc-snmp Service

101956333.png


101956361.png


101956383.png

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

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


102339334.png


102505945.png


linux客户端配置

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

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