64位linux環境下編譯安裝cacti

首先安裝apache

# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
# ./configure --prefix=/usr/local/apache22 --enable-module=so--with-mpm=worker --enable-module=rewrite
# make && make install
啓動apache:
# /usr/local/apache22/bin/apachectl start
IE訪問http://ip/出現”It works!”,說明apache安裝成功。


mysql

# tar zxvf mysql-5.0.22.tar.gz
# cd mysql-5.0.22
# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data/--without-innodb --without-debug --with-extra-charsets=gbk--with-extra-charsets=all --enable-assembler --with-pthread--enable-thread-safe-client --with-client-ldflags=-all-static
配置成功出現“Thank you forchoosing MySQL!”提示。
# make &&make install
Mysql配置
# cp ./support-files/mysql.server /etc/init.d/mysql
# groupadd mysql
# useradd –g mysql mysql
# chmod 777 /etc/init.d/mysql
# /usr/local/mysql/bin/mysql_install_db
# chown -R mysql:mysql /usr/local/mysql/data/
啓動Mysql
# service mysql start
# /usr/local/mysql/bin/mysqladmin –u root –p password '123456'      //設置密碼爲rootpw
Enterpassword:                //默認密碼爲空,所以直接回車
# /usr/local/mysql/bin/mysql –u root –p
Enterpassword:                //輸入新密碼後,登錄成功
mysql安裝配置完畢。


第二部分:安裝GD庫及相關插件

編譯安裝libxml

# wget http://xmlsoft.org/sources/libxml2-2.7.2.tar.gz

# tar zxvflibxml2-2.7.2.tar.gz

# cd libxml2-2.7.2

# ./configure --prefix=/usr/local/libxml2/

# make && make install


編譯安裝zlib

# wget http://google-desktop-for-linux-mirror.googlecode.com/files/zlib-1.2.3.tar.gz

# tar zxvf zlib-1.2.3.tar.gz

# cd zlib/1.2.3/

# ./configure --prefix=/usr/local/zlib2/

# make && make install


編譯安裝jpeg

這個版本jpeg在make install時會出現目錄error。手動創建這些目錄,然後再重新makeinstall就可以了,我這把缺失的命令都加上了,應該不會出這個error了。

# wget ftp://ftp.aai.ee/pub/unix/jpegsrc.v6b.tar.gz

# mkdir /usr/local/jpeg6

# mkdir /usr/local/jpeg6/include

# mkdir /usr/local/jpeg6/lib

# mkdir /usr/local/jpeg6/bin

# mkdir/usr/local/jpeg6/man/man1 -p

# tar zxvfjpegsrc.v6b.tar.gz

# cd jpeg-6b

# ./configure --prefix=/usr/local/jpeg6

# make

# make install-lib

# make install


編譯安裝libpng

# wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz

# tar zxvflibpng-1.2.18.tar.gz

# cd libpng-1.2.18

# cp scripts/makefile.gcmmx makefile

# ./configure --disable-shared--prefix=/usr/local/libpng2/

# make && make install


編譯安裝freetype

# wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz

# tar zxvf freetype-2.3.5.tar.gz

# cd freetype-2.3.5

# ./configure --disable-shared--prefix=/usr/local/freetype2/

# make && make install


編譯安裝libart_lgpl

# wget http://oss.oetiker.ch/rrdtool/pub/libs/libart_lgpl-2.3.17.tar.gz

# tar zxvf libart_lgpl-2.3.17.tar.gz

# cd libart_lgpl-2.3.17

# ./configure --disable-shared--prefix=/usr/local/libart/

# make && make install


編譯安裝gettext

# wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.16.1.tar.gz

# tar zxvf gettext-0.16.1.tar.gz

# cd gettext-0.16.1

# ./configure --prefix=/usr/local/gettext/

# make && make install  //這個編譯時間好長啊。。。

上面全部安裝完成後,開始編譯安裝gd,此處注意configure時各個插件的地址是否正確:

# wget http://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz

# tar zxvfgd-2.0.35.tar.gz

# cd gd/2.0.35/

# ./configure --prefix=/usr/local/gd2--with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng2/--with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/--with-libart=/usr/local/libart/ --with-gettext=/usr/local/gettext/--with-libxml=/usr/local/libxml2

# cp /usr/lib/libattr.* /lib/  //如果沒執行這步,make時會出現下面的error信息

# make && make install

安裝GD2時出錯提示:

cd . &&/bin/sh /tmp/cacti/gd/2.0.35/config/missing --run aclocal-1.9 -I config

