Cacti搭建
 
一、原理
     Cacti是在大型网络中较常见的性能检测软件,可对CPU负载、内存占用率、运行进程数、磁盘空间、网卡流量等各种数据信息的检测。Cacti本身只是基于PHP语言编写的一个管理套件,需要使用Net-SNMP工具采集检测数据,并结合RRDtool(Round Robin Database Tool,轮询数据库工具)记录数据及绘制图片通过WEB页面展现给管理员用户。
二、Cacti安装_服务端
1、安装依赖包
[root@localhost] # yum -y install httpd php php-mysql php-snmp mysql mysql-server perl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-devel ruby ruby-devel  lm_sensors
客户端安装
[root@localhost] # yum -y  net-snmp net-snmp-libs net-snmp-utils net-snmp-devel  lm_sensors
设置服务开机启动
[root@localhost] # chkconfig mysqld on
[root@localhost] # chkconfig httpd on
[root@localhost] # chkconfig snmpd on
 
2、修改apache配置
修改 apache 配置文件
[root@localhost] # vim /etc/httpd/conf/httpd.conf
#找到 DirectoryIndex index.html
修改为:
DirectoryIndex  index.php  index.html
启动 mysql 与 http 服务
[root@localhost] #  service httpd start
[root@localhost] #  service mysqld start
 
3、安装rrdtool
rrdtool-1.2.30-1.el5.wrl.x86_64.rpm
rrdtool-perl-1.4.5-1.el5.wrl.x86_64.rpm
rrdtool-ruby-1.3.9-1.el5.wrl.x86_64.rpm
 
4、修改snmp的设置
[root@localhost] #  vim /etc/snmp/snmp.conf
com2secnotConfigUser default public
改为:
com2secnotConfigUser 127.0.0.1 public    (这是监控本地,可以将127.0.0.1换成对应主机的IP)
access  notConfigGroup “”  any   noauth    exact  systemview  none none
改为:
Access notConfigGroup  “”  any noauth   exact   all none  none
#view all    included  .1         80
将前面的 # 注释去掉。
重新启动 snmp 服务
[root@localhost] #  service snmpd restart
 
5、安装Cacti
[root@localhost] # tar xzvf  cacti-0.8.7g.tar.gz -C /usr/local/src/
[root@localhost src] # mv cacti-0.8.7g/ var/www/html/cacti
 
6、创建数据库
[root@localhost html]# mysql -u root -p
mysql> create database cactidb default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cactidb.* to cactiuser@localhost identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
[root@localhost html]# mysql -u cactiuser -p cactidb < cacti/cacti.sql 
Enter password: 
[root@localhost html]# 
[root@localhost html]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| cactidb            | 
| mysql              | 
| test               | 
+--------------------+
4 rows in set (0.00 sec)
mysql> 
 
7、修改Cacti配置文件
[root@localhost html]# cd /var/www/html/cacti/
[root@localhost cacti]# vim include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "127.0.0.1";
$database_username = "cactiuser";
$database_password = "redaht";
$database_port = "3306";
$config [ 'url_path' ] = "/";
/* Default session name - Session name must contain alpha characters */
#$cacti_session_name = "Cacti";
?>
 
9、收集数据
每五分钟生成一个监控图表。
[root@localhost] # crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
 
10、Cacti_web 设置
    
三、Cacti客户端配置
[root@localhost] #  vim /etc/snmp/snmp.conf
com2secnotConfigUser default public
改为:
com2secnotConfigUser 127.0.0.1 public    (这是监控本地,可以将127.0.0.1换成对应主机的IP)
access  notConfigGroup “”  any   noauth    exact  systemview  none none
改为:
Access notConfigGroup  “”  any noauth   exact   all none  none
#view all    included  .1         80
将前面的 # 注释去掉。
重新启动 snmp 服务
[root@localhost] #  service snmpd restart
 
四、Cacti日常问题处理
查看数据是否搜集到,收集到数据才可以正常显示图像
rrdtool fetch ( .rrd文件) AVERAGE
 
 /usr/bin/snmpwalk -v 2c -c publicsvr 127.0.0.1 .1.3.6.1.2.1.25.2.3.1.5.3  命令更新未出图像的主机信息
 
 /usr/bin/php /var/www/html/cacti/poller.php --force 强制执行收集数据 (如不使用force时不显示数据,则使用force会显示详细的报错信息。)