源码编译安装分离式LAMP平台

LAMP是指:Linux(操作系统),Apache(Web服务器),MySQL/MariaDB(数据库),PHP/Perl/Python(脚本语言),所有组成产品各自独立的开源软件,组合在一起使用,就组成了目前互联网中流行的Web框架;与Java/J2EE架构相比,LAMP具有Web资源丰富,轻量,开发快速等特点,与微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。

工作原理:

源码编译安装分离式LAMP平台

分离式的LAMP架构,Apache,Mysql/MariaDB,PHP都部署在独立的服务器上,静态资源放在web服务器上,动态的页面放在php服务器上。

客户端请求访问Web站点,Web服务器接收用户的访问请求,如果是静态页面直接返回结果,如果是动态页面,则Web服务器通过FastCGI协议将动态页面交由php服务器处理,PHP服务器对动态页面的处理需要与数据库进行交互。处理完成之后,PHP服务器将处理结果交给Web服务器,由Web服务器向客户端返回结果。

实验案例:构建分离式LAMP平台;

(1)、

站点A:pma.chencer.org,PhpMyAdmin管理MySQL程序站点,使用https协议通信;

站点B:blog.chencer.org, Wordpress论坛站点;

(2)、PHP-fpm服务器部署xcache实现加速。

实验过程:

编译安装httpd:

系统版本:CentOS 6.6x86_64;

服务器IP:192.168.1.10;

httpd源码包:httpd-2.4.16.tar.bz2;

apr源码包:apr-1.5.2.tar.bz2;

apr-util源码包:apr-util-1.5.4.tar.bz2

官网:

安装编译环境:
# yum groupinstall "Server Platform Development" "Developmenttools"

apr:
# tar xf apr-1.5.2.tar.bz2
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install

apr-util:       
# tar xf apr-util-1.5.4.tar.bz2
# cdapr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
# make && make install
    --with-apr=/usr/local/apr/    :指明apr安装位置;

httpd:
# tar xf httpd-2.4.16.tar.bz2
# cd httpd-2.4.16
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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=all--enable-mpms-shared=all --with-mpm=event
# make && make install

httpd编译参数解释:
> --prefix=/usr/local/apache    :安装位置;
> --sysconfdir=/etc/httpd    :配置文件位置;
> --enable-so    :支持DSO动态装载模块;
> --enable-ssl    :支持SSL/TLS,可实现https协议访问,需要安装openssl-devel;
> --enable-cgi    :支持CGI脚本;
> --enable-rewrite    :支持URL重写;
> --with-zlib    :使用指定的zlib压缩库,不指定路径会自动寻找;
> --with-pcre    :使用指定的pcre库,增强的正则表达式分析工具;不指定路径会自动寻找 需已安装pcre-devel;
> --with-apr=/usr/local/apr    :指定依赖apr程序安装位置;
> --with-apr-util=/usr/local/apr-util    :指定依赖apr-util程序安装位置;
> --enable-modules=all    :支持动态启用模块;all:所有,most:常用;
> --enable-mpms-shared=all    :编译并共享模块;
> --with-mpm=event    :默认启用模块;{prefork|worker|event}

添加,并重读环境变量:
# vim /etc/profile.d/httpd.sh
> export PATH=/usr/local/apache/bin:$PATH
# source /etc/profile.d/httpd.sh

导出头文件:
# ln -sv /usr/local/apache/include/ /usr/include/httpd

导出man手册:
# vim /etc/man.config
> MANPATH /usr/local/apache/man

修改主配置文件指定pidfile:
# vim /etc/httpd/httpd.conf
> PidFile"/usr/local/apache/logs/httpd.pid"

提供服务脚本:可使用rpm包安装提供的脚本修改使用;
# vim/etc/rc.d/init.d/httpd
> #!/bin/bash
> #
> # httpd        Startup script for the Apache HTTPServer
> #
> # 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
> #
> ### BEGININIT 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 INITINFO
>
> # Source functionlibrary.
> ./etc/rc.d/init.d/functions
>
> if [ -f/etc/sysconfig/httpd ]; then
>        . /etc/sysconfig/httpd
> fi
>
> # Starthttpd in the C locale by default.
> HTTPD_LANG=${HTTPD_LANG-"C"}
>
> # This willprevent initlog from swallowing up a pass-phrase prompt if
> # mod_sslneeds a pass-phrase from the user.
> INITLOG_ARGS=""
>
> # SetHTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
> # with thethread-based "worker" MPM; BE WARNED that some modules may not
> # workcorrectly with a thread-based MPM; notably PHP will refuse to start.
>
> # Path tothe 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-/usr/local/apache/logs/httpd.pid}
> lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> RETVAL=0
> STOP_TIMEOUT=${STOP_TIMEOUT-10}
>
> # Thesemantics of these two functions differ from the way apachectl does
> # things --attempting to start while running is a failure, and shutdown
> # when notrunning is also a failure.  So we just doit the way init scripts
> # areexpected to behave here.
> start() {
>        echo -n $"Starting $prog: "
>        LANG=$HTTPD_LANG daemon--pidfile=${pidfile} $httpd $OPTIONS
>        RETVAL=$?
>        echo
>        [$RETVAL = 0 ] && touch ${lockfile}
>        return $RETVAL
> }
>
> # Whenstopping httpd, a delay (of default 10 second) is required
> # beforeSIGKILLing the httpd parent; this gives enough time for the
> # httpdparent 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 toconfiguration syntax error"
>        failure $"not reloading $httpd dueto 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 wewere 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

脚本执行权限;
# chmod +x /etc/rc.d/init.d/httpd

添加服务,启动服务;
# chkconfig httpd –add
# chkconfig httpd on
# service httpd start

访问测试:

源码编译安装分离式LAMP平台

编译安装PHP-fpm:

系统版本:CentOS 6.6x86_64;

服务器IP:192.168.1.11

php源码包:php-5.4.43.tar.bz2;

官网:

安装编译环境;
# yum groupinstall "Server Platform Development" "Developmenttools" "Desktop Platform Development"

安装依赖关系程序:
# yum install bzip2-devel libmcrypt-devel mhash-devel
    注意:libmcrypt-devel和mhash-devel来自于epel源;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/057c2b7603c27b5e8dfcf9e1e1fd5a16.html