LINUX Cacti 安裝SOP FOR CentOS6.5

CACTI for LINUX安裝SOP

前言:

Cacti是一套基於PHP,MySQL,SNMPRRDTool開發的網絡流量監測圖形分析工具。它通過snmpget來獲取數據,使用RRDtool繪畫圖形,其功能相當完善,界面友好。Cacti最初是基於Linux的,但如果你對LINUX瞭解不多,比如像我一樣,那麼你最好不要使用Cacti for Linux,自然CactiEZ例外,因為即使你在Linux上能夠按安裝步驟安裝,安裝中出現的任何問題,哪怕它再小,也會讓你備受折磨,所以使用CactiEZ吧,或者Cacti for Windows也行。另外以下安裝方法,只保證在Redhat Desktop 9可行,在後面會提及原因。

準備工作:

    Linux平臺:CentOS6.5

    PHP+MySQL+SNMPCentOS6.5帶安裝包

    Cacti:cacti-0.8.7e.tar.gz

    Rrdtoolrrdtool-1.3.8-10.el6.i686

rrdtool-perl-1.3.8-10.el6.i686

Sambavsftp:便於安裝過程中上傳文件,我使用的是samba

直接yum –y install lftp

    Yum:很多軟件使用yum安裝,事先配置好yum源會方便很多

步驟:

  • 安裝系統

為你的監控電腦安裝Linux操作系統,在安裝過程中有詢問需要安裝那些軟件包,個人建議全選,因為PHP+MySQL+SNMP除了幾個安裝包外,還有十幾個Installing  package for dependencies,漏選一個都麻煩,而且,你會在意硬盤多耗兩G空間?!所以,全選吧。如果你安裝的不是Redhat Desktop 9,比如Linux4.0Linux 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.測試phpMysql

在/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

d81e359cc6ff331a0e38543504d524c7.jpg

64b6d5913d1c35ee420db1c2931db6cb.jpg

63ee832364a96666e81fe109348d9d2c.jpg

RRDTool根據你安裝的方式不同,RRDTool Binary Path可能需要更改,不然可能會出現RRDTOOL無法找到的現象。

初始用戶名admin 密碼admin

初次要更改密碼:

d0b81cf51cc6756d298a05a6b6a57454.jpg

進入初始頁面,沒有添加模板之前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裏將ViewThresholdsView minitore選擇上。

9907ab0b052cdcbd90cd48f75b302953.jpg

具體安裝過程如下:

#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 文件中添加,作用是一樣的。

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章