Centos5.2配置LAMP与Centos5.3配置LAMP


CentOS5.2配置LAMP全过程2009-03-30 22:00文章内容分为7部分

一:系统约定
二:系统基本设置
三:下载软件
四:安装必须的软件
五:编译安装软件
六:配置apache PHP
七:测试 (通过phpinfo,phpmyadmin,sugarcrm的安装来测试)

一:系统约定
采用Centos5.2光盘,
软件源代码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/software_name
MySQL 数据库位置 /data/mysql/data
Apache 网站根目录 /data/www/wwwroot(虚拟主机在这个目录下)
Apache 虚拟主机日志根目录 /data/www/logs
Apache 运行账户 www:www
创建两个虚拟主机 test.com linux.com

所有的配置的文件修改,都做备份,备份的名字为 文件名.save

下面的实验是用vmware station 6 创建一个 redhat AS5的vm,安装centos5.2,安装的时候,选择安装语言是英文,采用文本方式来安装,选择最小化的安装。

yum的更新,采用本地光盘的方式,这样比较快捷。

我的机器基本设置

IP:192.168.1.200/255.255.255.0

网关:192.16.1.1

DNS:192.168.1.1

hostname:ns1

二:系统基本设置

我已经把所有需要配置的内容,做一个一个脚本,只需要运行一次就可以。

cd /usr/local/src
vi /usr/local/src/init.sh

#####################

#Diabe IPV6
cp /etc/modprobe.conf /etc/modprobe.conf.save
echo “alias net-pf-10 off” >> /etc/modprobe.conf
echo “alias ipv6 off” >> /etc/modprobe.conf

#SSH
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.save
sed -i ‘/#PermitRootLogin/s/#PermitRootLogin/PermitRootLogin/’ /etc/ssh/sshd_config
sed -i -e ‘74 s/^/#/’ -i -e ‘76 s/^/#/’ /etc/ssh/sshd_config
sed -i “s/#UseDNS yes/UseDNS no/” /etc/ssh/sshd_config
sed -i -e ‘44 s/^/#/’ -i -e ‘48 s/^/#/’ /etc/ssh/sshd_config
/etc/init.d/sshd restart

#停止 the “beep”


cp /etc/inputrc /etc/inputrc.save
sed -i ‘/#set bell-style none/s/#set bell-style none/set bell-style none/’ /etc/inputrc


#关闭SElinux

cp /etc/sysconfig/selinux /etc/sysconfig/selinux.save
sed -i ‘/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/’ /etc/sysconfig/selinux



#加载光驱

mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
echo “mount /dev/cdrom /mnt/cdrom” >> /etc/rc.local


#设置yum使用本地光盘

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.save
mv /etc/yum.repos.d/CentOS-Media.repo /etc/yum.repos.d/CentOS-Media.repo.save
echo “[DVDISO]” >> /etc/yum.repos.d/dvdiso.repo
echo “name=DVD ISO” >> /etc/yum.repos.d/dvdiso.repo
echo “baseurl=file:///mnt/cdrom/” >> /etc/yum.repos.d/dvdiso.repo
echo “enabled=1″ >> /etc/yum.repos.d/dvdiso.repo
echo “gpgcheck=0″ >> /etc/yum.repos.d/dvdiso.repo


#vim设置

yum -y install vim-enhanced
mv /bin/vi /bin/vi.save
ln -s /usr/bin/vim /bin/vi
cp /etc/vimrc /etc/vimrc.save
sed -i “39 s/^/ set number \n filetype on\n set history=1000\n syntax on\n set tabstop=4\n set showmatch\n set vb t_vb=\n set mouse=a\n set ignorecase\n set autowrite\n /” /etc/vimrc

#时间的设置
yum -y install ntp
ntpdate 210.72.145.44 && clock -w

#安装常用软件

yum -y install wget unzip

#停止没有必要的服务
chkconfig –list |grep 3:on |awk ‘{print $1}’ |egrep -v ’sshd|network|syslog’ |xargs -i{} chkconfig –level 3 {} off
chkconfig –list | grep 3:on | cut -f1

#重新启动
init 6
####################

sh init.sh


三:下载软件

cd /usr/local/src
vi list

http://download.filehat.com/apache/httpd/httpd-2.2.8.tar.gz
http://opensource.nchc.org.tw/COSA/CNS4/cronolog-1.6.2.tar.gz
http://www.libgd.org/releases/gd-2.0.35.tar.bz2
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz
http://mirror.optus.net/sourcefo ... mcrypt-2.5.8.tar.gz
http://jaist.dl.sourceforge.net/ ... mcrypt-2.6.7.tar.gz
http://www.openssl.org/source/openssl-0.9.8h.tar.gz
http://openbsd.md5.com.ar/pub/Op ... penssh-5.0p1.tar.gz
http://mysql.byungsoo.net/Downlo ... ysql-5.0.51b.tar.gz
http://cn2.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
http://downloads.phpchina.com/ze ... glibc23-i386.tar.gz
ftp://ftp.cac.washington.edu/mail/imap.tar.Z
http://puzzle.dl.sourceforge.net ... s-utf-8-only.tar.gz
http://dl.sugarforge.org/sugarcr ... 0/SugarCE-5.1.0.zip
http://mirror.optus.net/sourceforge/m/mh/mhash/mhash-0.9.9.tar.gz

wget -i list

四:安装必须的软件

采用yum的方式安装

yum -y install gcc make patch gcc-c++ gcc-g77 flex bison autoconf automake \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libtiff-devel fontconfig-devel libXpm-devel gettext-devel pam-devel pcre-devel libtool libtool-ltdl

五:编译安装软件

下面的内容,其实你可以复制到一个文本,比如 install.sh 运行这个脚本,我已经测试过了,整整运行了快1个小时,估计是我在vm上跑道原因。前提是你下载的软件和我是一样的,也就是软件都是通过上面的下载的。

cd /usr/local/src
vi install.sh
###############################################

