1.安装环境:RedHatAS4
2.安装Apache、MySQL、PHP,rrdtool,net-snmp,cacti
1,安装MySQL
下载地址:http://dev.mysql.com/downloads/mysql/5.0.html
//查看系统中是否已经安装了MySQL,如果是卸载所有以mysql 开头的包。
#rpm–qa |grepmysql
#rpm–e mysql-*
//查找/etc/my.cnf(MySQL 的选项配置文件),如果有请删除它,以免影响新安装版本的启动。
#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/
//建立符号链接,如果以后有新版本的MySQL 的话,你可以仅仅将源码解压到新的路径,然后重新做一个
符号链接就可以了。这样非常方便,数据也更加安全。
#ln–s mysql-standard-5.0.27-linux-i686-glibc23/usr/local/mysql
//添加用于启动MySQL 的用户及用户组(如果以前安装过MySQl,用户及用户组可能已存在)。
#useradd mysql
#groupadd mysql
//初始化授权表
#cd /usr/local/mysql
#scripts/mysql_install_db–user=mysql
//修改MySQl 目录的所有权
#cd/usr/local
#chgrp–R mysqlmysql-standard-5.0.27-linux-i686-glibc23
#chgrp–R mysql
#chown–R mysqlmysql-standard-5.0.27-linux-i686-glibc23/data
#chown–R mysqlmysql/data
#ln–s /usr/local/mysql/bin/* /usr/local/bin/
//启动Mysql
#bin/safe_mysqld --user=mysql&
//配置系统启动时自动启动MySQl
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chkconfig—add mysqld
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
#cp /usr/local/apache/bin/* /usr/bin/
#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
(注意,如果是第二次安装apache 会提示出错:apr 之类的,请用下面的方式安装:
安装APR
cd srclib/apr
#./configure --prefix=/usr/local/apr
#make
#make install
安装APR-util
cd srclib/apr-util
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install
然后进入apache 编译目录
./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all --enable-cgi
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/bin
使用编辑器打开httpd 文件,并在第一行#!/bin/sh 下增加两行文字如下
# chkconfig: 2345 98 02
# description: apache
接着注册该服务
#chkconfig—add httpd
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
makeinstall
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/里拷一个
编译 libpng(centos)
#cp scripts/makefile.gcmmx makefile
#./configure --disable-shared --prefix=/usr
#make
#make install
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,RedHatAS4 默认安装libxml 包,但版本太低,PHP5 需要更高版本的libxml 包。
#rpm–e libxml --nodeps
#rpm–e libxml-devel --nodeps
#tar–zxvf libxml2-sources-2.6.23.tar.gz
#cd libxml2-2.6.25
#./configure(切忌不要指定路径)
#make
#make install(最好删除所有系统自带安装的libxml 信息,在/usr/local/include 和/usr/lib 还有
/usr/local/lib 中)
6).安装Fontconfig
Tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure --with-freetype-config=/usr/local/freetype
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 --with-fontconfig=/usr/local/fontconfig
make
make install
编译时显示以下信息:
**Configurationsummaryforgd2.0.34:
SupportforPNGlibrary:yes
SupportforJPEGlibrary:yes
SupportforFreetype2.xlibrary:yes
SupportforFontconfiglibrary:yes
SupportforXpmlibrary:no
Supportforpthreads: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
PHP 下载地址:http://www.php.net/downloads.php#v5
Tar -zxvfphp-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/
恭喜您,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//激活对FreeType1.x的支持
--with-freetype-dir=/usr/local/freetype//激活对FreeType2.x的支持
--with-jpeg-dir=/usr/local/libjpeg//激活对jpeg-6b的支持
--with-png-dir=/usr//激活对png的支持
--with-zlib-dir=/usr/local/zlib//激活对zlib的支持
--enable-mbstring//激活mbstring模块
--enable-gd-jis-conv//使JIS-mapped可用,支持日文字体
--with-mail//支持Mail函数
--enable-xml//支持XML
--enable-sockets//支持套接字
4,设置apache和php
#vi/usr/local/apache/conf/httpd.conf
查找AddType application/x-compress .Z(305 行/centos 为767 行/)
AddType application/x-gzip .gz .tgz(306 行/centos 为768 行/)
在其下加入AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
修改DirectoryIndex(164 行/centos 为391 行/),添加index.php
修改为DirectoryIndex index.php index.html index.html.var
修改php:
vi/usr/local/apache/htdocs/test.php
添加以下行:
<?php
Phpinfo();
?>
wq 保存退出。
/etc/init.d/httpd stop
/etc/init.d/httpd start
vi /usr/local/php/lib/php.ini
将:short_open_tag = Off(131 行)
改为: short_open_tag = On
在浏览器中输入:http://www.yourdomain.com/test.php 进行测试。
显示一个php 信息的页面证明apache 和php 配置成功
5,安装RRDTool
(1)设置变量
BUILD_DIR=/install
INSTALL_DIR=/usr/local/rrdtool-1.3.0
(2)安装pkg-config
cd $BUILD_DIR
tar -zvxf pkg-config-0.23.tar.gz
cd pkg-config-0.23
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(3)安装zlib
cd $BUILD_DIR
tar -zvxf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --shared
make
make install
(4)安装libpng
cd $BUILD_DIR
tar -zvxf libpng-1.2.18.tar.gz
cd libpng-1.2.18
env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
make
make install
(5)安装freetype
cd $BUILD_DIR
tar -zvxf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(6)安装libxml2
cd $BUILD_DIR
tar -zvxf libxml2-sources-2.6.32.tar.gz
cd libxml2-2.6.23
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(7)安装fontconfig
cd $BUILD_DIR
tar -zvxf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
–with-freetype-config=/usr/local/rrdtool-1.3.0/bin/freetype-config
make
make install
(8)安装pixman
cd $BUILD_DIR
tar -zvxf pixman-0.10.0.tar.gz
cd pixman-0.10.0
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(9)安装cairo
cd $BUILD_DIR
tar -zvxf cairo-1.4.10.tar.gz
cd cairo-1.4.10
./configure --prefix=$INSTALL_DIR \
--enable-xlib=no \
--enable-xlib-render=no \
--enable-win32=no \
CFLAGS="-O3 -fPIC"
make
make install
(10)安装glib
cd $BUILD_DIR
tar -zvxf glib-2.12.13.tar.gz
cd glib-2.12.13
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(11)安装pango
cd $BUILD_DIR
tar vxf pango-1.21.1.tar
cd pango-1.21.1
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
make
make install
(12)输出变量
export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig
export PATH=$INSTALL_DIR/bin:$PATH
export LDFLAGS="-Wl,--rpath -Wl,${INSTALL_DIR}/lib"
(13)安装rrdtool
cd $BUILD_DIR/rrdtool-1.3.0
./configure --prefix=$INSTALL_DIR --disable-tcl --disable-python
make clean
make
make install
//完成后建立符号连接
ln–s /usr/local/rrdtool-1.3.0/bin/* /usr/local/bin/
//执行rrdtool 看是否安装正确
/usr/local/bin/rrdtool
显示如下信息表示rrdtool 安装成功
(RRDtool 1.3.0 Copyright 1997-2008 by Tobias Oetiker <tobi@oetiker.ch>
Compiled Apr 24 2009 07:13:15
Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, info, fetch, tune,
resize, xport
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)
For more information read the RRD manpages)
6,安装net-snmp
RedHat 默认安装了SNMP 服务,但好象没有snmpwalk,snmpget 这两个命令,所以需要编译安装NET-SNMP。
NET-SNMP 官方网站: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-mfd-rewrites
--with-default-snmp-version="2" --with-sys-contact="root,E_mail:qubaoquan@ccpower.com.cn"
--with-sys-location="china" --with-logfile="/var/log/net-snmpd.log"
--with-persistent-directory="/var/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 数据的主机、抓取数据范围等)。
#/usr/local/net-snmp/sbin/snmpd//启动SNMP 服务
#vi /etc/rc.d/rc.local
//在rc.local 上加入一行/usr/local/net-snmp/sbin/snmpd,系统启动时启动SNMP 服务。
7,安装Cacti
Cacti 官方网站:www.cacti.net/
#tar–zxvf cacti-0.8.7d.tar.gz(mysql5.0 不支持cacti-0.8.6g.tar.gz)
#mv–r cacti-0.8.7d /usr/local/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/local/apache/htdocs/cacti/rra
//修改cacti 目录所属组
#chgrp–R cacti /usr/local/apache/htdocs/cacti
//为cacti 用户添加cron 任务
#su–cacti
#crontab–e
*/5**** /usr/local/bin/php/usr/local/apache/htdocs/cacti/poller.php&gt;/dev/null2&gt;&1
注意:首次执行poller.php 时请使用cacti 用户,否则生成的rrd 文件cacti 将没有写入权限。
8,.安装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
9,数据库配置
#mysql–uroot–p
Password:
mysql&gt;create database cacti;
QueryOK,1rowaffected(0.00sec)
mysql&gt; grant all on cacti.* to cacti@localhost identified by 'cacti';;
QueryOK,1rowaffected(0.00sec)
mysql&gt;exit
#cd /usr/local/apache/htdocs/cacti
# mysql -u cacti -p -D cacti <cacti.sql
Password:cacti
10,完成cacti的安装
1).在浏览器中输入:http://www.yourdomain.com/cacti/
默认用户名:admin 密码:admin
2).更改密码
3).设置cacti 用到的命令路径
Snmpwalk BinaryPath /usr/local/bin/snmpwalk
Snmp getBinaryPath /usr/local/bin/snmpget
RRDToolBinaryPath /usr/local/bin/rrdtool
PHPBinaryPath /usr/local/bin/php
CactiLogFilePath /usr/local/apache/htdocs/cacti/log/cacti.log
CactidPollerFilePath /usr/local/cactid/cactid
4).进入cacti 后需确认更改以下位置:(如下图)
Console>Settings&gt;General
Console&gt;Settings&gt;Poller