Cactirrdtool简介

一、概述
Linux
下用的最多的是 MRTG 的性能监视, MRTG 配置比较简单, MRTG 的确是非常好的东东,但我认为它毕竟已经是一套很旧的软件了,其作者在多年前就已经开发了 RRDTool 代替该软件,现在已经发展得很成熟。既然有更好的选择,为什么我们还要用 MRTG 呢?
简单的说, rrdtool 就是一个强大的绘图的引擎,很多语言都可以调用 rrdtool 绘图。
整个系统的架构是这样的:
基于 SNMP 协议,被监控端是服务器,或一些网络设备,
网络管理工作站,采用 Linux( Freebsd) 操作系统,并且安装 Net-SNMP 工具,使用 RRDTOOL 采集数据,存储数据,并用 Cacti 调用 rrdtool 显示出来。
CACTI
采用 PHP 编写,基于 B/S 结构。
二、介绍
MRTG
的优点:简单、易上手,基本安装完了之后只要更改一下配置文件即可。
缺点:
1
、使用文本式的数据库,数据不能重复使用;
2
、只能按日、周、月、年来查看数据;
3
、只能画两个 DS (一条线、一个块);
4
、每取一次数据即需要绘图一次,浪费系统资源;
5
、无管理功能;

rrdtool
的优点:
1
、使用 rrd 存储格式,数据能重复使用,比如我可以将一个 rrd 文件中的数据与另一个 rrd 文件中的数据相加。
2
、可以定义任意时间段画图,即你可以画出一张半年以来的数据的图,也可以画出一张半小时以来的图。
3
、能画任意个 DS
4
CDEF 让你能任意摆弄数据。

缺点:
1
rrdtool 的作用只是存储数据和画图,它没有 mrtg 中集成的数据采集功能;
2
、在命令行的使用非常复杂,参数极多。
3
、无管理功能。

简单的说, rrdtool 就是一个强大的绘图的引擎。

由于其非常复杂的命令,对用户非常不友好,我一度想自己用 php 写一套系统。幸运的是,半年前我找到了 cacti www.cacti.net) 。对该工具我只有一个字形容: “great
cacti 
其实是一套 php 程序,它运用 snmpget 采集数据,使用 rrdtool 绘图。它的界面非常漂亮,能让你根本无需明白 rrdtool 的参数能轻易的绘出漂亮的图形。更难能可贵的是,它提供了强大的数据管理和用户管理功能,一张图是属于一个 host 的,每一个 host 又可以挂载到一个树状的结构上。用户的管理上,作为一个开源软件,它居然做到为指定一个用户能查看的 host 、甚至每一张图,还可以与 LDAP 结合进行用户的验证!我不由得佩服作者考虑的周到! Cacti 还提供自己增加模板的功能,让你添加自己的 snmp_query script !可以说, cacti rrdtool 的所有 缺点 ”  都补足了!
cacti 安装环境:
操作系统:Redhat Linux AS5.4
安装方式:全新安装并以文本方式与自定义安装软件
内核版本:2.6.18-164.el5
Apache:httpd-2.2.3-31.el5
PHP:php-5.1.6-23.2.el5_3
Mysql:mysql-5.0.77-3.el5
Net-snmp:net-snmp-5.3.2.2-7.el5
RRDtool:rrdtool-1.2.23-1.el5.rf
Cacti:cacti-0.8.7e.tar.gz
 
Cacti架构图:
数据实现层              apache          php     
--------------------------------------------------------------------------------------------------
数据存储层               mysql           rrdtool
--------------------------------------------------------------------------------------------------
数据采集层              net-snmp        script
 
Cacti工作原理图:
 

 
全新linux系统安装
以文本方式并自定义安装软件
……………………省略…………………….
 
去掉所有打勾
然后把红色标记移到  development tools
 

接下来按F2,跳出详细菜单
选择OK就行了,
 

同样步骤把红色标记移到MySQL Database,按F2.除了默认打勾还要把以下三个一起打勾
Mod_auth_mysql mysql-devel  php-mysql
 

 
接下来同样步骤选择 web server,去掉默认 squid tux webalizer的安装
 
 

