Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

CentOS 源碼包完整搭建 Cacti 監控系統(上)

Cacti 是一套以 PHP、MySQL、SNMP 與 RRDTool 打造的网络流量圖形分析工具。它以 snmpget 取數、用 RRDtool 繪圖,你不必理解 RRDtool 繁瑣的參數就能畫出漂亮的曲線,同時還提供強大的資料與使用者管理:可指定每位使用者能看哪些樹狀結構、主機與圖表,也能串接 LDAP 驗證,模板更可自行擴充。

分工上,MySQL 配合 PHP 存放並讀取變數資料(主機名、IP、SNMP 團體名、埠號、模板資訊等);SNMP 抓到的實測值則不進 MySQL,而是寫入 RRDtool 產生的 rrd 檔。

架構與流程

CentOS 源碼包完整搭建 Cacti 監控系統(上)

CentOS 源碼包完整搭建 Cacti 監控系統(上)

實驗環境

系統:CentOS 5.4(64 位)
套件:mysql-5.5.17-linux2.6-x86_64.tar.gz、httpd-2.2.9.tar.gz、php-5.3.9.tar.gz、zlib-1.2.3.tar.gz、freetype-2.3.5.tar.gz、libpng-1.2.18.tar.gz、jpegsrc.v7.tar.gz、fontconfig-2.4.2.tar.gz、gd-2.0.28.tar.gz、libxml2-2.6.32.tar.gz、rrdtool-1.2.27.tar.gz、cacti-0.8.7i.tar.gz

一、安裝 MySQL

先檢查系統是否已有舊版,通常預設會安裝,有的話先移除再裝新版。

rpm -qa | grep mysql        # 查看是否已安裝
yum remove mysql            # CentOS 移除方式
rpm -e mysql                # RHEL 移除方式

接著解壓、就位、建立帳號與初始化:

tar -zxvf mysql-5.5.17-linux2.6-x86_64.tar.gz
mv mysql-5.5.17-linux2.6-x86_64 /usr/local/mysql
groupadd mysql
useradd -g mysql mysql
cp support-files/my-medium.cnf /etc/my.cnf

編輯 /etc/my.cnf,在 [mysqld] 段落補上 datadir:

[mysqld]
datadir = /usr/local/mysql/data
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data/
chgrp -R mysql .
bin/mysqld_safe --user=root &

沒有 error 就代表資料庫起來了。接著設為系統服務並加入環境變數:

cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
vi /etc/profile        # 加入 PATH=$PATH:/usr/local/mysql/bin
. /etc/profile

二、安裝 Apache

tar -zxvf httpd-2.2.9.tar.gz
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite
make
make install

在 /etc/rc.d/rc.local 加入 /usr/local/apache/bin/apachectl start 即可完成開機自啟。

三、安裝 PHP 與相依組件

先裝 zlib、freetype、libpng、jpeg,讓 PHP 支援 GD 庫(Cacti 的 WeatherMap 外掛需要較新的 GD)。各組件流程一致,以 zlib 為例:

tar -zxvf zlib-1.2.3.tar.gz
./configure --prefix=/usr/local/zlib
make && make install

libpng、freetype 依此類推。libjpeg 需先建目錄再編譯:

mkdir -p /usr/local/libjpeg/{bin,lib,man/man1}
./configure --prefix=/usr/local/libjpeg/ --enable-shared --enable-static
make && make install

fontconfig 要指定 freetype 與 expat 位置:

./configure --with-freetype-config=/usr/local/freetype/bin/freetype-config \
            --with-expat-lib=/usr/lib64/
make && make install

libxml2 則是標準三步驟:configure、make、make install。

四、安裝 GD 庫

./configure --prefix=/usr/local/libgd --with-png \
            --with-freetype=/usr/local/freetype/ \
            --with-jpeg=/usr/local/libjpeg/
make && make install

configure 結束時若看到 PNG 與 JPEG 都是 yes、Freetype 2.x 為 yes,即代表成功。完成後編輯 /etc/ld.so.conf,把 zlib、freetype、libjpeg、libgd 的 lib 路徑都加進去,再執行 ldconfig 讓動態載入器更新快取。

五、安裝並配置 PHP

tar -zxvf php-5.3.9.tar.gz
./configure --prefix=/usr/local/php \
  --with-apxs2=/usr/local/apache/bin/apxs \
  --with-mysql=/usr/local/mysql/ \
  --enable-gd-native-ttf --enable-gd-jis-conv \
  --with-freetype-dir=/usr/local/freetype/ \
  --with-jpeg-dir=/usr/local/libjpeg/ \
  --with-png-dir=/usr/ \
  --enable-xml --enable-mbstring --enable-sockets
make && make install

建立設定檔並串接 Apache:

cp php.ini-development /usr/local/php/php.ini
ln -s /usr/local/php/bin/* /usr/local/bin/

編輯 /usr/local/apache/conf/httpd.conf,確認以下四行:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-icon .ico
DirectoryIndex index.html index.php

建立測試檔 /usr/local/apache/htdocs/test.php 寫入 <?php phpinfo(); ?>,用瀏覽器開啟,看到資訊頁就代表解析環境正常。

CentOS 源碼包完整搭建 Cacti 監控系統(上)

由於篇幅所限,rrdtool 安裝與 Cacti 本體的部署請見續篇。

Copyright © Linux教程網 All Rights Reserved