aclocal:configure.ac:64:warning: macro `AM_ICONV' not found in library

cd .&& /bin/sh /tmp/cacti/gd/2.0.35/config/missing --run automake-1.9--foreign

cd . &&/bin/sh /tmp/cacti/gd/2.0.35/config/missing --run autoconf

configure.ac:64:error: possibly undefined macro: AM_ICONV

    If this token and others are legitimate, please use m4_pattern_allow.

    See the Autoconf documentation.

make: ***[configure] error 1


解決方法:

# cp /usr/lib/libattr.*/lib/         //有兩個libattr開頭文件,有一個/lib裏有,另一個複製過去就行了


編譯安裝Curl支持

# wget http://dl.ambiweb.de/mirrors/curl.haxx.se/curl-7.15.0.tar.gz

# tar zxvfcurl-7.15.0.tar.gz

# cd curl-7.15.0

# ./configure --prefix=/usr/local/curl

# make && make install



第三部分:編譯安裝並配置PHP

# wget http://us3.php.net/distributions/php-5.2.16.tar.bz2

# tar jxvf php-5.2.16.tar.bz2

# cd php-5.2.16

# ./configure --prefix=/usr/local/php--with-apxs2=/usr/local/apache22/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/--with-png-dir=/usr/local/libpng2/ --with-gd--with-freetype-dir=/usr/local/freetype2/ --with-zlib-dir=/usr/local/zlib2/--with-mysql=/usr/local/mysql --with-curl=/usr/local/curl--with-gettext=/usr/local/gettext --enable-sockets

我第一次安裝時,編譯PHP出錯了,出錯信息提示GD有問題:“configure: error: Unable to findgd.h anywhere under”上網查了下說:“系統中已經有GD了,把--with-gd後面留空,就可以順利configure了,上面的命令,我已經去掉了—with-gd的值,所以應該不會出這個error了。仔細想想好像我裝系統時確實把圖形那個組件給點上了!嘿嘿~~~

Configure成功後提示”Thankyou for using PHP.”.


# make

# make test


Make test時出錯了,不過感覺這個錯誤影響不是很大,暫時也沒找到原因,可能是版本問題,因爲上次安裝時,我用的不同版本,所以遇到的錯誤信息也不一樣,有點忘了,上次試用了三四個版本,頭都搞大了。所以這次也沒管它,直接繼續安裝了~還好後面都成功了,php好用~~~所以暫時就這樣吧,如果有高手知道原因,望告之~呵呵~~即使後面不成功的話,這裏也可以重編譯再裝:)換版本或想別的辦法解決!!!

ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush(). [tests/output/ob_start_basic_unerasable_005.phpt]

SPL: ArrayObject::exchangeArray() basic usage with object as underlyingdata store. [ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]


繼續:

# make install

# cp php.ini-dist/usr/local/php/lib/php.ini    //拷貝php配置文件


修改apache配置文件httpd.conf

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

在#AddType application/x-tar.tgz下加一行:

AddTypeapplication/x-httpd-php .php

在#LoadModule foo_module modules/mod_foo.so下加一行: 如果原來有就去掉#號

LoadModulephp5_module  modules/libphp5.so

找到DirectoryIndexindex.html在後面添加index.php

保存httpd.conf文件.

重啓動apache


# /usr/local/apache22/bin/apachectl stop

# /usr/local/apache22/bin/apachectl start


會出現報錯,重啓不成功:

*** httpd: Syntaxerror on line 53 of /usr/local/apache22/conf/httpd.conf: Cannot load /usr/local/apache22/modules/libphp5.sointo server: /usr/local/apache22/modules/libphp5.so: cannot restore segmentprot after reloc: Permission denied

# setenforce 0

# chcon -c -v -R -u system_u -r object_r -ttextrel_shlib_t /usr/local/apache22/modules/libphp5.so

# /usr/local/apache-2.2.17/bin/apachectlrestart

# setenforce 1


執行了之後還是會報錯:

*** httpd: Could not reliably determine theserver's fully qualified domain name, using 220.250.64.24 for ServerName

 在http.conf這個文件裏面找到#ServerName www.example.com:80這一行,取掉前面的註釋,然後保存退出就可以成功的重啓apache服務了



第四部分:編譯安裝rrdtool及安裝配置snmp

編譯安裝rrdtools

# wget ftp://ftp.pucpr.br/rrdtool/rrdtool-1.2.27.tar.gz

# tarzxvf rrdtool-1.2.27.tar.gz

# cdrrdtool-1.2.27

#./configure --prefix=/usr/local/rrdtool

# make && make install


安裝SNMP(或者採用源碼方式安裝SNMP,這裏爲了方便才使用的yum安裝)

# yum -y install net-snmp*


配置SNMP

#vi /etc/snmp/snmpd.conf

com2sec notConfigUser default public

改爲:com2sec notConfigUser127.0.0.1 public

access notConfigGroup "" anynoauth exact systemview none none

改爲:access notConfigGroup"" any noauth exact all none none

#view        all       included           .1         80

將前面的#註釋去掉。

保存退出:wq

4.重新啓動snmp服務

# service snmpd restart

用這個snmpwalk -v 2c -cpublic 127.0.0.1 if 測試SNMP是否有問題



第五部分:安裝/配置cacti

# wget http://www.cacti.net/downloads/cacti-0.8.7g.tar.gz

# tar zxvf cacti-0.8.7g.tar.gz

# mv cacti-0.8.7g/usr/local/apache22/htdocs/cacti

# chown -R root:root/usr/local/apache22/htdocs/cacti


在Mysql中創建新的database,導入cacti目錄中的cacti.sq創建表:

# /usr/local/mysql/bin/mysql –u root –p

Enter Password:123456                 //安裝mysql時設置的密碼,默認爲空

mysql> create database cacti;

mysql> use cacti;

mysql> source/usr/local/apache22/htdocs/cacti/cacti.sql;


設置數據庫用戶權限:

grant all on cacti.* to root;

grant all on cacti.* to root@localhost;

grant all on cacti.* to cactiuser;

grant all on cacti.* tocactiuser@localhost;

set password forcactiuser@localhost=password('123456');


編輯cacti的數據庫配置文件,與上一步中的用戶對應。

# vi /usr/local/apache22/htdocs/cacti/include/config.php

$database_type=“mysql”;

$database_default=“cacti”;

$database_hostname=“localhost”;

$database_username=“cactiuser”;

$database_password=“123456”;


打開瀏覽器http://IP地址/cacti

這裏可能出現的error信息如下:You have created anew database, but have not yet imported the 'cacti.sql …

解決方法:出現這個錯誤是因爲數據庫用戶的權限問題。如果按照我上面的用戶創建及設置應該是不會出現這個error的。如果把$database_hostname換成IP,就會出現這個錯誤。當然如果給這個IP地址grant給用戶權限後,就不會出錯了!

例如:grant all on cactidb.* to cactiuser@ip;grant all on cactidb.* to root@ip;

注:以下幾步,根據Cacti的版本不同,先後順序會稍有不同,但大致內容都是一樣的。

如果不出錯誤的話,應該就進入了Cacti InstallationGuide畫面,點擊Next>>,進入下一頁; 這個畫面可以選擇是初次安裝Cacti,還是升級安裝Cacti,同時提醒覈對數據庫連接信息,點擊Next>>,繼續; 打開snmp、php、rrdtool等工具的路徑設置畫面,按照你的安裝路徑全部填上就行了。設置完成後,登錄到cacti控制檯畫面,選擇左側菜單的settings->paths,可以修改設置。默認的配置中會出現許多“NotFound”,一定要全部填寫正確!不然會影響畫圖。各個路徑根據自己的安裝路徑填寫,找不着的可以試着用whereis、find之類的命令檢索一下。

RRDTool Binary Path: /usr/local/rrdtool/bin/rrdtool

PHP Binary Path:/usr/local/php/bin/php

snmpwalk Binary Path:/usr/bin/snmpwalk

snmpget Binary Path:/usr/bin/snmpget

snmpbulkwalk Binary Path:/usr/bin/snmpbulkwalk

snmpgetnext Binary Path:/usr/bin/snmpgetnext

CactiLogFilePath:/usr/local/apache22/htdocs/cacti/log/cacti.log

CactidPollerFilePath:/usr/local/apache22/htdocs/cacti/poller.php

RRDTool Default Font Path:/usr/local/rrdtool/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf

SNMP Utility Version選擇NET-SNMP 5.x

點擊Finish 結束配置,進入登錄畫面。

首次登陸默認賬號:admin密碼admin

登陸後系統會強制立即修改密碼


生成統計圖像:

手動運行一次poller.php,生成初始圖像文件:

# /usr/local/php/bin/php /usr/local/apache22/htdocs/cacti/poller.php >/dev/null 2>&1

查看圖像文件是否生成:

# ls /usr/local/apache22/htdocs/cacti/rra

這裏我看網上很多朋友都遇到圖像未生成或看不到圖像的問題了,我第一次安裝時也遇到了,查了好多資料,最後歸根結底其實都是SNMP的配置問題!按照我上面的安裝方法,安裝完成之後,使用如下命令測試一下,如果沒報錯,說明SNMP就是沒問題的!應該可以出現圖像的:

# snmpwalk -v 1 127.0.0.1 -c public

正常會顯示信息類似如下:

(略)HOST-RESOURCES-MIB::hrSWRunPerfCPU.2436= INTEGER: 8(略)

如果還是看不到圖像的話,可以到cacti的控制檯裏,打開Data Sources->隨便點一個例如Localhost – Processes,然後點擊右上角的Turn on Data SourceDebug Mode,下面會有一些提示信息。或者看一下/usr/local/apache22/htdocs/cacti/log/cacti.log文件。一定會找到原因的。或者問我也可以!哈哈~~~~

添加自動執行:

# crontab –e

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

這樣,每過1分鐘就會自動更新一次圖像統計信息。

打開cacti控制檯,在graphs中localhost裏就可以看到本機的CPU、內存等的統計信息圖了。

這裏需要注意一下,cacti的版本不同,settings裏的設定項也不太一樣!我也是因爲裝了兩次,用的不同版本才發現的!改動還滿大的~哈哈,實在懶得去看版本更新日誌,就直接進系統比較了~~~還有好多不一樣的地方,大家一起去發現吧:)

小提示:注意整個安裝過程中的權限相關的問題,主要涉及就如下幾個:本次安裝時我沒用創建新用戶單獨給cacti使用,而是直接用的root。如果用別的用戶,需要把/usr/local/apache22/htdocs/cacti的目錄權限及自動執行poller.php的用戶更改。還有就是mysql的用戶問題,注意/usr/local/mysql/data文件夾及其子目錄的權限問題,偶爾會出錯。

好了,暫時就寫到這吧~~如果有問題歡迎大家批評交流~~~呵呵:)


安裝 spine

          tar zxvfcacti-spine-0.8.7g.tar.gz

           cd cacti-spine-0.87g

          ./configure--prefix=/usr/local/spine

           Make && makeinstall

           cd /usr/local/spine/etc/

           cp spine.conf.distspine.conf

           Vim spine.conf  修改

        DB_Host         localhost    

        DB_Database     cacti            數據庫的名字

        DB_User             root              數據苦用戶

        DB_Pass          123456        數據庫密碼

        DB_Port              3306              端口號

        DB_PreG             0



安裝cacti插件,在官網上下載好對應cacti-0.87g的這個cacti-plugin-0.8.7g-PA-v2.8.tar.gz包,

tarzxvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz

/usr/local/mysql/bin/mysql -u root cacti -p< cacti-plugin-arch/pa.sql

patch -p1 -N <cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.8.diff

然後,vim /usr/local/apache22/htdocs/cacti/include/global.php 添加$config['url_path'] = '/cacti/';

下載monitor插件,cd /usr/local/apache22/htdocs/cacti/plugins

                   tar zxvfmonitor-0.8.2.tar.gz

                    /usr/local/mysql/bin/mysql-uroot cacti -p < monitor/monitor.sql

                    Vim/usr/local/apache22/htdocs/cacti/include/config.php

                    加上$plugins[] = 'monitor';

其他插件一樣安裝。


第六部分  後續問題

完成後報類似這樣的錯,經過google,查到是因爲mysql默認連接數太小造成的。

SPINE: Poller[0] FATAL: Connection Failed, Error:'1040', Message:'Toomany connections' (Spine thread)


解決辦法:/usr/local/mysql/bin/mysql -u root -p

set GLOBAL max_connections=200000;

/usr/local/mysql/bin/mysqladmin -uroot -p variables 查看是否改成功了

=============================================================================

安裝遇到問題總結

/usr/bin/ld: /usr/local/libpng2/lib/libpng12.a(libpng12_la-png.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

/usr/local/libpng2/lib/libpng12.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

make[2]: *** [libgd.la] 錯誤1

make[2]: Leaving directory `/data/soft/php/gd-2.0.35'

