总体布局如下:

类型软件版本地址分配功能
前台httpd-2.4.9.tar.bz2192.168.1.20(www.essun.com)处理静态页面请求
中间层处理器PHP-5.4.26.tar.bz2
192.168.1.10解析脚本请求
后台业务数据mysql-5.5.33.tar.bz2 192.168.1.30数据文件存储

一,安装httpd

前提:
必须先行安装好httpd的与MySQL的,因为后面安装的PHP要将这两个软件整合起来。
1、环境说明:

先编译安装的httpd

httpd的版本是2.4.9

下载地址:

#wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2
#wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.0.tar.bz2
#wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2

依赖关系:

在2.4.9中在以安装apr与apr-util包,由于http-2.4.9采用了新的数据结构,所以要安装apr-1.5.0以后的版本与apr-util-1.5.3版本,本机在安装好要需要的环境,要安装两个包组

# yum groupinstall -y "Development tools" "Server Platform Development"
 # yum install pcre-devel -y


2、图解编译过程

下载之后的包

wKioL1MuHovC0O0pAABwdS2tdBY570.jpg

安装APR-1.5.0.tar.bz2

wKiom1MuHtiBivjbAADFSkP0bko264.jpg

进入APR-1.5.0目录编译安装

#cd apr-1.5.0
 #./configure --prefix=/usr/local/apr
 #make && make install


解压并安装apr-util-1.5.3.tar.bz

#tar xf apr-util-1.5.3.tar.bz2
   #cd apr-util-1.5.3
   #./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
   # make && make install

解压并安装的httpd-2.4.9

# tar -xf  httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
#./configure --prefix=/usr/local/apache/ --sysconfdir=/etc/httpd24/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -enable-modules=most --enable-mpms-shared=all --with-mpm=event
    #make && make install

3、修改启动脚本(基于RPM安装的httpd所生成的服务脚本)

添加的PidFile文件路径

#vim /etc/httpd24/httpd.conf

wKioL1MuH4zQ-GduAABYHjeYce0270.jpg

此处为指定httpd服务创建的pid文件,优先读取配置文件中的参数脚本本身的定义的参数将被忽略。在配置文件中变量是不区分大小写的如若指定/var/run/directory/路径运行应用程序的用户必须有对/var/run有创建权限。

修改脚本文件


      #!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#           server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
# 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: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}
# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac
exit $RETVAL

4、添加到启动队列中

#chmod +x /etc/init.d/httpd24

wKiom1MuKQuijq8zAAHajvYEbi8497.jpg

5、启用httpd的相关模块
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
以上两个模块可以在httpd.conf中动态加载
6、配置虚拟主机支持使用fcgi
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include /etc/httpd24//extra/httpd-vhosts.conf

7、在相应的虚拟主机中添加类似如下。

#vim /etc/httpd24/extra/httpd-vhosts.conf

wKioL1MuKXmCqi-RAAM9kfTwADQ728.jpg

ProxyRequests Off:关闭正向代理
ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://192.168.1.20:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。

8、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页

wKiom1MuKdaBGt7DAACLuMN99ic927.jpg

9、定位至DirectoryIndex index.html

  修改为:

   #DirectoryIndex  index.php  index.html

=========================================到此httpd编译安装完成==========================

二、安装mysql

1、准备数据存放的文件系统
新建一个逻辑卷,并将其挂载至特定目录即可。 逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。

wKioL1MuKi-SWFS2AALnevJUKf4016.jpg

格式化、挂载到己经建立的目录上

wKiom1MuKnuTQ3OnAAF2aYFKAcY192.jpg

查看挂载(mount)

wKioL1MuKnnCTbJiAAJagsm-RzA292.jpg

将卷挂载到目录/mydata之后,新建一个目录(data)用于存放数据文件
2、新建一个用户,在一个安全的环境中运行

# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data

3、解压、编译

#tar -xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
 #cd /usr/local/
 # ln -s mysql-5.5.33-linux2.6-x86_64 mysql
 #cd mysql
# chown -R mysql.mysql .
 # scripts/mysql_install_db --user=mysql --datadir=/mydata/data
#chown -R root .

4、为mysql提供主配置文件:
# cd /usr/local/mysql
# cp support-files/my-large.cnf  /etc/my.cnf

并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:

thread_concurrency = 4

另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data

5、为服务添加脚本

wKiom1MuK9-yKaELAAL2cGSEbBY684.jpg

6、为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

导出man帮助手册

#echo 'MANPATH /usr/local/mysql/man' >>/etc/man.config

