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

nagios-3.4.1.tar.gz

nagios-plugins-1.4.16.tar.gz

rrdtool-1.3.8.tar.gz

1 先安装LAMP(yum安装)

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

2 服务设置开机启动

chkconfig  httpd on  

chkconfig  snmpd on  

chkconfig mysqld on

关闭 selinux

setenforce 0

3 安装cacti+nagios


tar zxvf cacti-0.8.7h.tar.gz

mv cacti-0.8.7h /var/www/html/cacti

tar zxvf rrdtool-1.3.8.tar.gz

mv rrdtool-1.3.8 /usr/local/rrdtool

cd /usr/local/rrdtool/

yum install pango-devel* cairo-devel* intltool

./configure

make make install

tar zxvf cacti-spine-0.8.7h.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 liguowei

mysqladmin -uroot -p create cacti

mysql -uroot -p cacti < cacti.sql


vi include/config.php

修改内容如下:

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "root";

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

$database_port = "3306";

$database_ssl = false;

vi include/global.php

修改内容如下:

/* Default database settings*/

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "root";

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

添加计划任务

vi /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 配置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  127.0.0.1   public   (ip为需要监控的主机的ip)

找到

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

做了一下改动后要,重启snmp

service snmpd restart

Stopping snmpd: [  OK  ]

Starting snmpd: [  OK  ]

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

Stopping crond: [  OK  ]

Starting crond: [  OK  ]

测试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客户端配置就完成了。


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