本文中的apache,php和mysql都是编译安装的,使用的都是最新的稳定版本,首先来看下它们的编译安装过程。

进行以下准备工作

建立以下目录:

[bash]#mkdir /usr/local/lamp                                    #存放所有编译的程序
[bash]#mkdir /usr/local/lamp/etc                              #存放配置文件
[bash]#mkdir /usr/local/lamp/apache24                    #apache安装目录
[bash]#mkdir /usr/local/lamp/mysql                          #mysql安装目录
[bash]#mkdir /usr/local/lamp/php                             #php安装目录
[bash]#groupadd -g 150 mysql

设定mysql用户和安装目录权限

[bash]#useradd -u 150 -g mysql -d /usr/local/lamp/mysql -M mysql   #mysql用户
[bash]#ls /usr/local/lamp/mysql/   -l
[bash]#chown -R mysql.root /usr/local/lamp/mysql      #改变安装目录用户所有权
[bash]#chmod  775 /usr/local/lamp/mysql                   #改变目录的读写权限
[bash]#mkdir /usr/local/lamp/database                           #存放mysql数据库
[bash]#chown -R mysql.root /usr/local/lamp/database/
[bash]#chmod -R 775 /usr/local/lamp/database/

1、安装apache

到搜狐开原镜像网站下载apache2.4最新版本

[bash]#wget http://mirrors.sohu.com/apache/httpd-2.4.1.tar.gz

解压缩

[bash]#tar zxvf   httpd-2.4.1.tar.gz
[bash]#cd httpd-2.4.1

进行编译前的配置:

[bash]#./configure --prefix=/usr/local/lamp/apache24 --sysconfdir=/usr/local/lamp/etc --with-included-apr --enable-so --enable-deflate --enable-expires --enable-rewrite --enable-static-support  --enable-mods-shared=most  --enable-speling  --enable-forward --enable-ssl  --with-ssl  --enable-cache-disk

编译

[bash]#make

安装

[bash]#make  install

如果出现: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

则需要下载apr和apr-utils 并解压到./srclib/, 再进行编译

[bash]#wget  http://apache.etoak.com//apr/apr-util-1.4.1.tar.gz

[bash]#wget  http://apache.etoak.com//apr/apr-1.4.6.tar.gz

[bash]#tar zxvf  apr-1.4.6.tar.gz

[bash]#tar zxvf apr-utli-1.4.1.tar.gz

[bash]#cp  -rf apr-1.4.6 httpd-2.4.1/srclib/apr

[bash]#cp  -rf apr-util-1.4.6 httpd-2.4.1/srclib/apr-util

测试服务是否安装成功

[bash]#/usr/local/lamp/apache24/bin/apachectl start

打开浏览器,输入

http://YOURIP

如果返回It works说明apache安装成功了,

2、安装mysql5.5.21

不知道为什么最近sohu和163的开源镜像站上都没有mysql的下载地址了,只好在官网注册个账号下载了

下载mysql-community-server-5.5.21.tar.gz源码

首先需要安装以下程序和开发库

[bash]#yum –y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel  libtool*

然后解压源码包

[bash]#tar zxvf mysql-5.5.21.tar.gz
[bash]#cd mysql-5.5.21

先对安装包进行清理

[bash]#make clean

[bash]#rm –rf  CMakeCache.txt

使用cmake编译mysql  (cmake编译mysql的选项参见mysql编译configure向cmake过渡指南)

配置编译选项:

[bash]#cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/lamp/mysql -DSYSCONFDIR=/usr/local/lamp/etc  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci   -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1   -DMYSQL_DATADIR=/usr/local/lamp/database  -DMYSQL_USER=mysql -DWITH_DEBUG=0

编译安装:

[bash]#make
[bash]#make install

复制配置文件

[bash]# cp ./support_files/my-medium.cnf  ../etc/my.cnf

#设置mysql服务

[bash]#cp /usr/local/lamp/mysql/support-files/mysql.server /etc/init.d/mysql
[bash]#chmod 755 /etc/init.d/mysql
[bash]#chkconfig mysql on

#安装默认数据库

[bash]#/usr/local/lamp/mysql/scripts/mysql_install_db --basedir=/usr/local/lamp/mysql --datadir=/usr/local/lamp/database --skip-name-resolve --user=mysql

#启动MySQL服务器

[bash]#service mysqd start

设置mysql的rootyonghu密码

[bash]#mysqladmin -uroot password  "password"

设定mysql的环境变量,我用连接的方式设定的

[bash]#ln -s /usr/local/lamp/mysql/bin/mysql  /usr/local/

3、安装php

安装一些开发库

安装libjpeg-devel,net-snmp,net-snmp-devel,net-snmp-utils gmp gmp-devel

