Cacti 監控安裝
Cacti 安裝
Cacti是一套基于PHP,MySQL,SNMP及RRDTool開發的網絡流量監測圖形分析工具,可以監控主機的狀態及負載情況,Cacti是通過 snmpget來獲取數據,使用 RRDtool繪畫圖形,而且你完全不需要了解RRDtool復雜的參數。
一、安裝依賴環境包
yum install net-snmp net-snmp-utils net-snmp-devel httpd-devel mysql-devel mysql-server php php-mysql php-json php-pdo
yum install cairo-devel libxml2-devel pango pango-devel
二、配置Rrdtool、Cacti
1.安裝rrdtool
[root@localhost cacti-nagios]# tar zxvf rrdtool-1.4.5.tar.gz
[root@localhost cacti-nagios]# cd rrdtool-1.4.5
[root@localhost rrdtool-1.4.5]# ./configure --prefix=/usr/local/rrdtool
[root@localhost rrdtool-1.4.5]# make && make install
[root@localhost rrdtool-1.4.5]# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
2.解壓 cacti
[root@localhost cacti-nagios]# tar zxvf cacti-0.8.8a.tar.gz
[root@localhost cacti-nagios]# mv cacti-0.8.8a /var/www/html/cacti
3.創建數據庫并導入sql
[root@localhost cacti-nagios]# mysql -uroot -ppassword
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cacti@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
[root@localhost cacti]# mysql -ucacti -ppassword --database cacti< /var/www/html/cacti/cacti.sql
配置完mysql后,我們需要設置cacti rra、log 目錄的權限,這里設置為777 :
chmod -R 777 /var/www/html/cacti/rra/
chmod -R 777 /var/www/html/cacti/log/
4.配置cacti
[root@localhost include]# pwd
/var/www/html/cacti/include
[root@localhost include]# vi global.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "password";
$database_port = "3306";
$database_ssl = false;
[root@localhost include]# vi config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "password";
$database_port = "3306";
$database_ssl = false;
5,配置抓圖任務
[root@localhost include]# crontab -e*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php
三、Error
通常做到這里,很多人還無法打開http://ip/cacti/install/index.php
為了讓大家少走些彎路,我將我遇到的一些錯誤總結一下
1.打開/etc/php.ini,修改時區并打開錯誤顯示
date.timezone = PRC
display_errors = On
2.如果顯示 /var/lib/php/session 沒有權限,要給與這個目錄cacti用戶權限,我后面還會寫一篇與nagios集成,所以這些我都設置為nagios用戶。
[root@localhost ~]# chown -R nagios:nagios /var/lib/php/session
[root@localhost ~]# chown -R nagios:nagios /var/www/html/cacti
[root@localhost ~]# vi httpd.conf
User nagios
Group nagios
DirectoryIndex index.html index.html.var index.php
AddType application/x-http-php .php
3.空白頁面大部分是因為權限,還有好多朋友配置時是因為少安裝了php-mysql,導致空白頁面,如果找不到favicon.ico,搜索這個文件,拷貝到/var/www/html/目錄下
4.關閉selinux,這個有時候會出現問題
[root@localhost ~]# vi /etc/selinux/config
SELINUX=disabled
四、安裝Cacti
瀏覽器打開 http://IP/cacti/install/index.php
默認用戶名密碼為admin/admin,登陸后需要重置
五、配置監控本機 1.設置本機SNMP(紅色為修改部分)
[root@localhost etc]# vi /etc/snmp/snmpd.conf
com2sec notConfigUser 127.0.0.1 public
access notConfigGroup "" any noauth exact all none none
view all included .1 80
[root@localhost etc]# service snmpd restart
停止 snmpd:[確定]
正在啟動 snmpd:[確定]
編輯localhost 模板
console->Devices->localhost ,選擇下snmp版本并配置團體名,默認是public,就可以直接監控了
大家有什么問題可以給我留言