接下来选择system tools ,然后按回车,再选中它按F2,去掉所有默认安装
只留Net-snmp-libs 与net-snmp-utils连个打上勾
 
安装完后重启
选择firewall configuration,禁用selinux

开放http-80 端口

启动结束进入系统
 
=====================================================================
(大家也可以通过把yum源更换到光盘或centos资源库,具体可以参考我另外一篇bolg。 http://viong.blog.51cto.com/844766/278402
先yum mysql  apache    php
yum -y install mysql mysql-server php-mysql httpd php
再yum需要用到的包
yum -y install php-pdo lm_sensors net-snmp php-snmp net-snmp-utils perl-Net-Daemon perl-PlRPC perl-DBI perl-DBD-MySQL
 =====================================================================
设置 mysql Apache snmp 开机自动启动
 
[root@cacti-qmail soft]# chkconfig mysqld on
[root@cacti-qmail soft]# chkconfig httpd on
[root@cacti-qmail soft]# chkconfig snmpd on
[root@cacti-qmail soft]# service mysqld start
[root@cacti-qmail soft]# service httpd start
[root@cacti-qmail soft]# service snmpd start
PHP配置(默认已都激活)
激活PHP扩展
/ etc/php.ini
Extension_dir=”usr/lib/php/modules”
 
激活mysql扩展
/etc/php.d/mysql.ini
Extension=mysql.so
Apache配置(默认已支持)
配置支持PHP:/etc/httpd/conf.d/php.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
AddType text/html .php
DirectoryIndex index.php
Mysql配置
为mysql数据库root账号设置密码
[root@cacti-qmail soft]#  mysqladmin --user=root password viong0613
[root@cacti-qmail soft]#  mysqladmin --user=root --password reload
Enter password:  输入刚设置密码,检验是否正确
Rrdtool安装
[root@cacti-qmail soft]#  ll
总计 1100
-rw-r--r-- 1 root root    49815 02-22 22:18 perl-rrdtool-1.2.23-1.el5.rf.i386.rpm
-rw-r--r-- 1 root root 955176 02-22 21:53  rrdtool-1.2.23-1.el5.rf.i386.rpm
-rw-r--r-- 1 root root     5542 02-22 22:01 rrdtool-devel-1.2.23-1.el5.rf.i386.rpm
-rw-r--r-- 1 root root    65566 2004-05-19 rzsz-3.48.tar.gz
drwxrwxr-x 2 10127 wheel    4096 02-24 01:46 src
[root@cacti-qmail soft]# rpm –ivh perl-rrdtool-1.2.23-1.el5.rf.i386.rpm  rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-devel-1.2.23-1.el5.rf.i386.rpm
warning: perl-rrdtool-1.2.23-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing...                 ########################################### [100%]
   1:rrdtool                ########################################### [ 33%]
   2:perl-rrdtool           ########################################### [ 67%]
   3:rrdtool-devel          ########################################### [100%]
Cacti安装
[root@cacti-qmail soft]# wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz
[root@cacti-qmail soft]# tar -zxvf cacti-0.8.7e.tar.gz
[root@cacti-qmail soft]# mv cacti-0.8.7e /var/www/html/cacti
[root@cacti-qmail soft]# chown -R root.root /var/www/html/cacti/
修改 cacti 文件目录的拥有者
在mysql建立cacti数据库环境
[root@cacti-qmail soft]# mysql -u root -h 127.0.0.1 -p
Enter password:
mysql> create database cacti;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on cacti.* to viong@localhost identified by 'viong0623';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;      
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit;
Bye
到cacti根目录下把cacti.sql中的数据导入到数据库cacti中
[root@cacti-qmail cacti]# mysql -uroot -pviong0613 cacti<cacti.sql
配置mysql连接参数
[root@cacti-qmail cacti]# vi /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 = " viong";
$database_password = " viong0623";
$database_port = "3306";
 
[root@cacti-qmail cacti]# vi /var/www/html/cacti/include/global.php
 
/* Default database settings*/
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = " viong";
$database_password = " viong0623";
$database_port = "3306";
 
cacti-plugins插件安装
[root@cacti-qmail soft]#unzip cacti-plugin-0.8.7e-PA-v2.6.zip
[root@cacti-qmail soft]# cd cacti-plugin-arch/
[root@cacti-qmail cacti-plugin-arch]# ll
总计 124
-rw-r--r-- 1 root root 93070 11-22 13:50 cacti-plugin-0.8.7e-PA-v2.6.diff
drwxr-xr-x 5 root root 4096 11-22 13:03 files-0.8.7e
-rw-rw-rw- 1 root root 15237 2006-11-10 LICENSE
-rw-rw-rw- 1 root root 2037 2007-11-06 pa.sql
-rw-rw-rw- 1 root root 1230 11-22 13:50 Readme.txt
 
[root@cacti-qmail cacti-plugin-arch]# cp cacti-plugin-0.8.7e-PA-v2.6.diff /var/www/html/cacti/
[root@cacti-qmail cacti-plugin-arch]# cp pa.sql /var/www/html/cacti/
root@cacti-qmail cacti-plugin-arch]# cd /var/www/html/cacti/
[root@cacti-qmail cacti]# patch -p1 -N <cacti-plugin-0.8.7e-PA-v2.6.diff
[root@cacti-qmail cacti]# mysql -uroot -pviong0613 cacti<pa.sql
[root@cacti-qmail cacti]# vi include/global.php
修改一下参数
$config['url_path'] = '/cacti/';
保存退出
建立任务调度
[root@cacti-qmail cacti]#  crontab –e
输入以下内容,代表每5分钟来执行后面PHP解析内容,把显示信息重定向到空的路径
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
[root@cacti-qmail cacti]#  crontab -l
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
 