#安装openssl
cd /usr/local/src
tar zxvf openssl-0.9.8h.tar.gz
cd openssl-0.9.8h
./config shared zlib
make
make test
make install
mv /usr/bin/openssl /usr/bin/openssl.save
mv /usr/include/openssl /usr/include/openssl.save
mv /usr/lib/libssl.so /usr/lib/libssl.so.save
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ln -sv /usr/local/ssl/lib/libssl.so.0.9.8 /usr/lib/libssl.so
cd ..


#配置库文件搜索路径
echo “/usr/local/ssl/lib” >> /etc/ld.so.conf
ldconfig -v

#检测安装结果
openssl version

#安装openssh

tar xvf openssh-5.0p1.tar.gz

cd openssh-5.0p1

./configure \
”–prefix=/usr” \
”–with-pam” \
”–with-zlib” \
”–sysconfdir=/etc/ssh” \
”–with-ssl-dir=/usr/local/ssl” \
”–with-md5-passwords”

make
make install

cd ..

service sshd restart

ssh -v

#安装GD

tar jxvf gd-2.0.35.tar.bz2
cd gd-2.0.35
aclocal
./configure –prefix=/usr/local/gd2
make && make install
cd ..

#安装 libmcrypt


tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure –enable-ltdl-install
make
make install
cd ../../

cp /usr/local/lib/libmcrypt.* /usr/lib



#安装libiconv


tar zxvf libiconv-1.12.tar.gz

cd libiconv-1.12/
./configure –prefix=/usr/local
make
make install
cd ../

ln -s /usr/local/lib/libiconv.so.2 /usr/lib/


#安装mhash

tar zxvf mhash-0.9.9.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

#安装mcrypt


tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
./configure
make
make install
cd ../


#安装cronolog

tar xvf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

./configure –prefix=/usr/local/cronolog

make && make install

cd ..


#安装imap

