天天看點

centos 環境下cacti安裝部署

Cacti 研究了有段時間了,中間遇到點問題,最終還是搭建起來了.這裡記下自己安裝的過程,以免以後忘記還要重新檢視資料。同時也提供給感興趣的朋友!

一.Cacti的介紹

三.Cacti工作原理

四.名詞解釋

1. RRDtools

使用RRDtool來存儲和處理通過SNMP收集到的資料開始。這些資料很可能是某個網絡或計算機接收或發送的位元組數(比特數)。它也可以用來顯示潮水的波浪、陽光射線、電力消耗、展會的參觀人員、機場附近的噪音等級、你喜歡的度假區的溫度、電冰箱的溫度、以及任何你可以想象的東西。

你最需要一個度量資料,以及能夠提供這些資料給RRDtool的感應器就可以了。RRDtool會讓你建立資料庫、存儲資料、提取資料、建立用于在Web浏覽器中顯示的PNG格式的圖像。這些PNG圖像以來于你收集的資料,它可以是網絡平均使用率、峰值。

2.RRD

Round Robin Database環狀資料庫

3.SNMP

snmp(Simple Network Management Protocal, 簡單網絡管理協定)在架構體系的監控子系統中将扮演重要角色。大體上,其基本原理是,在每一個被監控的主機或節點上 (如交換機)都運作了一個 agent,用來收集這個節點的所有相關的資訊,同時監聽 snmp 的 port,也就是 UDP 161,并從這個端口接收來自監控主機的指令(查詢和設定)。  

如果使用 RHEL5 的 net-snmp,那麼被監控主機需要安裝 net-snmp(包含了 snmpd 這個 agent),而監控端需要安裝 net-snmp-utils。如果自行編譯,需要 beecrypt(libbeecrypt)和 elf(libraryelf)的庫。

每一個 agent 維護一個樹形的資料庫,稱為 MID(Management Information Base, 管理資訊庫),其每一個節點稱為 Object Identifier(OID),這在使用 net-snmp-utils 的工具時會用到。這些節點就表示了這台主機系統的裝置如網卡的接口描述(eth0 等)、實體位址(MAC)、接口類型等,也可能是系統的資訊,或者是需要監控的程序等...

五.應用場景極其優點

常見應用

伺服器資源:CPU、記憶體、磁盤、程序、連接配接數等

伺服器類型:WEB、Mail、FTP、資料庫、中間件

網絡接口:流量、轉發速度、丢包率

裝置運作狀态:風扇、電源、溫度

機房運作環境:電流、電壓、溫濕度

優點:

開源性;

界面 相對其它監控軟體漂亮,能劃出漂亮的資料圖;

跨平台監控;

可擴充性

開始安裝過程:

cacti 需要LAMP環境的支援:

 tar zxvf   httpd-2.0.64.tar.gz

 cd httpd-2.0.64

./configure --prefix=/usr/local/apache2/ --enable-so --enable-rewrite

make && make insatall

 2.安裝mysql

tar zxvf  mysql-5.5.22-linux2.6-i686.tar.gz

cp -ra mysql-5.5.22-linux2.6-i686  /usr/lcoa/mysql

useradd mysql

cd /usr/local/mysql

cp support-files/my-medium.cnf support-files/my.cnf

chown -R mysql.mysql /usr/local/mysql

scripts/mysql_install_db --user=mysql (初始化資料庫)

 cp support-files/mysql.server /etc/init.d/mysql

 ln –s /usr/local/mysql/bin/* /usr/local/bin/

/usr/local/mysql/bin/mysqld_safe --user=mysql  (啟動資料庫)

 因為cacti需要很多php支援,建議yum install php

或者

 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd --enable-gd-native-ttf  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --enable-xml --enable-mbstring --enable-sockets

make && make install

cp php.ini-development /usr/local/lib/php.ini

ln –s /usr/local/php/bin/* /usr/local/bin/

# vi /usr/local/apache/conf/httpd.conf

查找AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

在其下加入

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

修改DirectoryIndex 行,添加index.php

修改為DirectoryIndex index.php index.html index.html.var

# vi /usr/local/apache/htdocs/test.php

添加以下行:

<?php

Phpinfo();

?>

wq 儲存退出。

# /usr/local/apache/bin/apachectl restart

在浏覽器中輸入:http://www.yourdomain.com/test.php 進行測試。

 然後配置apache支援php

RRDtools 同樣需要很多庫檔案的支援,隻需要在安裝作業系統的時候将開發軟體包都裝上就可以了。

tar zxf rrdtool-1.4.4.tar.gz

cd rrdtool-1.4.4

./configure --prefix=/uar/local/rrdtool --disable-tcl

//完成後建立符号連接配接

ln –s /usr/local/rrdtool/bin/* /usr/local/bin/

5.安裝net-snmp

建議 yum install net-snmp

vim /etc/snmp/snmpd.conf

修改如下内容:

#com2sec notConfigUser  default       public

修改為:

com2sec notConfigUser  127.0.0.1       public(同時去掉#)

#access  notConfigGroup ""      any       noauth    exact  systemview none none

access  notConfigGroup ""      any       noauth    exact  all  none none

#view all    included  .1 這一行去掉注釋#

service snmpd start

OK! 

 6.安裝cacti

useradd cacti

tar zxvf  cacti-0.8.7i.tar.gz

cp -ra cacti-0.87i /usr/local/apache2/htdocs/cacti

chown -R cacti.cacti /usr/loca/apache2/htdocs/cacti

 vi /usr/local/apache/htdocs/cacti/include/config.php

 修改如下:

<a href="http://blog.51cto.com/attachment/201204/114319446.png" target="_blank"></a>

  7.資料庫配置

  mysql -u root

create database cacti;

flush priviledges;

exit;

mysqladmin -u root password("mysql")

mysql -uroot -pmysql cacti &lt; /usr/local/apache/htdocs/cacti/cacti.sql

Chmod 777 /usr/local/apache/htdocs/cacti/log

Chmod 777 /usr/local/apache/htdocs/cacti/rra

8. 完成cacti 的安裝

在浏覽器中輸入:http://ip/cacti/

預設使用者名:admin 密碼:admin

設定cacti用到的指令的絕對路徑 

snmpwalk Binary Path       /usr/local/ bin/snmpwalk 

snmpget Binary Path       /usr/local/ bin/snmpget 

RRDTool Binary Path       /usr/local/ bin/rrdtool 

PHP Binary Path             /usr/local/bin/php 

Cacti Log File Path       /usr/local/apache/htdocs/cacti/log/cacti.log 

Cactid Poller File Path    /usr/local/cactid/cactid

<a href="http://img1.51cto.com/attachment/201001/19/765312_1263916510GAXh.jpg"></a>

<a href="http://img1.51cto.com/attachment/201001/19/765312_1263916511qMbb.jpg"></a>

9.安裝問題

我在安裝過程中,也就是執行第8步驟的時候遇到很多warn 資訊,比如warn date:

網上有很多解決方案,但是好像我在使用的時候怎麼改沒奏效。

經過摸索,我發現其實隻需更改一個檔案就可以了:

vim /usr/local/apache2/htdocs/cacti/lib/functions.php

在首行加入如下時區定義:

date_default_timezone_set('Asia/Shanghai');

重新開機apache

重新打開浏覽器通路即可!

大功告成!!!

    本文轉自marbury 51CTO部落格,原文連結:http://blog.51cto.com/magic3/822991,如需轉載請自行聯系原作者