監(jiān)控網(wǎng)絡(luò)神器---Cacti 安裝與配置
Cacti是一款非常實(shí)用的網(wǎng)絡(luò)流量監(jiān)測(cè)圖形分析工具,叫它為監(jiān)控網(wǎng)絡(luò)神器也不為過,讓我們看看他的安裝和配置!
一、Cacti的安裝
1.安裝環(huán)境:RedHat AS 4
2.安裝Apache、MySQL、PHP
(1).安裝MySQL
下載地址:http://dev.mysql.com/downloads/mysql/5.0.html
//查看系統(tǒng)中是否已經(jīng)安裝了MySQL,如果是卸載所有以mysql開頭的包。
# rpm –qa | grep mysql
# rpm –e mysql-*
//查找/etc/my.cnf(MySQL的選項(xiàng)配置文件),如果有請(qǐng)刪除它,以免影響新安裝版本的啟動(dòng)。
# rm –f /etc/my.cnf
# tar –zxvf mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
# cp –rf mysql-standard-5.0.27-linux-i686-glibc23 /usr/local/
//建立符號(hào)鏈接,如果以后有新版本的MySQL的話,你可以僅僅將源碼解壓到新的路徑,然后重新做一個(gè)符號(hào)鏈接就可以了。這樣非常方便,數(shù)據(jù)也更加安全。
# ln –s mysql-standard-5.0.27-linux-i686-glibc23 /usr/local/mysql
//添加用于啟動(dòng)MySQL的用戶及用戶組(如果以前安裝過MySQl,用戶及用戶組可能已存在)。
# useradd mysql
# groupadd mysql
//初始化授權(quán)表
# cd /usr/local/mysql
# scripts/mysql_install_db
//修改MySQl目錄的所有權(quán)
# cd /usr/local
# chgrp –R mysql mysql-standard-5.0.27-linux-i686-glibc23
# chgrp –R mysql mysql
# chown –R mysql mysql-standard-5.0.27-linux-i686-glibc23/data
# chown –R mysql mysql/data
# ln –s /usr/local/mysql/bin/* /usr/local/bin/
//啟動(dòng)Mysql
# bin/safe_mysqld --user=mysql &
//配置系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng)MySQl
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
//修改MySQL的***連接數(shù)
# vi /etc/my.cnf
//添加以下行
[mysqld]
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
//max_connections設(shè)置***連接數(shù)為1000
//max_user_connections設(shè)置每用戶***連接數(shù)為500
//wait_timeout表示200秒后將關(guān)閉空閑(IDLE)的連接,但是對(duì)正在工作的連接不影響。
//保存退出,并重新啟動(dòng)MySQL
//重新啟動(dòng)MySQL后使用下面的命令查看修改是否成功
# mysqladmin -uroot -p variables
Password:
//可以看到以下項(xiàng)說明修改成功
| max_connections | 1000
| max_user_connections | 500
| wait_timeout | 200
(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
//編譯時(shí)加上加載模塊參數(shù)--enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
//修改Apache配置文件,添加ServerName www.yourdomain.com (或ServerName 本機(jī)ip)
# vi /etc/rc.d/rc.local
//在rc.local上加入一行/usr/local/apache/bin/apachectl –k start,系統(tǒng)啟動(dòng)時(shí)啟動(dòng)Apache服務(wù)。
#p#
(3).安裝PHP
先安裝zlib,freetype,libpng,jpeg以便于讓PHP支持GD庫(Cacti的WeatherMap插件必須要較新GD庫的支持)
庫文件下載地址:http://oss.oetiker.ch/rrdtool/pub/libs/
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/里拷一個(gè)
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 一步創(chuàng)建多層目錄
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make && make install
注意,這里configure一定要帶--enable-shared參數(shù),不然,不會(huì)生成共享庫
5).安裝Fontconfig
tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure --with-freetype-config=/usr/local/freetype
make
make install
6).安裝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
編譯時(shí)顯示以下信息:
** 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
7).編輯/etc/ld.so.conf,添加以下幾行到此文件中。
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/libjpeg/lib
/usr/local/libgd/lib
并執(zhí)行l(wèi)dconfig命令,使用動(dòng)態(tài)裝入器裝載找到共享庫
8).安裝libxml,RedHat AS 4默認(rèn)安裝libxml包,但版本太低,PHP5需要更高版本的libxml包。
# tar –zxvf libxml2-2.6.25.tar.gz
# cd libxml2-2.6.25
# ./configure
# make
# make install
9).安裝PHP
PHP下載地址:http://www.php.net/downloads.php#v5
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 --enable-gd-jis-conv --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
# make
# make install
# cp php.ini-recommended /usr/local/php/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-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
修改DirectoryIndex 行,添加index.php
修改為DirectoryIndex index.php index.html index.html.var
# vi /usr/local/apache/htdocs/test.php
添加以下行:
//php標(biāo)記(用<代替[)
[?php
Phpinfo();
?]
wq保存退出。
# /usr/local/apache/bin/apachectl –k stop
#/usr/local/apache/bin/apachectl –k start
在瀏覽器中輸入:http://www.yourdomain.com/test.php進(jìn)行測(cè)試。
對(duì)php編譯選項(xiàng)的解釋:
--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 //激活對(duì)本地 TrueType 字符串函數(shù)的支持
--with-ttf //激活對(duì) FreeType 1.x 的支持
--with-freetype-dir=/usr/local/freetype //激活對(duì) FreeType 2.x 的支持
--with-jpeg-dir=/usr/local/libjpeg //激活對(duì) jpeg-6b 的支持
--with-png-dir=/usr //激活對(duì) png 的支持
--with-zlib-dir=/usr/local/zlib //激活對(duì)zlib 的支持
--enable-mbstring //激活mbstring模塊
--enable-gd-jis-conv //使JIS-mapped可用,支持日文字體
--with-mail //支持Mail函數(shù)
--enable-xml //支持XML
--enable-sockets //支持套接字
#p#
1.安裝RRDTool
由于rrdtool-1.2.23需要一些庫文件支持,故需先安裝配置支持的環(huán)境,然后編譯安裝。直接運(yùn)行以下bash腳本就可以完成安裝:
注意:將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放到/root/rrdtool-1.2.23目錄下,將腳本保存為/root/rrdtool-1.2.23/rrdtoolinstall.sh,并給執(zhí)行權(quán)限chmod u+x /root/rrdtool-1.2.23/rrdtoolinstall.sh。
以下鏈接是我重新打好的一個(gè)rrdtool-1.2.23的安裝包,里面包括了所有用到的庫文件和安裝腳本,下載解壓后執(zhí)行腳本rrdinstall.sh即可以完成RRDTool的安裝。
點(diǎn)擊下載rrdtool-1.2.23.tar.gz
如果以上腳本安裝失敗,可以試試以下安裝包:
http://61.156.20.41/autodownload/rrdtool-1.2.11.tar.gz
#!/bin/sh
BUILD_DIR=`pwd`
INSTALL_DIR=/usr/local/rrdtool
cd $BUILD_DIR
tar zxf cgilib-0.5.tar.gz
cd cgilib-0.5
make CC=gcc CFLAGS="-O3 -fPIC -I."
mkdir -p $BUILD_DIR/lb/include
cp *.h $BUILD_DIR/lb/include
mkdir -p $BUILD_DIR/lb/lib
cp libcgi* $BUILD_DIR/lb/lib
cd $BUILD_DIR
tar zxf zlib-1.2.3.tar.gz
cd zlib-1.2.3
env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf libpng-1.2.18.tar.gz
cd libpng-1.2.18
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.2.5
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
env CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
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
cd $BUILD_DIR
tar zxf rrdtool-1.2.23.tar.gz
cd rrdtool-1.2.23
./configure --prefix=$INSTALL_DIR --disable-python --disable-tcl && make && make install
//完成后建立符號(hào)連接
ln –s /usr/local/rrdtool/bin/* /usr/local/bin/
//執(zhí)行rrdtool看是否安裝正確
#p#
2.安裝net-snmp
RedHat默認(rèn)安裝了SNMP服務(wù),但好象沒有snmpwalk,snmpget這兩個(gè)命令,所以需要編譯安裝NET-SNMP。
NET-SNMP官方網(wǎng)站:http://www.net-snmp.org/
# 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
//修改snmpd.conf(修改COMMUNITY、允許抓取snmp數(shù)據(jù)的主機(jī)、抓取數(shù)據(jù)范圍等)。
# /usr/local/net-snmp/sbin/snmpd //啟動(dòng)SNMP服務(wù)
# vi /etc/rc.d/rc.local
//在rc.local上加入一行/usr/local/net-snmp/sbin/snmpd,系統(tǒng)啟動(dòng)時(shí)啟動(dòng)SNMP服務(wù)。
3.安裝Cacti
Cacti官方網(wǎng)站:www.cacti.net/
# tar –zxvf cacti-0.8.6j.tar.gz
# mv –r 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目錄的所有權(quán)給cacti用戶
# chown –R cacti /usr/loca/apache/htdocs/cacti/rra
//修改cacti目錄所屬組
# chgrp –R cacti /usr/loca/apache/htdocs/cacti
//為cacti用戶添加cron任務(wù)
# su – cacti
# crontab –e
*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1
注意:***執(zhí)行poller.php時(shí)請(qǐng)使用cacti用戶,否則生成的rrd文件cacti將沒有寫入權(quán)限。
4.安裝Cactid
CACTID 的安裝需要以下支持:
o net-snmp-devel (需要編譯安裝net-snmp時(shí)添加--enable-developer選項(xiàng))
o mysql
o mysql-devel (mysql源文件編譯安裝后默認(rèn)支持)
o openssl-devel (Redhat默認(rèn)安裝)
# 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
//這時(shí)你將在此目錄下看到多出了cactid、cactid.conf兩個(gè)文件
# 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
5.數(shù)據(jù)庫配置
#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:
#p#
6.完成cacti的安裝
1).在瀏覽器中輸入:http://www.yourdomain.com/cacti/
默認(rèn)用戶名:admin 密碼:admin
2).更改密碼
3).設(shè)置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

4).進(jìn)入cacti后需確認(rèn)更改以下位置:(如下圖)
Console>Settings>General

Console>Settings>Poller

通過上面幾大步的安裝和配置,終于把監(jiān)控網(wǎng)絡(luò)神器---Cacti 搞定了!
【編輯推薦】