一. cacti 架構php
二. cacti工做流程html
三. cacti的安裝mysql
1. 安裝環境:RedHat AS4.8linux
2. 安裝Apache、MySQL、PHPgit
(1).安裝MySQLsql
//查看系統中是否已經安裝了MySQL,若是是卸載全部以mysql 開頭的包。數據庫
# rpm –qa | grep mysqlapache
# rpm –e mysql-*瀏覽器
//查找/etc/my.cnf(MySQL 的選項配置文件),若是有請刪除它,以避免影響新架構
安裝版本的啓動。
# rm –f /etc/my.cnf
# tar –zxvf mysql-4.1.10.tar.gz
# ./configure --prefix=/usr/local/mysql && make && make install
//添加用於啓動MySQL 的用戶及用戶組(若是之前安裝過MySQl,用戶及用戶
組可能已存在)。
# useradd mysql
# cd /usr/local/mysql
//修改MySQl 目錄的全部權
# chown –R mysql.mysql /usr/local/mysql
# bin/mysql_install_db --user=mysql
修改數據庫屬主
Chown mysql var
Bin/mysqld_safe –user=mysql &
Echo ‘/usr/local/mysql/bin/mysqld_safe --user=mysql &’>>/etc/rc.local
# ln –s /usr/local/mysql/bin/* /usr/local/bin/
(2).安裝Apache
下載地址:http://httpd.apache.org/
# tar –zxvf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
# ./configure --prefix=/usr/local/apache --enable-so
//編譯時加上加載模塊參數--enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
//修改Apache 配置文件,添加ServerName www.yourdomain.com(或ServerName 本
機ip)
# vi /etc/rc.d/rc.local
// 在rc.local 上加入一行/usr/local/apache/bin/apachectl start, 系統啓動時啓動
Apache 服務。
(3).安裝PHP
先安裝zlib,freetype,libpng,jpeg 以便於讓PHP 支持GD 庫( Cacti 的WeatherMap
插件必需要GD 庫的支持)
1).安裝zlib
tar zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make
make install
2).安裝libpng
tar zxvf libpng-1.2.16.tar.tar
cd libpng-1.2.16
cd scripts/
mv makefile.linux ../makefile
cd ..
make
make install
注意,這裏的makefile 不是用./configure 生成,而是直接從scripts/裏拷一個
3).安裝freetype
tar zxvf freetype-2.3.4 .tar.gz
cd freetype-2.3.4
./configure --prefix=/usr/local/freetype
make
make install
4).安裝Jpeg
tar -zxf jpegsrc-1.v6b.tar.gz
cd jpeg-6b/
mkdir /usr/local/libjpeg
mkdir /usr/local/libjpeg/include
mkdir /usr/local/libjpeg/bin
mkdir /usr/local/libjpeg/lib
mkdir /usr/local/libjpeg/man
mkdir /usr/local/libjpeg/man/man1
//能夠用mkdir -p /usr/local/libjpeg/man/man1 一步建立多層目錄
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make && make install
注意,這裏configure 必定要帶--enable-shared 參數,否則,不會生成共享庫
5).安裝libxml,RedHat AS 4 默認安裝libxml 包,但版本過低,PHP5 須要更高
版本的libxml 包。
# tar –zxvf libxml2-2.6.25.tar.gz libxml2-devel也要裝(RPM)
# cd libxml2-2.6.25
# ./configure
# make
# make install
6).安裝Fontconfig (用RPM安裝,灰字忽略)擴展包和關聯包也裝上
tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
make
make install
7).安裝GD
tar -zxvf gd-2.0.34.tar.gz
cd gd-2.0.34
./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg
make
make install
編譯時顯示如下信息:
** Configuration summary for gd 2.0.34:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
8).編輯/etc/ld.so.conf,添加如下幾行到此文件中。
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/libjpeg/lib
/usr/local/libgd/lib
並執行ldconfig 命令,使用動態裝入器裝載找到共享庫
9).安裝PHP
tar -zxvf php-5.2.3.tar.gz
cd php-5.2.3
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --enable-gd-native-ttf --with-ttf --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr --with-zlib-dir=/usr/local/zlib --enable-xml --enable-mbstring --enable-sockets
#注:若是出現configure: error: cannot find output from lex; giving up,從光盤安裝flex包便可解決。-_-!!
# make
# make install
# 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-tar .tgz
AddType application/x-httpd-php .php
AddType p_w_picpath/x-icon .ico
修改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 進行測試。
對php 編譯選項的解釋:
--prefix=/usr/local/php //指定PHP 的安裝目錄
--with-apxs2=/usr/local/apache2/bin/apxs //支持Apache 模塊
--with-mysql=/usr/local/mysql //支持MySQl
--with-gd=/usr/local/libgd //支持GD 庫
--enable-gd-native-ttf //激活對本地TrueType 字符串函數的支持
--with-ttf //激活對FreeType 1.x 的支持
--with-freetype-dir=/usr/local/freetype //激活對FreeType 2.x 的支持
--with-jpeg-dir=/usr/local/libjpeg //激活對jpeg-6b 的支持
--with-png-dir //激活對png 的支持
--with-zlib-dir=/usr/local/zlib//激活對zlib 的支持
--enable-mbstring //激活mbstring 模塊
--with-mail //支持Mail 函數
--enable-xml //支持XML
--enable-sockets //支持套接字
3. 安裝RRDTool
因爲rrdtool-1.2.23 須要一些庫文件支持,故需先安裝配置支持的環境,而後編譯安
裝。
須要的包:cgilib-0.5.tar.gz、zlib-1.2.3.tar.gz、libpng-1.2.18.tar.gz、freetype-
2.3.5.tar.gz、libart_lgpl-2.3.17.tar.gz、rrdtool-1.2.23.tar.gz
tar zxf cgilib-0.5.tar.gz
(1)cd cgilib-0.5
對於0.5版本的cgilib源碼部分需作必定的修改:
在 cgi.c 裏尋找 #include <malloc.h> ,把那行刪掉
修改cgitest.c中116行的錯誤
116行的代碼以下:
printf ("<h3>Cookie "Library" set</h3>\n";
應爲代碼出錯,正確的應是
printf ("<h3>Cookie \"Library\" set</h3>\n";
make
make install
mkdir -p /usr/local/rrdtool/lb/include
cp cgi.h /usr/local/rrdtool/lb/include
mkdir -p /usr/local/rrdtool/lb/lib
cp libcgi.a /usr/local/rrdtool/lb/lib
(2)tar zxf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/rrdtool/lb
make
make install
tar zxvf libpng-1.2.18.tar.gz
(3)cd libpng-1.2.18
./configure --disable-shared --prefix=/usr/local/rrdtool/lb
make
make install
tar zxvf freetype-2.3.5.tar.gz
(4)cd freetype-2.2.5
./configure --disable-shared --prefix=/usr/local/rrdtool/lb
make
make install
(5)tar zxvf libart_lgpl-2.3.17.tar.gz 用RPM把開發包也裝上libart_lgpl-devel....
cd libart_lgpl-2.3.17
./configure --disable-shared --
prefix=/usr/local/rrdtool/lb
make;make install
(6)tar xjf intltool-0.40.6.tar.bz2
Cd intltool-0.40.6
./configure
Make;make install
(7)tar zxf rrdtool-1.2.23.tar.gz
cd rrdtool-1.2.23
./configure --prefix=/uar/local/rrdtool --disable-tcl &&
make && make install
//完成後創建符號鏈接
ln –s /usr/local/rrdtool/bin/* /usr/local/bin/
cp /usr/local/lib/libpng.so.0 /usr/lib/ 這步必須有,不然報錯找不到此文件。
//執行rrdtool 看是否安裝正確
4. 安裝net-snmp
# tar zxvf net-snmp-5.2.4.tar.gz
#cd net-snmp-5.2.4
#./configure --prefix=/usr/local/net-snmp --enable-developer
#make
#make install
# ln –s /usr/local/net-snmp/bin/* /usr/local/bin/
#cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
修改/usr/local/net-snmp/share/snmp/snmpd.conf文件的61和62行,設置能夠訪問改SNMP的網段以及community名稱。
好比設置爲
com2sec local localhost public
com2sec mynetwork 192.168.100.0/24 public
# /usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf
啓動SNMP 服務
# vi /etc/rc.d/rc.local
//在rc.local 上加入一行/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf,系統啓動時啓動SNMP
服務。
5. 安裝Cacti
Cacti 官方網站:www.cacti.net/
# tar –zxvf cacti-0.8.6j.tar.gz
# mv cacti-0.8.6j /usr/loca/apache/htdocs/cacti
# vi /usr/local/apache/htdocs/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
//添加cacti 用戶
# useradd cacti
//將rra 目錄的全部權給cacti 用戶
# chown –R cacti /usr/loca/apache/htdocs/cacti/rra
//修改cacti 目錄所屬組
# chgrp –R cacti /usr/loca/apache/htdocs/cacti
//添加cron 任務
# crontab –e
*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/cacti/poller.php
> /dev/null 2>&1
6. 安裝Cactid
CACTID 的安裝須要如下支持:
net-snmp-devel (須要編譯安裝net-snmp 時添加--enable-developer 選項)
mysql
mysql-devel (mysql 源文件編譯安裝後默認支持)
openssl-devel (Redhat 默認安裝)
# tar -zxvf cacti-cactid-0.8.6i.tar.gz
# cd cacti-cactid-0.8.6i
# ./configure --with-mysql=/usr/local/mysql --with-snmp=/usr/local/net-snmp
# make;
//這時你將在此目錄下看到多出了cactid、cactid.conf 兩個文件
# mkdir /usr/local/cactid
# cp cactid cactid.conf /usr/local/cactid
# vi /usr/local/cactid/cactid.conf //修改cactid 配置文件
DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
7. 數據庫配置
#mysql –uroot –p
Password:
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cacti@localhost identified by 「cacti」;
Query OK, 1 row affected (0.00 sec)
mysql>exit
# cd /usr/local/apache/htdocs/cacti
# mysql –uroot –p cacti < cacti.sql
Password:
補充:#ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.15.0.0 /usr/lib/libmysqlclient.so.15
#ldconfig
這兩句要加上,不然系統沒法找到libmysqlclient.so.15庫
Chmod 777 /usr/local/apache/htdocs/cacti/log
Chmod 777 /usr/local/apache/htdocs/cacti/rra
8. 完成cacti 的安裝
1).在瀏覽器中輸入: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