由于一直在生产环境中使用 FreeBSD 操作系统,平时经常会在虚拟机上装 N 多个系统用于测试。有些测试需要从干净的环境开始,所以经常建重复的虚拟机,让人无聊无比。如何快速搭建测试所需环境,成为了这种无聊事情中唯一有乐趣的事情。
一般来说,AMP 环境是众多测试项目环境的基础。譬如邮件系统、远程监控管理等众多应用都会用到 Apache、MySQL 等组件。因此,快速搭建 AMP 环境是那些有乐趣的事情中的重点。我们崇尚 BT 精神,追求搭建 AMP 环境的速度。公司里也有个文档,每次搭建一个就掐秒表,搭完了记录一下,看谁能保持最快纪录。
我初学 FreeBSD,对这样的竞赛不敢留有想法。要知道某些列车并不是我们这些泛泛之辈可以赶上的。为了让自己的动作也快一些,再快一些,我也做了这样一个笔记。
首先是一些时刻准备着的包:
www# ls
APC-3.0.13.tgz jpeg-6b.diff.gz
Authen-SASL-2.10.tar.gz jpegsr6.zip
GD-2.35.tar.gz jpegsrc.v6b.tar.gz
libgcrypt-1.2.4.tar.gz Storable-2.16.tar.gz
libiconv-1.11.tar.gz Unix-Syslog-0.100.tar.gz
libpng-1.2.12.tar.bz2 ZendOptimizer-3.2.6-freebsd6.0-i386.tar.gz
libxml2-2.6.26.tar.bz2 m4-1.4.9.tar.gz
autoconf-2.60.tar.bz2 maildrop-2.0.4.tar.bz2
automake-1.9.6.tar.bz2 make-3.81.tar.bz2
mhash-0.9.7.tar.bz2 mm-1.4.2.tar.bz2
cyrus-sasl-2.1.22.tar.gz mysql-5.0.37.tar.gz
mysql_configure.sh pcre-6.7.tar.bz2
freetds-stable.tgz pcre-7.0.tar.bz2
freetype-2.1.9.tar.bz2 perl-5.8.8.tar.bz2
freetype-2.3.2.tar.gz php-5.2.3.tar.bz2
freeze-2.5.tar.gz php_configure.sh
gd-2.0.34.tar.bz2 gettext-0.16.tar.gz
pure-ftpd-1.0.21.tar.gz gmp-4.2.1.tar.bz2
wget-1.9.tar.gz gzip-1.3.5.tar.bz2
zlib-1.2.3.tar.bz2 httpd_configure.sh
其中 php_configure.sh 是 PHP 编译脚本,mysql_configure.sh 是 MySQL 编译脚本,httpd_configure.sh 是 Apache 编译脚本,其内容如下:
www# more php_configure.sh
#!/bin/sh
./configure --prefix=/usr/local/php --disable-cgi --sysconfdir=/etc --with-apxs2=/usr/local/apache/bin/apxs --enable-discard-path --
with-config-file-path=/etc/apache --enable-hash --with-openssl --with-mhash --enable-bcmath --with-bz2 --enable-calendar --enable-ct
ype --enable-dbase --enable-ftp --with-iconv --enable-exif --with-gd --enable-gd-native-ttf --with-zlib=/usr --with-ttf --with-freet
ype-dir=/usr --with-png --with-gmp --enable-mbstring --enable-mbregex --with-pcre-regex=/usr --with-mysql=/usr/local/mysql --with-my
sql-sock=/tmp/mysql.sock --enable-pdo --with-pdo-mysql=/usr/local/mysql --with-mssql=/usr/local/freetds --with-gettext=shared,/usr -
-with-expat-dir=/usr --with-xml --enable-wddx --with-mm=/usr --enable-sockets --disable-debug --disable-ipv6 --enable-memory-limit -
-enable-inline-optimization --enable-zend-multibyte --with-tsrm-pthreads --with-jpeg-dir=/usr --enable-zip
# LoadModule php5_module libexec/libphp5.so
# AddModule mod_php5.c
# AddType application/x-httpd-php .php .phtml
www# more mysql_configure.sh
#!/bin/sh
# mysql configure
./configure --prefix=/usr/local/mysql --enable-assembler \
--disable-largefile --with-charset=gbk \
--with-pthread --with-zlib-dir=/usr \
--without-debug --with-openssl=/usr --without-docs \
--without-man
www# more httpd_configure.sh
./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --enable-modules=all --enable-mods-shared=all --enable-cache --enabl
e-mime-magic --enable-mem-cache --enable-ssl --enable-cgi --enable-rewrite --enable-isapi --enable-so
下面的过程已经比较精简了,就不再注释:
www# tar -xzvf wget-1.9.tar.gz
www# cd wget-1.9
www# ./configure
www# make
www# make install
www# file /usr/local/bin/wget
/usr/local/bin/wget: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
www# /usr/local/bin/wget http://apache.mirror.phpchina.com/httpd/httpd-2.2.8.tar.gz
www# tar -xzvf httpd-2.2.8.tar.gz
www# /usr/local/bin/wget http://192.168.0.200/mysql-5.0.45.tar.gz
www# tar -xzvf mysql-5.0.45.tar.gz
www# /usr/local/bin/wget http://cn.php.net/get/php-5.2.5.tar.gz/from/this/mirror
www# tar xzvf php-5.2.5.tar.gz
www# cd ..
www# tar -xzvf zlib-1.2.3.tar.bz2
www# cd zlib-1.2.3
www# ./configure -s
www# make
www# make install
www# cd ../mysql-5.0.45
www# sh ../mysql_configure.sh
www# make
www# make install
www# cd ../httpd-2.2.8
www# sh ../httpd_configure.sh
www# make
www# make install
www# cd ..
www# tar -xzvf freetds-stable.tgz
www# cd freetds-0.64/
www# ./configure --prefix=/usr/local/freetds
www# make
www# make install
www# cd ..
www# tar -xzvf libiconv-1.11.tar.gz
www# cd libiconv-1.11
www# ./configure
www# make
www# make install
www# cd ..
www# file /usr/local/apache/bin/apxs
/usr/local/apache/bin/apxs: a /replace/with/path/to/perl/inte script text executable
www# tar -xzvf pcre-6.7.tar.bz2
www# cd pcre-6.7
www# ./configure
www# make
www# make install
www# cd ..
www# tar -xzvf perl-5.8.8.tar.bz2
www# cd perl-5.8.8
www# rm -f config.sh Policy.sh
www# sh Configure -de
www# make
www# make test
www# make install
www# file /usr/bin/perl
/usr/bin/perl: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
www# vi /usr/local/apache/bin/apxs
将
#!/replace/with/path/to/perl/interpreter -w
换成
#!/usr/bin/perl -w
www# cd ..
www# tar -xzvf libxml2-2.6.26.tar.bz2
www# cd libxml2-2.6.26
www# ./configure
www# make
www# make install
www# cd ..
www# tar -xzvf gzip-1.3.5.tar.bz2
www# cd gzip-1.3.5
www# ./configure
www# make
www# make install
www# cd ..
www# tar xzvf jpegsrc.v6b.tar.gz
www# gzip -d jpeg-6b.diff.gz
www# cd jpeg-6b
www# ./configure --prefix=/usr/local --enable-shared
www# make
www# make install
www# cd ..
www# tar -xzvf libpng-1.2.12.tar.bz2
www# cd libpng-1.2.12
www# ./configure
www# make
www# make check
www# make install
www# cd ..
www# tar -xzvf make-3.81.tar.bz2
www# cd make-3.81
www# ./configure
www# make
www# make check
www# make install
www# tar -xzvf freetype-2.1.9.tar.gz
www# cd freetype-2.1.9
www# /usr/local/bin/make
www# /usr/local/bin/make (没错,的确是两遍)
www# /usr/local/bin/make install
www# cd ..
www# tar -xzvf gettext-0.16.tar.gz
www# cd gettext-0.16
www# ./configure
www# make
www# make install
www# cd ..
www# tar -xzvf gmp-4.2.1.tar.bz2
www# cd gmp-4.2.1
www# ./configure
www# make
www# make check
www# make install
www# cd ..
www# tar -xzvf mhash-0.9.7.tar.bz2
www# cd mhash-0.9.7
www# ./configure
www# make
www# make install
www# cd ..
www# tar -xzvf mm-1.4.2.tar.bz2
www# cd mm-1.4.2
www# ./configure
www# make
www# make test
www# make install
www# cd ../php-5.2.5
www# sh ../php_configure.sh
www# make
www# make test
www# make install
未完待续。