也可手工跑一次 :/usr/bin/php /var/www/html/cacti/poller.php
 
Cacti的web初始化
 
在浏览器输入 http://192.168.15.67/cacti/登陆cacti
 

   

 

  

被监控主机snmp文件设置
Linux
 
被监控主机需要配置snmp.
 
 #vi /etc/snmp/snmpd.conf
1更改
 com2sec notConfigUser default public
改为
com2sec notConfigUser 127.0.0.1 public
2、更改
access notConfigGroup "" any noauth exact  systemview none none
改为
access notConfigGroup "" any noauth exact  all none none
 
#view all included .1 80
将前面的 # 注释 去掉。 保存退出
 
如果还是无法抓到snmp数据包
用ps aux  |grep snmp 查看是否启动,如没有看到进程
输入/usr/local/sbin/snmpd -c /etc/snmp/snmpd.conf 启动snmp进程
 
 测试snmp是否正常
 #snmpwalk -c public -v 2c localhost
 
 #snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
 
IP-MIB::ipAdEntIfIndex.61.xxx.xxx.xxx = INTEGER: 2 IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1 IP-MIB::ipAdEntIfIndex.172.xxx.xxx.xxx = INTEGER: 3
 
也可以用snmpd -f -Le 命令查看当前有没有出什么错
 
Windows
需要安装snmp服务
开启---运行—appwiz.cpl 把管理和监视工具打上勾,然后点详细信息进去,勾起我们需要用的组件
 

 
安装好后,
运行—services.msc,点snmp server设置一下选项
 
 
 
小插曲:很感谢方老师制作了一个cacti视频教程,自己用cacti也几年时间了。为了加固自己的知识。把这些整理出来当备用,并附上方老师发给我的一系列的视频教程.下载看附件
开源网管软件Cacti系列视频讲座
(一)Cacti架构与应用示例     
 (二)Cacti安装与部署(上)      
(二)Cacti安装与部署(下)       
(三)Cacti设备管理与模板应用
(四)Cacti的多种数据采集方式 
 (五)Cacti插件架构与插件安装   
(六)Cacti高效轮询工具spine