Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> Linux文化

Cacti 安裝實錄:從零開始的踩雷筆記

Cacti 早就聽過很多次,也看過它的成果,但因為懶一直沒自己裝。這兩天終於找時間裝起來,越用越順手,值得推薦。以下把過程與踩到的雷記錄下來,權當一份作業。

三個原則

1. 認真看官方文件。官方文件很多,別抓到一篇就当救生圈,多看好幾份再動手。

2. 善用 Google。

3. 不斷嘗試。筆者裝了兩次:第一次因為沒耐性,PHP 沒把 gd 編進去就放棄,後來在 RedHat AS 3 上完整裝了一次,再回頭把原系統修好。

需要的軟體

全部以原始碼編譯(裝 rpm 裝怕了):MySQL(建議 4.x,5.x 使用過程中出過問題,換回 4.x 就正常)、Apache、zlib、libpng、freetype、GD、Net-SNMP(建議裝 rpm:net-snmp、net-snmp-devel、net-snmp-utils)、libart、RRDTool、Cacti。

安裝順序

mysql → apache → net-snmp → zlib → libpng → freetype → libart → GD → php → RRDTool → Cacti。順序不是絕對,但編譯 PHP 之前一定要先裝好 GD,而 GD 依赖的函式庫自然更早。

關鍵步驟

MySQL

groupadd mysql
useradd -g mysql mysql
gunzip < mysql-VERSION.tar.gz | tar -xvf -
./configure --prefix=/usr/local/mysql
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysql_install_db --user=mysql
chown -R root . && chown -R mysql var && chgrp -R mysql .
bin/mysqld_safe --user=mysql &

Apache

./configure --prefix=/usr/local/apache --enable-shared=max --enable-cache --enable-speling --enable-rewrite --enable-so --with-mpm=worker --enable-ssl
make && make install

Net-SNMP

rpm -ivh Net-snmp*

libpng/freetype/libart/RRDTool/GD

這幾個環節最麻煩,涉及環境變數。先設定:

BUILD_DIR=/tmp/rrdbuild
INSTALL_DIR=/usr/local/rrdtool-1.2.12

zlib 用 env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb;libpng 與 freetype 則帶上 CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" 並加 --disable-shared;libart_lgpl 同樣以 CFLAGS="-O3 -fPIC" 編譯。

接著再一次設定環境變數:

IR=-I$BUILD_DIR/lb/include
CPPFLAGS="$IR $IR/libart-2.0 $IR/freetype2 $IR/libpng"
LDFLAGS="-L$BUILD_DIR/lb/lib"
CFLAGS=-O3
export CPPFLAGS LDFLAGS CFLAGS

然後編譯 rrdtool(--disable-python --disable-tcl),最後編 GD 時明確指定 --with-freetype、--with-libpng 的路徑。

PHP

./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-zlib --with-png=/usr/local/libpng --with-jpeg --with-freetype=/usr/local/freetype --enable-sockets
make && make install

Cacti

解到 htdocs 下,建立資料庫並匯入 cacti.sql,建立帳號:

grant all privileges on cacti.* to cactiuser@localhost identified by 'cacti';
flush privileges;
chown -R cactiuser rra/ log/

修改 include/config.php 的資料庫參數,並在 /etc/crontab 加入:

*/5 * * * * cactiuser /usr/local/php/bin/php /usr/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1

測試

先手動執行 poller.php,若輸出類似:

OK u:0.00 s:0.00 r:1.01

連續幾行就代表正常。測完請把 rra/ 裡的 rrd 檔刪掉,因為剛剛是用 root 跑的,權限會有問題。

踩到的雷

1. MySQL 5.x 使用過程中出問題,換回 4.x 即恢復。

2. 編譯 GD 出現:

gd_png.c:802: syntax error before '&' token
make[2]: *** [gd_png.lo] Error 1

解法是修改 gd_png.c,把 include 明確指向 /usr/local/libpng/include/png.h。

參考資料

chinaunix 教學、phpv 文章、Cacti 官方文件、rrdtool 的 rrdbuild.txt。

若有遺漏,敬請見諒。

Copyright © Linux教程網 All Rights Reserved