链接头文件

#ln -s include /usr/include/mysql

指定库文件

#echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
 #ldconfig

导入二进制文件

#echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
# . /etc/profile.d/mysql.sh

============================================到此安装完成 mysql============================

三、安装php

1、下载地址:

#wget http://am1.php.net/distributions/php-5.4.26.tar.bz2
2、安装流程

./configure --prefix=/usr/local/php --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets  --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

注:

今天下午安装 php 5.4.26的时候出现了一个错误,是关于libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.

系统 centos 6.5 X64
我首先查看 有没有安装libxml2
[root@station114 php-5.4.26]# rpm -ql  libxml2
/usr/bin/xmlcatalog
/usr/bin/xmllint
/usr/lib64/libxml2.so.2
/usr/lib64/libxml2.so.2.7.6
/usr/share/doc/libxml2-2.7.6
/usr/share/doc/libxml2-2.7.6/AUTHORS
/usr/share/doc/libxml2-2.7.6/ChangeLog.gz
/usr/share/doc/libxml2-2.7.6/Copyright
/usr/share/doc/libxml2-2.7.6/NEWS
/usr/share/doc/libxml2-2.7.6/README
/usr/share/doc/libxml2-2.7.6/TODO
/usr/share/man/man1/xmlcatalog.1.gz
/usr/share/man/man1/xmllint.1.gz
/usr/share/man/man3/libxml.3.gz
安装了,可是不好使,废话少说,直接上源码的
#wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz
#tar xf libxml2-29.0.tar.gz
#cd libxml2-2.9.0
#./configure --prefix=/usr/local/libxml
#make && make install
此过程可能会出现各种警告,请自行忽略
重新编译
../configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd  --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/local/libxml2/ --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
#make
#make install

wKioL1MuLbezA_AFAAKM_LHv18U148.jpg

3、修改配置文件
# cp php.ini-production /etc/php.ini
4、配置php-fpm
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
cd php-5.4.26
# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on

wKiom1MuLnKji68YAACF1BN01Lw927.jpg

5、为php-fpm提供配置文件:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):

wKioL1MuLnChJofXAAHZG9_Hk-E610.jpg

本次实验用的到参数说明

wKiom1MuLq2iaAadAAI6Wux3rG0739.jpg

6、接下来就可以启动php-fpm了:
# service php-fpm start
7、默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验正其是否已经监听在相应的套接字。
#ss -tunl |grep ":9000"

wKioL1MuLtewDrCOAABkh6Mgrzg436.jpg

此次实验所使用的地址与端口
8、而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
在192.168.1.10上的/www/essun.com/
#vim index.php

测试页面index.php示例如下

<?php
     $link = mysql_connect('192.168.1.30','root','mysql');
     if ($link)
       echo "Success...";
     else
       echo "Failure...";
     mysql_close();
   ?>

测试结果

wKiom1MuL27zq7A4AABCKQertO8794.jpg

证明与mysql连接成功。
下面将使用phpMyAdmin-4.0.5-all-languages连接管理数据,同时对此站点进行压力测试
将下载后的包放到192.168.1.10php处理器的站点目录中
下载地址:
#wget    http://ncu.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.10/phpMyAdmin-4.0.10-all-languages.zip
# unzip  phpMyAdmin-4.0.10-all-languages.zip
 #cd phpMyAdmin-4.0.10-all-languages
 #mv * /www/essun.com/

访问www.essun.com

wKiom1MuL-XxvcaDAAHqffJSvtI832.jpg

对其压力测试

#ab -c 100 -n 1000 http://essun.com/

wKiom1MuMCaRlsqMAAMLbOLu3C8182.jpg

四、安装xcache,为php加速

1、下载地址

#wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.bz2

2、编译安装

# tar xf xcache-3.0.3.tar.gz
# cd xcache-3.0.3
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install


wKioL1MuMSHCFfKHAAEq7iaP0f0033.jpg

将编译生成的shared extensions后面的数据写入配置文件中,

找到zend_extension开头的行,修改为如下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位

wKioL1MuMbaz9XFFAAD-GIK3dJY431.jpg

查看xcache是否安装成功
在/www/esun.com/下新建一个目录为test,在其下测试页面
<?php
phpinfo();
?>

结果是

wKioL1MuMm3Rpar4AAHh1QRscMc635.jpg

安装XCache成功
再次测试:
wKioL1MuMqLwqthMAAJrRRaKtqQ052.jpg

明显比上一次测试响应的要快的多

==========================================到此LAMP编译与性能测试完成======================