make[1]: *** [all-recursive] 錯誤1

make[1]: Leaving directory `/data/soft/php/gd-2.0.35'

make: *** [all] 錯誤2

-----------------------------

libpng的問題,我們改一改編譯以及安裝的方式。跟上邊2個一樣,要先把/usr/local/libpng2 都刪乾淨,然後再重新編譯安裝。

編譯安裝 libpng

#tar zxvf libpng-1.2.34.tar.gz

#cd libpng-1.2.34

#cp scripts/makefile.gcmmx makefile

#./configure --prefix=/usr/local/libpng2/

# vi Makefile

找到 CFLAGS = -g -O2 後邊加上 -fPIC

# make && make install


編譯安裝後php.ini 文件應該放在 /usr/lib64/php.ini 中 注意設定好時間

安裝rrdtool之前確保安裝了這些庫zlib libpng freetype libart_lgpl

如果./configure時出現下面這個錯誤


configure: error: Please fix the library issues listed above and try again.


就要安裝libart_lgpl-devel這個包

make   進行編譯
make install  將編譯好的安裝到/usr/local/rrdtool-1.2.6/
ls /usr/local/rrdtool-1.2.6/ 查看該目錄

bin examples include lib man share shared 應該有這些目錄才正至此rrdtool安裝成功



本文出自 “某人說我技術宅” 博客,請務必保留此出處http://1992mrwang.blog.51cto.com/3265935/1264444

發佈了57 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章