CACTI for LINUX安裝SOPphp
前言: html
Cacti是一套基於PHP,MySQL,SNMP及RRDTool開發的網絡流量監測圖形分析工具。它經過snmpget來獲取數據,使用RRDtool繪畫圖形,其功能相當完善,界面友好。Cacti最初是基於Linux的,但若是你對LINUX瞭解很少,好比像我一樣,那麼你最好不要使用Cacti for Linux,天然CactiEZ例外,因為即便你在Linux上能夠按安裝步驟安裝,安裝中出現的任何問題,哪怕它再小,也會讓你備受折磨,因此使用CactiEZ吧,或者Cacti for Windows也行。另外如下安裝方法,只保證在Redhat Desktop 9可行,在後面會說起緣由。mysql
準備工做:sql
Linux平臺:CentOS6.5shell
PHP+MySQL+SNMP:CentOS6.5自帶安裝包數據庫
Cacti:cacti-0.8.7e.tar.gzapache
Rrdtool:rrdtool-1.3.8-10.el6.i686瀏覽器
rrdtool-perl-1.3.8-10.el6.i686安全
Samba或vsftp:便於安裝過程中上傳文件,我使用的是sambabash
直接yum –y install lftp
Yum:不少軟件使用yum安裝,事先配置好yum源會方便不少
步驟:
安裝系統
為你的監控電腦安裝Linux操做系統,在安裝過程中有詢問須要安裝那些軟件包,個人建議全選,因為PHP+MySQL+SNMP除了幾個安裝包外,還有十幾個Installing package for dependencies,漏選一個都麻煩,並且,你會在乎硬盤多耗兩G空間?!因此,全選吧。若是你安裝的不是Redhat Desktop 9,好比Linux4.0或Linux 5.0,那麼你須要在安裝的過程當中將SELinux(Security-EnhancedLinux)選爲disable,雖然SELinux可以在必定程度上保證系統的安全,但它對於進程只賦予最小的權限,會致使在安裝後RRDtool調運拒絕,而沒法正常運行出圖。
架設PHP+MySQL+SNMP平臺
搭建LAMP環境環境
若是你按我上面說的,在安裝Linux的過程當中勾選了所有軟件包,那麼你如今會輕鬆不少,若是你沒有的話,那麼你得找回Linux安裝盤,並使用yum -y install httpd mysql php mysql-serverphp-mysql net-snmp將其一一安裝,LAMP環境就搭建好了。
2.啓動服務
[root@cacti html]# /etc/init.d/httpd start
[root@cacti html]# /etc/init.d/mysqld start
[root@cacti html]# /etc/init.d/snmpd start
3.設置服務開機自啓動
[root@cacti ~]# chkconfig httpd on
[root@cacti ~]# chkconfig mysqld on
[root@cacti ~]# chkconfig snmpd on
固然你也能夠直接使用setup命令,在system services裏面直接勾選。
4.測試php、Mysql
在/var/www/html/內建立一個以下php.php文件測試php。
[root@cacti html]#vi php.php #插入內容以下
<?php
phpinfo();
?>
瀏覽器測試http://服務器IP/php.php,若是能看到PHP信息則PHP環境搭建好了。
測試Mysql:打mysql命令能看到mysql>提示符就好了。
安裝RRDtool
若是你使用的是.rpm安裝包,那麼按如下方式安裝
[root@cacti ~]# yum install libart_lgpl.i386libart_lgpl-devel.i386
[root@cacti ~]#
rpm -ivh rrdtool-1.3.8-10.el6.i686rrdtool-perl-1.3.8-10.el6.i686
若是使用的是.tar.gz或者.tar.tar安裝包,使用如下方式安裝
[root@cacti ~]# tar -zxvf rrdtool-1.2.25.tar.tar
[root@cacti ~]# cd rrdtool-1.2.25
[root@cacti ~]# ./configure-prefix=/usr/local/rrdtool
[root@cacti ~]# make
[root@cacti ~]# make install
配置mysql cacti數據庫
建立一個執行監控用的用戶cactiuser
[root@ cacti ~]# useradd –p 你的密碼-s /sbin/bash cactiuser
-p指定密碼 –s指定登陸shell
而後進入mysql配置cacti數據庫
mysql>create database cactidb; #建立database
Query OK, 1 row affected (0.00 sec)
mysql>grant all on cactidb.* to root; #受權root用戶全部權限
Query OK, 0 rows affected (0.01 sec)
mysql>grant all on cactidb.* to root@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql>grant all on cactidb.* to cactiuser; #受權cactiuser
Query OK, 0 rows affected (0.00 sec)
mysql>grant all on cactidb.* to cactiuser@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql>set password for cactiuser@localhost=password(’你的密碼’);
Query OK, 0 rows affected (0.00 sec)
mysql>exit
安裝配置Cacti
[root@cacti tasks]# tar -xzvf cacti-0.8.7b
#解壓cacti-0.8.7b ;
[root@cacti tasks]# mv cacti-0.8.7b/var/www/html/cacti
#移動cacti文件夾到/var/www/html 目錄並更名cacti;
[root@cacti cacti]# cd /var/www/html/cacti/
#進入cacti目錄;
[root@cacti cacti]# mysql -u root -pcactidb<cacti.sql
#執行cacti.sql語句並導入到cactidb數據庫中;
編輯配置文件,具體根據實際狀況:
[root@cacti cacti]#vi /var/www/cacti/include/config.php
$database_type = 「mysql」;
$database_default = 「cactidb」;
$database_hostname = 「localhost」;
$database_username = 「cactiuser」;
$database_password = 「你的密碼」;
爲cactiuser用戶加入數據更新,5分鐘取一次。
[root@cacti cacti]#crontab –u cactiuser –e
插入如下內容並保存
*/5 * * * * php -f /var/www/html/cacti/poller.php>/dev/null 2>&1
注意用戶權限,若是是root用戶就直接crontab –e 。
進入cacti頁面進行初始化安裝。
http://服務器IP/cacti 若是沒法訪問提示沒有權限,請查看cacti文件夾是否賦予apache用戶和組權限,由於默認訪問cacti服務器的用戶爲apache。
RRDTool根據你安裝的方式不一樣,RRDTool Binary Path可能須要更改,否則可能會出現RRDTOOL沒法找到的現象。
初始用戶名admin 密碼admin
初次要更改密碼:
進入初始頁面,沒有添加模板以前cacti頁面只有console 和graphs兩個選項。
安裝插件
但在安裝插件時,必須先安裝cacti的一個patch--Plugin Architecture
安裝cacti-plugin-arch:
下載地址:http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7g-PA-v2.8.tar.gz
[root@cacti tasks]#tar -zxvf cacti-plugin-arch.tar.gz
[root@cacti tasks]#cp -a cacti-plugin-arch /var/www/html/cacti/
[root@cacti tasks]#cd /var/www/html/cacti/
[root@cacti cacti]#cp cacti-plugin-0.8.7b-PA-v2.1.diff /var/www/html/cacti/
[root@cacti cacti]#patch -p1 -N <cacti-plugin-0.8.7b-PA-v2.1.diff
編輯include/global.php 文件:
[root@cacti cacti]#vi include/global.php
在 $plugins = array(); 下面加上:
$plugins[] = ‘thold’;
$plugins[] = ‘monitor’; //若是安裝monitor的話
保存便可。
注意:有些插件默認不顯示在頁面上,須要在user managerment裏將ViewThresholds或View minitore選擇上。
具體安裝過程以下:
#wget http://cactiusers.org/downloads/cacti-plugin-arch.gzip
tar -zvxf cacti-plugin-arch.tar.gz
cd cacti-plugin-arch
cp cacti-plugin-0.8.7b-PA-v2.1.diff /var/www/html/cacti
cd /var/www/html/cacti
sudo patch -p1 -N < cacti-plugin-0.8.7b-PA-v2.1.diff
#wget http://cactiusers.org/downloads/thold.tar.gz
tar -zvxf thold-0.3.9.tar.gz
chown -R root:root thold
mv thold /var/www/html/cacti/plugins/
#wget http://cactiusers.org/downloads/monitor.tar.gz
tar -zvxf monitor-0.8.2.tar.gz
chown -R root:root monitor
mv monitor /var/www/html/cacti/plugins/
#wget http://cactiusers.org/downloads/settings.tar.gz
tar -zvxf settings-0.5.tar.gz
chown -R root:root settings
mv settings /var/www/html/cacti/plugins/
#wget http://cactiusers.org/downloads/update.tar.gz
tar -zvxf update-0.4.tar.gz
chown -R root:root update
mv update /var/www/html/cacti/plugins/
vi /var/www/html/cacti/include/config.php
/* Default session name – Session name must containalpha characters */
#$cacti_session_name = "Cacti";
#在此處增長下面內容
$plugins = array();
$plugins[] = ‘thold’;
$plugins[] = ‘monitor’;
$plugins[] = ‘settings’;
$plugins[] = ‘update’;
?>
亦可在include/global.php 文件中添加,做用是同樣的。