cacti简介:
cacti 是用 php 语言实现的一个软件,它的主要功能是用 snmp 服务获取数据, snmp 需要的变量数据是通过读取 mysql 数据库得到,
然后用 rrdtool 储存和更新数据,当用户需要查看数据的时候用 rrdtool 生成图表呈现给用户。rrdtool 对数据的更新和存储就是对 rrd
文件的处理, rrd 文件是大小固定的档案文件,它能够存储的数据笔数在创建时就已经定义。
1 . snmp 用来收集数据;
2 . rrdtool 用来存储数据和生成图表;
3 . mysql 用来配合 PHP 程序存储一些变量数据并对变量数据进行调用。

所需软件支持:
net-snmp mysql apache php ( gd ) rrdtool cacti spine cacti-plugin(0.8.8以上不需要) cacti 运行环境需要 php + mysql + rrdtool 以及 snmp 工具的支持。
软件安装
-
[root@vm1 ~]# yum install httpd mysql mysql-server mysql-devel php php-mysql php-snmp \
-
net-snmp net-snmp-utils net-snmp-libs net-snmp-devel libart_lgpl-devel libpng-devel \
-
freetype-devel cairo-devel pango-devel gcc -y
-
[root@vm1 ~]# rpm -qa | grep php
-
php-5.3.3-22.el6.x86_64
-
[root@vm1 ~]# yum localinstall php-snmp-5.3.3-22.el6.x86_64.rpm -y (与php版本一致)
-
[root@vm1 ~]# /etc/init.d/mysqld start //初始化数据库
-
[root@vm1 ~]# /etc/init.d/httpd start
-
建议修改 /etc/httpd/conf/httpd.conf ServerName yourip:80
可以避免出现开启服务时的警告: httpd:httpd: apr_sockaddr_info_get() failed for vm1.example.com
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
配置snmp
-
vi /etc/snmp/snmpd.conf
-
#com2sec notConfigUser default public
-
com2sec local localhost public
-
com2sec nicknetwork 192.168.0.0/24 public
-
#group notConfigGroup v1 notConfigUser
-
#group notConfigGroup v2c notConfigUser
-
group MyRWGroup v1 local
-
group MyRWGroup v2c local
-
group MyRWGroup usm local
-
group MyROGroup v1 mynetwork
-
group MyROGroup v2c mynetwork
-
group MyROGroup usm mynetwork
-
view systemview included .1.3.6.1.2.1.1
-
view systemview included .1.3.6.1.2.1.25.1.1
-
view all included .1 80
-
#access notConfigGroup "" any noauth exact systemview none none
-
access MyROGroup "" any noauth exact all none none
-
access MyRWGroup "" any noauth exact all all none
-
syslocation RHEL6.4
-
syscontact Root <root@local>
-
disk / 10000 打开
[root@vm1 ~]# /etc/init.d/snmpd start
现在来测试一下snmp是否正确安装
[root@vm1 ~]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.201 = INTEGER: 2 看到主机ip表明一切OK!
关于snmp的安装和配置可以参考:http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/mrtg_config_step_3.php
安装rrdtool
-
tar zxf rrdtool-1.4.4.tar.gz
-
cd rrdtool-1.4.4
-
./configure
-
make && make install
-
ln -s /opt/rrdtool-1.4.4/bin/rrdtool /usr/local/bin/
-
在configure和make的时候可能会出错 解决办法:yum install libxml* perl-ExtUtils-Embed -y
安装cacti
-
tar zxf cacti-0.8.8b.tar.gz -C /var/www/html 等下直接用web访问cacti
-
cd /var/www/html
-
mv cacti-0.8.8b/ cacti
-
useradd cacti
-
cd cacti
-
chown -R cacti rra/ log/
-
mysqladmin create cact 创建cacti库i
-
mysql cacti < cacti.sql
-
mysql 到数据库里去对cacti进行设置
-
mysql> grant all on cacti.* to cacti@localhost identified by ‘cacti‘;
-
mysql> flush privileges;
-
mysql>quit
-
vi include/config.php
-
$database_type = "mysql";
-
$database_default = "cacti";
-
$database_hostname = "localhost";
-
$database_username = "cacti";
-
$database_password = "cacti";
-
$database_port = "3306";
-
$database_ssl = false;
-
$url_path = "/cacti/";
-
$cacti_session_name = "Cacti";
-
crontab -u cacti -e
*/5 * * * * php /var/www/html/cacti/poller.php //以cacti身份运行
关于cacti的安装也可以参考官方步骤:http://docs.cacti.net/manual:088:1_installation.1_install_unix.5_install_and_configure_cacti
安装spine(加速插件)
-
yum install automake libtool -y
-
tar zxf cacti-spine-0.8.8b.tar.gz
-
cd cacti-spine-0.8.8b
-
aclocal
-
libtoolize --force
-
autoheader
-
autoconf
-
automake
-
./configure
-
make && make install
-
cd /usr/local/spine/etc
-
cp spine.conf.dist spine.conf
-
vi spine.conf
-
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
DB_PreG 1
-
cacti 0.8.8版本以后可以不用装plugin,所以我们直接装以下插件:
-
tar -zxf monitor-0.8.2.tar.gz -C /var/www/html/cacti/plugins/
-
tar -zxf thold-0.4.2.tar.gz -C /var/www/html/cacti/plugins/
-
tar -zxf settings-0.5.tar.g z -C /var/www/html/cacti/plugins/
OK,现在我们可以进入到web界面去设置cacti
进入cacti之后,首先设置安装好的spine
Console->Setting->Paths

save之后Poller->Poller Type选择spine最后save
还有monitor thold需要添加
Console->Plugin Management 安装插件
还有其他的一些设置就见仁见智了,So~现在就去定制自己的吧!
在cacti里面我碰到了一个小问题就是,在Graphs中,rrdtool可以绘图,但是表中有乱码,检查后发现系统没有安装任何字体,如果你的问题跟我一样
解决方法:yum install -y cjkuni-uming-fonts 乱码解决!
最后,奉上几张cacti绘制出来的炫酷图

监控—Cacti
原文:http://blog.chinaunix.net/uid-28841896-id-4670165.html