tar zxf imap.tar.Z
cd imap-2007b
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4
echo “set disable-plaintext nil” > /etc/c-client.cf
mkdir /usr/local/imap-2007b
mkdir /usr/local/imap-2007b/include/
mkdir /usr/local/imap-2007b/lib/
chmod -R 077 /usr/local/imap-2007b
rm -rf /usr/local/imap-2007b/include/*
rm -rf /usr/local/imap-2007b/lib/*
rm -rf /usr/sbin/imapd
cp imapd/imapd /usr/sbin/
cp c-client/*.h /usr/local/imap-2007b/include/
cp c-client/*.c /usr/local/imap-2007b/lib/
cp c-client/c-client.a /usr/local/imap-2007b/lib/libc-client.a

cd ..

#安装MYSQL


tar zxvf mysql-5.0.51b.tar.gz

cd mysql-5.0.51b

./configure \
“–prefix=/usr/local/mysql” \
“–localstatedir=/data/mysql/data” \
“–with-comment=Source” \
“–with-server-suffix=-test.com” \
“–with-mysqld-user=mysql” \
“–without-debug” \
“–with-big-tables” \
“–with-charset=gbk” \
“–with-collation=gbk_chinese_ci” \
“–with-extra-charsets=all” \
“–with-pthread” \
“–enable-static” \
“–enable-thread-safe-client” \
“–with-client-ldflags=-all-static” \
“–with-mysqld-ldflags=-all-static” \
“–enable-assembler” \
“–without-isam” \
“–without-innodb” \
“–without-ndb-debug”
make && make install
useradd mysql -d /data/mysql -s /sbin/nologin
/usr/local/mysql/bin/mysql_install_db –user=mysql
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql /data/mysql/data
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig –add mysqld
/etc/rc.d/init.d/mysqld start

cd /usr/local/mysql/bin
for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done

cd /usr/local/src

mysqladmin -u root password chenshake


#安装Apache

tar zxvf httpd-2.2.8.tar.gz
cd httpd-2.2.8
./configure \
“–prefix=/usr/local/apache2″ \
“–with-included-apr” \
“–enable-so” \
“–enable-deflate=shared” \
“–enable-expires=shared” \
“–enable-rewrite=shared” \
“–enable-static-support” \
“–disable-userdir”
make
make install
cd ..

#安装PHP

tar jxvf php-5.2.6.tar.bz2
cd php-5.2.6
./configure \
“–prefix=/usr/local/php” \
“–with-apxs2=/usr/local/apache2/bin/apxs” \
“–with-config-file-path=/usr/local/php/etc” \
“–with-mysql=/usr/local/mysql” \
“–with-gd=/usr/local/gd2″ \
“–with-libxml-dir=/usr” \
“–with-jpeg-dir” \
“–with-png-dir” \
“–with-freetype-dir” \
“–with-zlib ” \
–with-iconv-dir=/usr/local \
“–with-openssl=/usr/local/ssl” \
“–with-curl ” \
“–with-curlwrappers ” \
“–with-mcrypt” \
“–with-imap=/usr/local/imap-2007b” \
“–with-kerberos” \
“–with-bz2″ \
“–enable-soap” \
“–enable-gd-native-ttf” \
“–enable-ftp” \
“–enable-mbstring” \
“–enable-exif” \
“–disable-ipv6″ \
“–disable-cgi” \
“–disable-cli”

make
make install
mkdir /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
cd ..

#安装Zend Optimizer (安装Zend Optimizer过程的最后不要选择重启Apache。)

tar xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install.sh


##########################################################################

sh install.sh


脚本到这里为止,因为zend的设置,我没法自动完成,只能你手动设置,如果谁知道怎么做,麻烦指导指导,注意php.ini 的位置 /usr/local/php/etc/

#设置session的存放位置和修改php上次文件的大小,最大文件25m

cp /usr/local/Zend/etc/php.ini /usr/local/Zend/etc/php.ini.save
sed -i -e ‘991 s/;//’ /usr/local/Zend/etc/php.ini
sed -i ’s/post_max_size = 8M/ post_max_size = 30M/g’ /usr/local/Zend/etc/php.ini
sed -i ’s/upload_max_filesize = 2M/ upload_max_filesize = 25M/g’ /usr/local/Zend/etc/php.ini
cd /usr/local/src

六:配置apache PHP

创建apache的启动脚本,apache编译包里带的那个启动脚本,有一个缺点,启动和停止没有任何提示,所以就用下面这个,比较方便。

vi /etc/init.d/httpd

###################################

#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=”"

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=/usr/local/apache2/bin/httpd
pid=/usr/local/apache2/logs/httpd.pid
prog=httpd
RETVAL=0




# The semantics of these two functions differ from the way apachectl does
# things — attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $”Starting $prog: “
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $”Stopping $prog: “
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid
}
reload() {
echo -n $”Reloading $prog: “
killproc $httpd -HUP
RETVAL=$?
echo
}

# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f $pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|condrestart|reload|status”
echo $”|fullstatus|graceful|help|configtest}”
exit 1
esac

exit $RETVAL

###########################


设置可运行和开机启动

chmod +x /etc/rc.d/init.d/httpd
chkconfig –add httpd
chkconfig –level 3 httpd on


配置apache

groupadd www -g 48
useradd -u 48 -g www www
mkdir -p /data/www/wwwroot/linux.com
mkdir -p /data/www/wwwroot/test.com
mkdir -p /data/logs
chmod +w /data/www/wwwroot
chown -R www:www /data/www/wwwroot
cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.save


编辑httpd.conf

sed -i -e ‘121 s/^/#/’ -i -e ‘122 s/^/#/’ /usr/local/apache2/conf/httpd.conf
sed -i -e “s/User daemon/User www/” -i -e “s/Group daemon/Group www/” /usr/local/apache2/conf/httpd.conf
sed -i ’s/DirectoryIndex index.html/ DirectoryIndex index.php index.html index.htm/g’ /usr/local/apache2/conf/httpd.conf
sed -i -e ‘101 s/^#//g’ -i -e ‘374 s/^#//g’ -i -e ‘389 s/^#//g’ -i -e ‘392 s/^#//g’ -i -e ‘401 s/^#//g’ /usr/local/apache2/conf/httpd.conf
sed -i “58 s/^/AddType application\/x-httpd-php .php/” /usr/local/apache2/conf/httpd.conf


编辑php.ini

cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.save
sed -i ‘205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g’ /usr/local/php/etc/php.ini
sed -i ‘/expose_php/s/On/Off/’ /usr/local/php/etc/php.ini
sed -i ‘/display_errors/s/On/Off/’ /usr/local/php/etc/php.ini

配置虚拟主机

备份相关配置文件

mv /usr/local/apache2/conf/extra/httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf.save
mv /usr/local/apache2/conf/extra/httpd-default.conf /usr/local/apache2/conf/extra/httpd-default.conf.save
mv /usr/local/apache2/conf/extra/httpd-mpm.conf /usr/local/apache2/conf/extra/httpd-mpm.conf.save


创建3个apache相关的文件

vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80


ServerAdmin shake.chen@gmail.com
DocumentRoot “/data/www/wwwroot/test.com”
ServerName test.com
ServerAlias bbs.test.com
ErrorLog “logs/test.com-error_log”
CustomLog “|/usr/local/cronolog/sbin/cronolog /data/logs/access_www.test.com.%Y%m%d” combined



ServerAdmin shake.chen@gmail.com
DocumentRoot “/data/www/wwwroot/linux.com”
ServerName linux.com
ServerAlias bbs.linux.com
ErrorLog “logs/linux.com-error_log”
CustomLog “|/usr/local/cronolog/sbin/cronolog /data/logs/access_www.linux.com.%Y%m%d” combined


vi /usr/local/apache2/conf/extra/httpd-default.conf

Timeout 15
KeepAlive Off
MaxKeepAliveRequests 50
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
ServerTokens Prod
ServerSignature Off
HostnameLookups Off

vi /usr/local/apache2/conf/extra/httpd-mpm.conf


ServerLimit 2000
StartServers 10
MinSpareServers 10
MaxSpareServers 15
MaxClients 2000
MaxRequestsPerChild 10000


七:测试

修改本地hosts文件
192.168.1.200 www.test.com

启动Apache

service httpd start

复制代码

测试php

cd /data/www/wwwroot/test.com
vi info.php


phpinfo()

?>


这个时候 http://192.168.1.200/info.php 或者 http://www.test.com/info.php 就可以看到php的信息。

安装phpadmin

cd /usr/local/src
tar zxvf phpMyAdmin-2.11.8.1-all-languages-utf-8-only.tar.gz
cp -rf phpMyAdmin-2.11.8.1-all-languages-utf-8-only /data/www/wwwroot/test.com/phpmyadmin
cd /data/www/wwwroot/test.com/phpmyadmin

cp config.sample.inc.php config.inc.php

sed -i -e “/^\$cfg\['blowfish_secret'\]/{ s@”;@’88888888888888888′;@; }” config.inc.php


这个时候,你就可以通过 http://192.168.1.200/phpmyadmin 或者 http://www.test.com/phpmyadmin来进行数据库管理, 我上面已经给mysql设置的密码。

user:root
password:chenshake

安装sugarcrm

sugarcrm的邮件模块需要用到imap,ssl,所以我编译的时候,需要吧imap,curl模块编译进去.

cd /usr/local/src
unzip SugarCE-5.1.0.zip
mv SugarCE-Full-5.1.0/ /data/www/wwwroot/test.com/sugarcrm
chmod -R 777 /data/www/wwwroot/test.com/sugarcrm/

与30万Linux爱好者讨论问题!

【已有6位网友发表了看法】 【打印】 【关闭】


相关评论
作者: isosdw 发布日期: 2009-7-29
大同小异
作者: baizx 发布日期: 2009-7-29
请 教我实质的 内容 比如 如何如何改 哪里哪里应该变动~~~谢谢
作者: baizx 发布日期: 2009-8-05
呃 转个 5.3的最近找到的

CentOS 5 全功能WWW服务器搭建全教程 V3.0
一、基本系统安装
1、下载CentOS 5
我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多。大家可以到这儿下载,速度很快的。
http://ftp.iasi.roedu.net/mirrors/ce...86-bin-DVD.iso
建议在windows下用BT或迅雷下载,速度会快很多。
下载后刻录成光盘。我建议你刻录DVD啦,如果是菜鸟,把图形界面也装上,可以在图形界面进行学习,当然强烈不建议在服务器上装桌面。
Centos 5系列任何一个版本就行了,安装后可以通过yum upgrade直接更新为最新版本。

2、安装CentOS 5
作为服务器,不安装不需要的组件,所以在选择组件的时候,除了选择FTP SERVER外取消所有组件的选择。也不要选web服务器。因为我们后面要手动编译安装。
系统约定RPM包和源码包存放位置
RPM包和源码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/xxx
脚本以及维护程序存放位置 /usr/local/sbin
MySQL 数据库位置 /var/lib/mysql
Apache 网站根目录 /usr/local/apache2/htdocs
Apache 虚拟主机日志根目录 /data/logs/www
yum RPM包信息文件 /etc/yum.list

3、系统环境部署及调整
(1)检查系统是否正常
# more /var/log/messages //检查有无系统内核级错误信息
# dmesg //检查硬件设备是否有错误信息
# ifconfig //检查网卡设置是否正确
# ping www.163.com // 检查网络是否正常
(2)关闭不需要的服务
# export LANG='en_US' //设置语言
# setup //选择启动的服务
进入system service 选项。
以space 键选定所需服务。
以下仅列出需要启动的服务,未列出的服务一律关闭:
crond
irqbalance 仅当服务器CPU为S.M.P架构或支持双核心、HT技术时,才需开启,否则关闭。
microcode_ctl
network
iptables
vsftpd
sshd
syslog
yum-updatesd
(3)修改/etc/yum.repos.d/CentOS-Base.repo,将镜象站点地址改为在中国的镜象站点地址。不然我们通过yum安装软件速度会极慢。修改如下:
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.shlug.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.shlug.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirrors.shlug.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.shlug.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.shlug.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.shlug.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
protect=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
保存文件。
(4)更新系统,我们使用yum,
运行:
# yum upgrade
建议更新所有列出的程序,包括内核,rhel 5.X的稳定性还要继续努力呢。
(5)定时校正服务器时间
# yum install –y ntp
# crontab -e
0 23 * * * /usr/sbin/ntpdate 210.72.145.44
以上命令设置好后存盘。
# /sbin/service crond reload
重载计划任务配置
您的机器将在每天的23:00根据中国国家授时中心的NTP服务器时间自动校准时间。
(6)FTP服务器的配置
vi /etc/vsftpd/vsftpd.conf
把anonymous_enable=YES
修改为anonymous_enable=No不允许匿名登录。
添加两句
chroot_local_user=yes
listen_port=2121
将用户锁定在主目录,并将FTP监听端口修改为2121
把ftpd_banner=*前的注释去掉。后面改成你的欢迎信息(这样设置可以避免显示ftp服务器的版本信息)
然后保存,service vsftpd start就可以了。
这时应当添加用户,因为root默认不能通过FTP方式登录,也不安全。
groupadd upload
useradd upload -g upload -d /usr/local/apache2/htdocs/ -M
如果FTP登录时出现
ftp服务器连接失败,错误提示:
500 OOPS: cannot change directory:/home/*******
500 OOPS: child died
解决方法:
# setsebool ftpd_disable_trans 1
# service vsftpd restart
这样对于我们上传一些文件到系统中很方便。
大家有兴趣的可以看下这篇文章对vsftpd进行一个比较详细的了解
http://blog.chinaunix.net/u/10047/showart_198837.html
4、重新启动系统
# init 6
此时系统启动成功,可以删除老的内核

二、安装mysql, apache, php, Zend Optimizer等基本环境
5. 使用 yum 程序安装所需开发包(以下为标准的rpm包名称)
# yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel
#这里我们将编译GD所必须的一些小软件比如libpng,libtiff,freetype,libjpeg,gettext-devel等先用RPM 的方式一并安装好,避免手动编译浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,php5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。
另外libxml2系统已经默认安装了,所以我们不需要手工编译了,直接安装它的开发包就行了。
6. 源码编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
# tar xzvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# yum install libtool libtool-ltdl
# aclocal
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man
// 注意,CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" 这个环境参数只针对intel P4 芯片,如果你的CPU是AMD的,注意不能使用。请查看相应的编译优化参数。否则程序会无法编译,即使编译成功也无法运行,嘿嘿。
关于其他CPU的优化参见我的BLOG的一篇转贴:
http://www.cnprint.org/bbs/blogs/1/blog43.html
//./configure 配置。
# make //make 是用来编译的,它从 Makefile 中读取指令,然后编译。
# make install //make install 是用来安装的,它也从 Makefile 中读取指令,安装到指定的位置。
(2) Apache 日志截断程序
# cd /usr/local/src
# wget http://cronolog.org/patches/cronolog-1.7.0-beta.tar.gz
# tar cronolog-1.7.0-beta.tar.gz
# cd cronolog-1.7.0-beta
#CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/cronolog && make && make install

7、编译mysql 5.0.50
mysql 5.0.50是企业版本,貌似双数版本都是企业版本了。个人觉得代码质量要比社区版本要好一些。大家可以下载,免费使用。并不需要向mysql公司交钱。
#cd /usr/local/src
# wget http://mirror.provenscaling.com/mysq...-5.0.50.tar.gz
# tar xzvf mysql-5.0.50.tar.gz
# cd mysql-5.0.50
修改mysql 客户端最大连接数, 默认的只有100,远远达不到我们的要求。
# vi sql/mysqld.cc
搜索找到下面一行:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
将其中的100改为1500, 当然小点也可以,根据你的需要来,不建议改的太大。
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
保存。
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,latin1 --with-pthread --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid
配置成功会提示:
MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.
Thank you for choosing MySQL!
# make
编译的时间可能会比较长,毕竟优化的比较厉害。
# make install
编译安装完成后执行后续操作:
# useradd mysql //添加 mysql 用户
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 "."
# cp share/mysql/my-medium.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
#添加LIB PATH
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf && ldconfig
vi /etc/my.cnf
修改 MySQL 配置,增加部分优化参数,如下:
[mysqld]
ft_min_word_len=2
运行以下命令即可启动 MySQL 服务器:
# /etc/rc.d/init.d/mysqld start //启动 MySQL
# bin/mysqladmin -u root password "password_for_root"
# service mysqld stop //关闭 MySQL

8. 编译安装 Apache
# cd /usr/local/src
# wget http://www.ip97.com/apache.org/httpd/httpd-2.2.6.tar.gz
# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
先依次安装apr和apr-util
# cd srclib/apr
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
# make && make install
# cd ../apr-util
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql
# make && make install
cd /usr/local/src/httpd-2.2.6
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mysql=/usr/local/mysql --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-ssl --with-ssl=/usr/include/openssl --with-pcre
# make
# make install
注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
--enable-cache //支持缓存
--enable-file-cache //支持文件缓存
--enable-mem-cache //支持记忆缓存
--enable-disk-cache //支持磁盘缓存
--enable-static-support //支持静态连接(默认为动态连接)
--enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
--enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
--enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
--enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
--enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
--enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
--enable-static-checkgid //使用静态连接编译 checkgid
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP
--enable-ssl // 编译 ssl模块。
我们不再使用worker模式编译apache,worker模式和php貌似有一些不协调不稳定之处。所以使用了默认的perfork模式。
将apache设置成开机自启动:
在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache2/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.
或者将apache安装为系统服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
然后 vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)
# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server
最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig --add httpd
# chkconfig httpd on

9、编译php 5.2.5
Suhosin是php增强型安全补丁,可以编译到静态内核中,也可以编译成php动态扩展。我个人强烈你建议安装成静态内核。Suhosin已经进入 Gentoo Linux、FreeBSD、OpenSuSE Linux、Mandriva Linux、Debian Linux官方包。下面的以下先说静态安装步骤。当然你也可以在安装php后将它编译成php的动态扩展。
# cd /usr/local/src
# wget http://cn.php.net/get/php-5.2.5.tar.gz/from/this/mirror
wget http://www.hardened-php.net/suhosin/...9.6.2.patch.gz
# tar zxvf php-5.2.5.tar.gz
# gunzip suhosin-patch-5.2.5-0.9.6.2.patch.gz
# cd php-5.2.5
# patch -p 1 -i ../suhosin-patch-5.2.5-0.9.6.2.patch
# ./buildconf --force
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd=/usr/local/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-openssl --with-gettext --enable-suhosin
配置成功会提示:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
# make
# make test
# make install
# cp php.ini-recommended /etc/php.ini
# echo "/usr/local/php/lib" >> /etc/ld.so.conf && ldconfig
在这里也顺便说一下将suhosin安装成为php的动态扩展的方法。毕竟网上根本不见它的中文安装教程。
虽然我个人不推荐这种方式。
wget http://www.hardened-php.net/suhosin/...sin-0.9.20.tgz
tar zxvf suhosin-0.9.20.tgz
cd suhosin-0.9.20
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
会提示编译的模块存在的目录,记住它。
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20060613/
然后在php.ini中增加一行下列语句。
extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/suhosin.so"

10、整合apache 与php
# vi /usr/local/apache2/conf/httpd.conf
在最后一行加上:
AddType application/x-httpd-php .php
查找:(设置 WEB 默认文件)
DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html index.htm
找到这一段:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none
更改为AllowOverride all
允许apache rewrite
保存httpd.conf,退出。
# /usr/local/apache2/bin/apachectl restart //重启 Apache
这时会出现错误:
/usr/local/apache2/bin/apachectl start
httpd: Syntax error on line 107 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
不急,我们慢慢解决。
这个Permission denied问题,在centos 5下面一般是Selinux引起的,作为生产用服务器,我建议你千万别草率地关掉Selinux一了百了。就像家里的防盗网,阻碍了你的猫自由进出窗户,你不能为了猫方便,就把防盗网简单拆除是同样的道理。我看见网上许多人建议把Selinux简单关闭来解决这个问题,这是削足适履的做法,不值得提倡。
我们可以这样操作:
# audit2allow -a //查看究竟问题出在什么地方

allow unconfined_t usr_t:file execmod;
allow useradd_t var_log_t:file { read write };
然后
# cd /etc/selinux/targeted/modules/
# audit2allow -M local -d
屏幕产生如下提示:
Generating type enforcment file: local.te
Compiling policy
checkmodule -M -m -o local.mod local.te
semodule_package -o local.pp -m local.mod
******************** IMPORTANT ***********************
In order to load this newly created policy package into the kernel,
you are required to execute
semodule -i local.pp
我们运行
# semodule -i local.pp
这样就让Selinux加载了新的规则。
更详细的内容请看我在BLOG上的转贴:
http://www.cnprint.org/bbs/blogs/1/blog48.html
重启apache
哈哈,apache不会再报错了吧?
这样我保留了selinux的功能,同时apache也能正常运行。
PHP5.1.x开始需要设置时区,默认时区与中国时区差8个小时,这种情况需要在php.ini中这么设置,找到date.timezone,去掉前面的分号,修改为以下值,大陆地区可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)
不然一些php程序的时间老是和中国标准时间相差8个小时。我的我的VBB论坛在windows上就是这样。这儿有亚洲地区的对应时区。
http://www.php.net/manual/en/timezones.asia.php
11、安装 Zend Optimizer
# cd /usr/local/src
# wget http://downloads.zend.com/optimizer/...21-i386.tar.gz
# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh
按照它的提示一步步进行就行了。
总之一句话。如果你的服务器环境不需要ZendOptimizer,那么能不安就不安装这个。避免和eaccelerator冲突。
12. 查看确认 L.A.M.P 环境信息
vi /usr/local/apache2/htdocs/phpinfo.php
新增加下面一行,并保存。

# chmod 755 /usr/local/apache2/htdocs/phpinfo.php
用浏览器打开 http://192.168.9.150/phpinfo.php
检查 phpinfo中的各项信息是否正确。
测试php与mysql的连接
# vi /usr/local/apache2/htdocs/testdb.php
增加下面几行,并保存。
$link=mysql_connect('localhost','root','yourpassword');
if(!$link) echo "fail";
else echo "success";
mysql_close();
?>
# chmod 755 /usr/local/apache2/htdocs/testdb.php
# service mysqld start
用浏览器打开 http://192.168.9.150/testdb.php
如果输出success就OK了
到这一步,一个基本的lamp就建立完成了。如果你是初学者,下面的步骤根据需要参考,不必全部照做,记住一句话,功能越多,越容易出错,在任何领域都是这样。

三、LAMP环境加速,包括squid, memcache, eaccelerator
13、安装eaccelerator
eaccelerator是php的加速软件,使用后php的执行效率会有较大幅度的提升。目前eaccelerator 0.9.5.2已经和ZendOptimizer-3.3.0能够基本上兼容啦。不过我个人觉得,ZendOptimizer-3.3.0没有加速的功能,反而使php运行变慢,只是起到了运行zend加密文件的作用而已。闲话不多说了,大家有兴趣的,可以去google下。
# cd /usr/local/src
# wget http://bart.eaccelerator.net/source/....9.5.2.tar.bz2
# tar -jxvf eaccelerator-0.9.5.2.tar.bz2
# cd eaccelerator-0.9.5.2
export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize //指定一下php的目录
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config --with-eaccelerator-shared-memory // 设置
# make & make install
编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,php5.2.X系列是在 /usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so,记住这个路径,待会要用到。
修改php.ini(安装完zend之后,php.ini存放于/usr/local/Zend/etc)
在文件最后,zend之前,注意,这部分内容务必放在zend之前,不然可能会出现不可预期的服务器问题。添加下列信息:
[eaccelerator]
extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
然后
# mkdir /tmp/eaccelerator // 建立目录
# chmod 0777 /tmp/eaccelerator // 修改目录属性
解释:
zend_extension 是安装完程序自动指示给我们的文件路径和文件名
如果您使用 thread safe 编译安装 PHP,则您必须使用 “zend_extension_ts” 代替 默认添加的“zend_extension”。我就必须修改这里,否则不起作用。
zend_extension_ts="/home/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"
实际上,安装好eAccelerator以后, /home/php/lib/php/extensions/下会生成2个目录,一个是no-debug-zts-xxxxxxxx,一个是no- debug-non-zts-xxxxxxxx,2个目录下都有eaccelerator.so文件。
eaccelerator.shm_size="32"
eAccelerator 可以使用的共享内存的数量 (以兆为单位) . "0" 是指操作系统的默认值. 默认值是 "0".可根据服务器的实际情况来调整,16,32,64,128都是可以的。
eaccelerator.cache_dir="/home/php/tmp"
这个目录是给磁盘缓存使用. eAccelerator 在这里储存预先编译好的代码, 进程数据, 内容以及用户的自定义内容. 同样的数据也能被储存在共享内存中 (这样可以提高访问速度). 默认的设置是 "/tmp/eaccelerator".
eaccelerator.enable="1"
开启或关闭 eAccelerator。”1″ 为开启,”0″ 为关闭。默认值为 “1″。
eaccelerator.optimizer="1"
启或关闭内部优化器,可以提升代码执行速度。”1″ 为开启,”0″ 为关闭。默认值为 “1″。
eaccelerator.check_mtime="1"
打开或者关闭 PHP 的文件修改检查. "1" 是指打开, "0" 是指关闭. 如果您在修改以后重新编译 PHP 的文件,那么您应当设置为 "1". 默认值是 "1".
eaccelerator.debug="0"
开启或关闭调试日志记录。”1″ 为开启,”0″ 为关闭。默认值为 “0″。
eaccelerator.filter=""
判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 “*.php *.phtml”等)
如果参数以 “!” 开头,则匹配这些参数的文件被忽略缓存。默认值为 “”,即,所有 PHP 文件
都将被缓存。
eaccelerator.shm_max="0"
当使用 ” eaccelerator_put() ” 函数时禁止其向共享内存中存储过大的文件。该参数指定允许
存储的最大值,单位:字节 (10240, 10K, 1M)。”0″ 为不限制。默认值为 “0″。
eaccelerator.shm_ttl="0"
当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在
最后 “shm_ttl” 秒内无法存取的脚本缓存。默认值为 “0″,即:不从共享内春中删除
任何缓存文件。
eaccelerator.shm_prune_period="0"
当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于
“shm_prune_period” 秒的缓存脚本。默认值为 “0″,即:不从共享内春中删除
任何缓存文件。
eaccelerator.shm_only="0"
允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认
值为 “0″,即:使用磁盘和共享内存进行缓存。
eaccelerator.compress="1"
允许或禁止压缩内容缓存。默认值为 “1″,即:允许压缩。
eaccelerator.compress_level="9"
指定内容缓存的压缩等级。默认值为 “9″,为最高等级。
最后重新启动apachectl
重启apache,phpinfo显示:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.3.0, Copyright (c) 1998-2006, by Zend Technologies
也会有eAccelerator的具体信息。

14、安装Squid,提供web反向代理缓存
Squid是一个更专业的代理服务器,性能和效率会比Apache的mod_proxy高很多。
Squid Internet Object Cache (Harvest Project的后续版本) 是美国政府大力助的一项研究计划,其目的为解决网络带宽不足的问题,是现在Unix系统上使用者最多功能也最完整的一套软体。Apache和 Netscape虽附有相关的Proxy模块,但因其功能简单而不够普及。有关squid的详细说明可到squid网站(http: //www.squid-cache.org)查询。
反向代理是和前两种代理完全不同的一种代理服务。使用它可以降低原始WEB服务器的负载。反向代理服务器承担了对原始WEB服务器的静态页面的请求,防止原始服务器过载。它位于本地WEB服务器和Internet之间,处理所有对WEB服务器的请求,组织了WEB服务器和Internet的直接通信。如果互联网用户请求的页面在代理服务器上有缓冲的话,代理服务器直接将缓冲内容发送给用户。如果没有缓冲则先向WEB服务器发出请求,取回数据,本地缓存后再发送给用户。这种方式通过降低了向WEB服务器的请求数从而降低了WEB服务器的负载。
下载squid
# wget http://www.squid-cache.org/Versions/...ABLE16.tar.bz2
# tar jxvf squid-2.6.STABLE16.tar.bz2
# cd squid-2.6.STABLE16
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/squid --enable-async-io=500 --with-maxfd=65536 --disable-delay-pools --disable-mem-gen-trace --disable-useragent-log --enable-kill-parent-hack --disable-arp-acl --enable-epoll --disable-ident-lookups --enable-snmp --enable-large-cache-files --with-large-files --with-pthreads --enable-underscore --enable-storeio="aufs,coss,diskd,ufs" --enable-err-language="Simplify_Chinese" --enable-default-err-languages="Simplify_Chinese"
# make && make install
如果是2.6的内核,才能支持epoll的IO模式,旧版本的内核则只能选择poll或其他模式了;另外,记得带上支持大文件的选项,否则在access log等文件达到2G的时候就会报错。
设定 squid 的配置大概如下内容:
# mv /usr/local/squid/etc/squid.conf /usr/local/squid/etc/squid.conf.bak
# vi /usr/local/squid/etc/squid.conf
#服务器IP 192.168.9.150
#监听服务器的80端口,反向代理,支持域名和IP的虚拟主机
http_port 192.168.9.150:80 vhost vport
#防止天涯盗链,转嫁给百度
acl tianya referer_regex -i tianya
http_access deny tianya
deny_info

tianya
#防止百度机器人爬死服务器,这将导致百度不能收录你的网站内容,请注意
acl AntiBaidu req_header User-Agent Baiduspider
http_access deny AntiBaidu
#Squid信息设置
visible_hostname www.cnprint.org
cache_mgr admin@cnprint.org
#squid使用的用户组和用户名
cache_effective_user nobody
cache_effective_group nobody
tcp_recv_bufsize 65535 bytes
client_persistent_connections off
server_persistent_connections on
half_closed_clients off
#单台使用,不使用该功能
icp_port 0
#设置Squid所能使用的内存共40MB,这个值因人而异,每次处理缓存大小为40MB,当缓存空间使用达到95%时新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动
cache_mem 40 MB
cache_swap_low 90
cache_swap_high 95
#最大缓存文件大小,超过这个值则不缓存,这个值因人而异,maximum_object_size_in_memory #装入内存缓存的文件大小,这个值对Squid的性能影响比较大,因为默认值是8K,超过8K的文件都不装入内存,而实际应用中很多网页和图片等都超过 8KB, 个人认为如果缓存不装入内存而存在磁盘上,性能和apache直接读取磁盘文件没什么区别,甚至不如直接访问apache,现在设置成小于4兆的文件通通装入内存缓存.
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_replacement_policy lru
memory_replacement_policy lru
#磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是100MB,都是 16*256 级子目录
cache_dir ufs /usr/local/squid/var/cache 100 16 256
#这个设置是不记录store.log
cache_store_log none
#设置默认刷新规则
refresh_pattern -i ^ftp: 1440 20% 10080
refresh_pattern -i ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
#不要相信ETag 因为有gzip
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
#设置超时策略
forward_timeout 20 seconds
connect_timeout 15 seconds
read_timeout 3 minutes
request_timeout 1 minutes
persistent_request_timeout 15 seconds
client_lifetime 15 minutes
shutdown_lifetime 5 seconds
negative_ttl 10 seconds
#打开emulate_httpd_log选项,将使Squid仿照Aapche的日志格式
emulate_httpd_log on
#日志格式combined的设置
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs % #这里是设置pid和日志文件的位置,因人而异,同时日志格式是combined,awstats可以直接调用分析了
pid_filename /usr/local/squid/var/squid.pid
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log combined
#设置不想缓存的目录或者文件类型
acl all src 0.0.0.0/0.0.0.0
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
#2.6的反向代理加速配置
#代理到本机的80端口的服务,仅仅做为原始内容服务器
cache_peer 127.0.0.1 parent 80 0 no-query originserver login=PASS
#错误文档
error_directory /usr/local/squid/share/errors/Simplify_Chinese
保存。
mkdir /usr/local/squid/var/cache
chown -R nobody:nobody /usr/local/squid/var/cache
chown -R nobody:nobody /usr/local/squid/var/logs/
chmod 777 /usr/local/squid/var/cache
修改httpd.conf
初始化和启动squid
# /usr/local/squid/sbin/squid -z
# /usr/local/squid/sbin/squid -NCd1
第一条命令是先初始化squid缓存哈希子目录,只需执行一次即可。
最好还编辑/etc/hosts 文件
添加以下内容
192.168.9.150 cnprint.org www cnprint.org
这样免去查询DNS,速度也快一些。
现在大家肯定急着要打开浏览器访问你的网站看看效果吧,其实没啥变化,要等到有流量访问,squid把文件都装到内存后,效果才明显。可以用top命令观察squid的内存使用情况或者用
cat /usr/local/squid/var/logs/access.log |grep TCP_MEM_HIT
如果看到很多的TCP_MEM_HIT ,这表明该文件是从内存缓存读取的,squid已经起作用了!你再用浏览器打开该文件,应该是快如闪电了。。呵呵,大功告成了!还有其他类型的HIT,如 TCP_HIT等等,这些是从磁盘读取的,我觉得加速的意义不大,只不过缓解了apache的压力而已。
3. 启动squid:./bin/RunCache &
这边我使用squid附带的启动脚本来启动squid,有个好处就是,如果squid的进程死了的话,这个脚本会自动启动squid,对于运行在线上的服务器来说,这点太重要了。
开机自动运行squid
修改开机自动运行文件,将 /usr/local/squid/bin/RunCache & 加进开机自动执行的程序中。
因为第一次是以 root 身份启动,所以,/usr/local/squid/var/squid.out 及 /usr/local/squid/var/squid.pid 的拥有者是 root ,这会造成下列以 nobody 身份启动 squid 时,会有错误出现,所以,必须在第二次由 rc.local 启动前,先行将 squid.out 及 squid.pid 两个文件的所有者(owner)改为 nobody,即是
chown nobody:nobody /usr/local/squid/var/squid.out
chown nobody:nobody /usr/local/squid/var/logs/squid.pid
在 /etc/rc.d/rc.local 中加入
/usr/local/squid/bin/RunCache &

15、memcache + libevent 安装
memcached是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。最初为了加速 LiveJournal 访问速度而开发的,后来被很多大型的网站采用。起初作者编写它可能是为了提高动态网页应用,为了减轻数据库检索的压力,来做的这个缓存系统。它的缓存是一种分布式的,也就是可以允许不同主机上的多个用户同时访问这个缓存系统,这种方法不仅解决了共享内存只能是单机的弊端,同时也解决了数据库检索的压力,最大的优点是提高了访问获取数据的速度!基于memcached作者对分布式cache的理解和解决方案。 memcached完全可以用到其他地方比如分布式数据库,分布式计算等领域。
Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。(关于Memcache的更多信息请Google)
Memcache官方网站:http://www.danga.com/memcached
服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.2.3。
另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,libevent的最新版本是libevent-1.3e。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/
(1)、安装memcached服务器端
编译安装:
# cd /usr/local/src
# wget http://monkey.org/~provos/libevent-1.3e.tar.gz
# tar zxvf libevent-1.3e.tar.gz
# cd libevent-1.3e
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local && make && make install
# echo "/usr/local/lib" >> /etc/ld.so.conf && ldconfig
# cd ../
# wget http://www.danga.com/memcached/dist/...d-1.2.3.tar.gz
# tar zxvf memcached-1.2.3.tar.gz
# cd memcached-1.2.3
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local
# make && make install
备注:如果 libevent 不是安装在 /usr 目录下,那么需要把 libevent-1.3e.so.1 拷贝/链接到 /usr/lib 中,否则 memcached 有可能无法正常加载。
(2)、安装php对memcache支持模块
安装php-memcache模块,这是memcache的php客户端,php-memcache需要pecl库的支持。
# cd /usr/local/src
# wget http://pecl.php.net/get/memcache-2.2.0.tgz
# tar zxvf memcache-2.2.0.tgz
#cd memcache-2.2.0
#export PHP_PREFIX=/usr/local/php
#$PHP_PREFIX/bin/phpize
#CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --enable-memcache --with-zlib-dir --with-php-config=$PHP_PREFIX/bin/php-config
#make && make install
修改php.ini
在最末尾增加一行:
extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/memcache.so"
运行以下命令来启动 memcached:
#/usr/local/memcached/bin/memcached \
-l 192.168.9.139 -d -p 11211 -u nobody -m 128
表示用 daemon 的方式启动 memcached,监听在 192.168.9.19 的 11211 端口上,运行用户为 nobody,为其分配 128MB 的内存。
这时查看一下进程,看memcached启动成功没有。
top -U nobody
可以看到
5867 nobody 15 0 2352 684 276 S 0.0 0.1 0:00.00 memcached
说明 memcached安装成功,并正在运行。
设置成开机自动运行
在 /etc/rc.d/rc.local 中加入
/usr/local/memcached/bin/memcached -l 192.168.9.150 -d -p 11211 -u nobody -m 128

四、附加功能配置, 包括ssl, mysqlhotcopy, phpmyadmin

15、安装DBI和DBD for mysql

//用于提供perl访问mysql数据库的接口规范,请确认你已经安装了perl,一般默认系统都装上了。
因为我们要用到mysqlhotcopy功能,需要这两个小程序的支持。
# wget http://mirrors.xueron.com/CPAN/autho...I-1.601.tar.gz
首先,安装DBI包:
# tar zxvf DBI-1.061.tar.gz
# cd DBI-1.061
# perl Makefile.PL
# make
# make test
# make install

wget http://search.cpan.org/CPAN/authors/...l-4.005.tar.gz
# tar zxvf DBD-mysql-4.005.tar.gz
# cp /usr/local/mysql/lib/mysql/libmysqlclient.so.15 /usr/lib/
# perl Makefile.PL --libs="-L/usr/local/mysql/lib/mysql -lmysqlclient -L/usr/lib -lz " --cflags=-I/usr/local/mysql/include/mysql --mysql_config=/usr/local/mysql/bin/mysql_config --testhost=127.0.0.1--testsocket=/tmp/mysql.sock --testdb=test --testuser=root --testpassword="youpassword"
# make
# make test
# make instll
测试执行 mysqlhotcopy 並出現如下类似錯誤訊息
#/usr/local/mysql/bin/mysqlhotcopy mysql /tmp/test -u root -p 'password'
Invalid db.table name 'mysql.mysql`.`activity' at /usr/local/bin/mysqlhotcopy line 855.
Ans:
找到了 [MySQL Bugs: #27303: mysqlhotcopy dies with error Invalid db.table name 'foo.bar`.`baz'] 说明将 mysqlhotcopy 文件修改一下后即可顺利执行 mysqlhotcopy 了
#vi /usr/local/mysql/bin/mysqlhotcopy //在第 835 下新增一行
835 my @dbh_tables = eval { $dbh->tables() };
836 map { s/^.*?\.//o } @dbh_tables; //加入此行
mysql 5.0.50后已经修正这个错误。

16、配置https
vi /usr/local/apache2/conf/httpd.conf
# 监听443端口,支持https连接
取消注释 httpd.conf 中的 Include conf/extra/httpd-ssl.conf
设置SSL并创建自己的CA
# cd /etc/pki/tls/misc
# ./CA -newca
屏幕上出现如下的提示:CA certificate filename (or enter to create)
这是要求输入要创建的CA的证书文件名, 可以直接回车或输入证书文件名。
Making CA certificate ...
Generating a 1024 bit RSA private key
.........++++++
................................++++++
writing new private key to './demoCA/private/./cakey.pem'
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:-
此时要求输入和验证CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
至此,在当前目录下生成了demoCA的目录,CA的证书就在该目录下,文件名为cacert.pem
生成服务器的证书请求
# ./CA -newreq
屏幕上出现如下的提示:
Generating a 1024 bit RSA private key
.....................................................++++++
.....++++++
writing new private key to 'newreq.pem'
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:
此时要求输入和验证服务器的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
Please enter the following 'extra' attributes
to be sent with your certificaterequest
A challenge password []:
An optional company name []:
.Request (and private key) is in newreq.pem
这是要求输入服务器的相关信息。
此时,在当前目录下生成了一个名为newreq.pem的文件,包含了要生成服务器数字证书的请求。
签署证书
# ./CA -sign
屏幕上出现如下的提示:
Using configuration from /usr/share/ssl/openssl.cnf
Enter PEM pass phrase:
此时一样需要输入CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、
« 
» 

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3