Cacti搭建
1、原理
Cacti是在大型網絡中較常見的性能檢測軟件,可對CPU負載、內存佔用率、運行進程數、磁盤空間、網卡流量等各類數據信息的檢測。Cacti自己只是基於PHP語言編寫的一個管理套件,須要使用Net-SNMP工具採集檢測數據,並結合RRDtool(Round Robin Database Tool,輪詢數據庫工具)記錄數據及繪製圖片經過WEB頁面展示給管理員用戶。
2、Cacti安裝_服務端
一、安裝依賴包
[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
二、修改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
三、安裝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
四、修改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
五、安裝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
六、建立數據庫
[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>
七、修改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";
?>
九、收集數據
每五分鐘生成一個監控圖表。
[root@localhost] # crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
十、Cacti_web 設置
3、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
4、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會顯示詳細的報錯信息。)