[bash]#yum install libjpeg-devel,net-snmp,net-snmp-devel,net-snmp-utils gmp gmp-devel

下载php的最新稳定版本源码

[bash]#wget  http://mirrors.sohu.com/php/php-5.3.6.tar.gz
[bash]#tar zxvf php-5.3.6.tar.gz
[bash]#cd  php-5.3.6

配置编译选项

[bash]#./configure --prefix=/usr/local/lamp/php --with-apxs2=/usr/local/lamp/apache24/bin/apxs --with-mysql=/usr/local/lamp/mysql --with-mysqli=/usr/local/lamp/mysql/bin/mysql_config  --build=i386-redhat-linux-gnu  --host=i386-redhat-linux-gnu --target=i686-redhat-linux-gnu --with-pdo-mysql=/usr/local/lamp/mysql --with-libxml-dir --enable-xml --with-gd --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif  --with-snmp --enable-inline-optimization --disable-debug --sysconfdir=/usr/local/lamp/etc --cache-file=../config.cache --with-libdir=lib --with-config-file-path=/usr/local/lamp/etc --with-pic --disable-rpath --without-gdbm --with-gettext  --with-gmp --with-iconv --with-pcre-regex --with-zlib --with-layout=GNU --enable-magic-quotes

编译安装:

[bash]#make
[bash]#make install
[bash]#cp  php.ini-recommended /usr/local/lamp/php/etc/php.ini

编辑/usr/local/lamp/etc/httpd.conf

1、把这两行

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

添加到

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz之后

2、修改

DirectoryIndex index.html

DirectoryIndex index.html index.php

重启apache,并写一个phpinfo脚本测试下php的安装

这样基础的三大件就安装完成了,接下来安装cacti需要的一些组件:rrdtool 、 spine等

4、安装rrdtool

下载rrdtool

[bash]#wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
[bash]#tar zxvf rrdtool-1.4.7.tar.gz
[bash]#cd rrdtool

进行编译安装:

[bash]#./configure  --prefix= /usr/local/lamp/rrdtool
[bash]#Make
[bash]#Make install
[bash]#ln -s /usr/local/lamp/rrdtool/bin/* /usr/local/bin/    //完成后建立符号连接
[bash]#rrdtool -v    //查看rrdtool版本,测试rrdtool是否安装成功,如果安装成功就可以安装cacti了

5、安装配置cacti

下载安装cacti

[bash]#tar -zxvf cacti-0.8.7i.tar.gz
[bash]#mv –r cacti-0.8.7i  /usr/local/lamp/apache24/htdocs/cacti

初始化cacti数据库

[bash]#cd /usr/local/lamp/apache24/htdocs/cacti
[bash]#mysql -uroot -p  //登录mysql 配置cacti数据库

mysql>create database cacti;
mysql>grant all on cacti.* to cacti@localhost identified by "cacti";
mysql>exit

[bash]#mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql     //导入cacti数据库初始化脚本

配置cacti的数据库连接

[bash]#vim  include/config.php

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";

[bash]#vim include/globel.php

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";

配置snmp轮询

[bash]#useradd cacti       //添加cacti用户
[bash]#chown -R cacti rra     //将rra目录的所有权给cacti用户
[bash]#chgrp -R cacti .    //修改cacti目录所属组
[bash]#su cacti   //为cacti用户添加cron任务
[bash]#crontab -e   //编辑定时任务

*/5 * * * * /usr/local/lamp/bin/php /usr/local/lamp/apache24/htdocs/cacti/poller.php > /dev/null 2>&1
# /usr/local/bin/php /usr/local/lamp/apache24/htdocs/cacti/poller.php

正确输出类似于下面内容:

OK u:0.01 s:0.02 r:21.42
OK u:0.01 s:0.02 r:21.42
OK u:0.01 s:0.02 r:21.42
OK u:0.01 s:0.02 r:21.42
10/21/2008 015:20:31 PM - SYSTEM STATS: Time:3.5831 Method:cmd.php Processes:1 Threads:N/A Hosts:2
HostsPerProcess:7 DataSources:401 RRDsProcessed:220

6、测试cacti
在浏览器输入 http://serverip/cacti
默认用户名:admin 密码:admin

snmpwalk Binary Path             /usr/local/bin/snmpwalk
snmpget Binary Path              /usr/local/bin/snmpget
snmpbulkwalk Binary Path       /usr/local/bin/snmpbulkwalk
snmpgetnext Binary Path         /usr/local/bin/snmpgetnext
RRDTool Binary Path               /usr/local/bin/rrdtool
RRDTool Default Font Path
PHP Binary Path                    /usr/local/lamp/php/bin/php
Cacti Log File Path               /usr/local/lamp/apache24/htdocs/cacti/log/cacti.log

至此cacti整个的安装过程就完成了,后续的使用和调试,我会陆续发表出来。