设为首页 收藏本站
查看: 906|回复: 0

LAMP环境的搭建(fastcgi)+ xcache加速

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-3 10:31:48 | 显示全部楼层 |阅读模式

[url=]LAMP环境的搭建(fastcgi)[/url]

LAMP简介:

LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器。

[url=]Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.[/url]


为什么要使用源码安装:


                  理由

                 1.更新的版本  httpd   mysql  php

                 2.提高性能

                      3.自定义参数                          

apache  和 php的结合方式:

                     1.模块      libphp5.so                                             2.cgi      通用网关接口

                     3.fastcgi   快速cgi


下面我们使用fastcgi的方式实现apache和php的结合:


Linux环境  :        centos 6.4  版本号2.6.32-431.el6.i686  

32位操作系统

软件包       httpd-2.4.9.tar.bz2

            php-5.5.8.tar.bz2

mysql-5.6.15.tar.gz

apr-1.4.6.tar.gz

apr-util-1.5.1.tar.gz



预编译环境   :   Development tools

                  Server Platform Development

                  Additional Development

                  cmake

MySQL的安装:


mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要)

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

我的mysql目录配置如下:

安装路径:/usr/local/mysql

数据库路径:/usr/local/mysql/data

源码包存放位置:/usr/local/src

[iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media groupinstall "Development tools"  "Server Platform Development" –y

[iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media  remove  mysql-libs  -y                    (※ 卸载掉预安装的mysql的lib库文件)

[iyunv@vbird ~]# yum --disablerepo=* --enablerepo=c6-media  install cmake -y

[iyunv@vbird ~]# tar -zxvf mysql-5.6.15.tar.gz  -C  /usr/local/src/

[iyunv@vbird ~]# cd /usr/local/src/mysql-5.6.15/

[root@vbirdmysql-5.6.15]#[url=]cmake [/url]

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

-DMYSQL_DATADIR=/usr/local/mysql/data

-DSYSCONFDIR=/etc

-DWITH_MYISAM_STORAGE_ENGINE=1

-DWITH_INNOBASE_STORAGE_ENGINE=1  

-DWITH_MEMORY_STORAGE_ENGINE=1

-DMYSQL_TCP_PORT=3306  

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock

-DENABLED_LOCAL_INFILE=1  

-DWITH_PARTITION_STORAGE_ENGINE=1  

-DEXTRA_CHARSETS=all  

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8_general_ci

[iyunv@vbird mysql-5.6.15]# make && make install


来到MySQL的安装路径/usr/local/mysql下根据INSTALL-BINARY文件来完成MySQL的安装


[iyunv@vbird ~]# cd /usr/local/mysql/

[iyunv@vbird mysql]# vim INSTALL-BINARY




[iyunv@vbird mysql]# groupadd mysql

[iyunv@vbird mysql]# useradd -r -g mysql mysql

[iyunv@vbird local]# cd mysql/

[iyunv@vbird mysql]# chown -R mysql:mysql .

[iyunv@vbird mysql]# ./scripts/mysql_install_db  --user=mysql

[iyunv@vbird mysql]# chown -R root .

[iyunv@vbird mysql]# chown -R mysql data

MySQL的后续处理

拷贝MySQL的配置文件到/etc目录下

[iyunv@vbird mysql]# cp my.cnf  /etc

拷贝MySQL的控制脚本文件到/etc/init.d/目录下

[iyunv@vbird mysql]# cd support-files/

[iyunv@vbird support-files]# cp -p mysql.server  /etc/init.d/mysqld                           

编辑环境预配置文件添加MySQL的搜索路径

[iyunv@vbird ~]# vim /etc/profile

PATH=$PATH:/usr/local/mysql/bin

[iyunv@vbird ~]# . /etc/profile

   给MySQL设置管理口令

[iyunv@vbird ~]# mysqladmin -u root -p password '123'

   设置开机自动启动

[iyunv@vbird ~]# chkconfig --add mysqld

[iyunv@vbird ~]# chkconfig mysqld on

   库文件的处理

[iyunv@vbird ~]# vim /etc/ld.so.conf.d/mysql.conf

[iyunv@vbird ~]# ldconfig                           #刷新缓存

[iyunv@vbird ~]# ldconfig -pv |grep mysql           #查看是否加载

   头文件的处理

[iyunv@vbird ~]# cd /usr/include/

[iyunv@vbird include]# ln -s /usr/local/mysql/include/    mysql


MySQL手册的处理

[iyunv@vbird ~]# vim /etc/man.config

MANPATH /usr/local/mysql/man


apache的安装:


  为了方便apache的运行,需要搭建apache的可移植性运行环境,就需要额外使用两个包apr  apr-util

解压缩包到/usr/local/src

[iyunv@vbird ~]# tar -zxvf  apr-1.4.6.tar.gz  -C /usr/local/src/

[iyunv@vbird ~]# tar -zxvf  apr-util-1.5.1.tar.gz  -C /usr/local/src/

[iyunv@vbird ~]# tar -jxvf  httpd-2.4.9.tar.bz2  -C /usr/local/src/

安装apr

[iyunv@vbird ~]# cd /usr/local/src/apr-1.4.6/

[iyunv@vbird apr-1.4.6]# ./configure  --prefix=/usr/local/apr

[iyunv@vbird apr-1.4.6]# make && make install

安装apr-utils

[iyunv@vbird ~]# cd /usr/local/src/apr-util-1.5.1/

[iyunv@vbird apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils  --with-apr=/usr/local/apr/bin/apr-1-config

[iyunv@vbird apr-util-1.5.1]# make && make install

安装httpd

[iyunv@vbird ~]# cd /usr/local/src/httpd-2.4.9/

[iyunv@vbird httpd-2.4.9]# yum --disablerepo=* --enablerepo=c6-media install pcre-devel -y

[iyunv@vbird httpd-2.4.9]# ./configure  

--prefix=/usr/local/apache

--sysconfdir=/etc/httpd

--enable-so

--enable-ssl  

--enable-rewrite  

--with-apr=/usr/local/apr/bin/apr-1-config

--with-apr-util=/usr/local/apr-utils/bin/apu-1-config

--with-pcre  

--with-z  

--enable-mpms-shared=all

--enable-proxy      

--enable-proxy-fcgi

[iyunv@vbird httpd-2.4.9]# make && make install

httpd的后续处理

编辑环境预配置文件添加httpd的搜索路径

[iyunv@vbird ~]# vim /etc/profile

PATH=$PATH:/usr/local/apache/bin

[iyunv@vbird ~]# . /etc/profile

头文件的处理

[iyunv@vbird ~]# cd /usr/include/

[iyunv@vbird include]# ln -s /usr/local/apache/include/   apache

httpd手册的处理

[iyunv@vbird ~]# vim /etc/man.config

MANPATH /usr/local/apache/man

编辑httpd的控制脚本

[iyunv@vbird init.d]# vim /etc/init.d/httpd

[url=]#!/bin/bash[/url]

prog=/usr/local/apache/bin/httpd

lockfile=/var/lock/subsys/httpd

# description: the httpd server

# chkconfig:   2345 88 44

start() {

if [ -e $lockfile ];then

    echo "the httpd server is started"

else

    echo -n "the httpd server is starting"

    sleep 1

    $prog -k start && echo –e "         ok" && touch $lockfile || echo "failed"

fi

}

stop() {

if [ ! -e $lockfile ];then

    echo "the httpd server is stopped"

else

    echo -n "the httpd server is stopping"

    sleep 1

    $prog -k stop && echo –e "         ok" && rm -rf $lockfile || echo "failed"

fi

}

case "$1"  in

start)

  start

;;

stop)

  stop

;;

restart)

  stop

  start

;;

*)

  echo "USAGE:start|stop|restart"

;;

esac


[iyunv@vbird init.d]# chkconfig --add httpd


PHP的安装:

先安装php所需的devel包

[iyunv@vbird php-5.5.8]# [url=]yum --disablerepo=* --enablerepo=c6-media install libxml2-devel libjpeg-turbo-devel libpng-devel  freetype-devel  -y[/url]

解压缩包到/usr/local/src

[iyunv@vbird ~]# tar -jxvf php-5.5.8.tar.bz2  -C /usr/local/src/

[iyunv@vbird ~]# cd /usr/local/src/php-5.5.8/

[iyunv@vbird php-5.5.8]# ./configure   

--prefix=/usr/local/php

--enable-fpm   

--enable-sockets  

--with-mysql=/usr/local/mysql

--with-pdo-mysql=/usr/local/mysql

--with-mysqli=/usr/local/mysql/bin/mysql_config  

--enable-mbstring  

--enable-xml  

--with-png-dir

--with-gd   

--with-jpeg-dir  

--with-zlib  

--with-freetype-dir

--with-config-file-path=/etc/php

--with-config-file-scan-dir=/etc/php5.d



[iyunv@vbird php-5.5.8]# make && make install

php的后续处理

创建php的配置文件目录php和额外扩展配置文件目录php5.d

[iyunv@vbird ~]# mkdir -pv /etc/php /etc/php5.d

[iyunv@vbird ~]# cd /usr/local/src/php-5.5.8/

[iyunv@vbird php-5.5.8]# cp php.ini-production /etc/php/php.ini

来到/usr/local/php/etc目录下通过php-fmp的默认配置文件生成php-fmp的配置文件

[iyunv@vbird etc]# cp php-fpm.conf.default php-fpm.conf

来到/usr/local/src/php-5.5.8/sapi/fpm目录下,拷贝php的控制脚本到/etc/init.d目录下并给它可执行权限

[iyunv@vbird fpm]# cp init.d.php-fpm  /etc/init.d/php-fpm

[iyunv@vbird fpm]# chmod a+x /etc/init.d/php-fpm

使用chkconfig管理

[iyunv@vbird fpm]# chkconfig --add php-fpm

[iyunv@vbird fpm]# chkconfig php-fpm  on


由于php和apache是用fcgi结合起来的,编辑apache的配置文件/etc/httpd/httpd.conf加载mod_proxy.so和mod_proxy_fcgi.so模块


在httpd.conf  加入  AddType application/x-httpd-php .php和AddType application/x-httpd-php-source  .phps指明.php文件和.phps文件的处理类型


添加.php类型的默认首页


关闭正向代理功能,启动反向代理,把URI为^/(.*.php)$形式的请求反向代理到fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1


重新启动httpd,mysqld,hph-fpm服务


在apache的默认站点目录下编辑一个默认.php类型的首页,做一下php和httpd的连接测试

[iyunv@vbird ~]# cd /usr/local/apache/htdocs/

[iyunv@vbird htdocs]# vim index.php


可以看到php的各种参数,连接成功


更改index.php的内容测试php和MySQL的连接情况



可以看到连接成功



搭建phpwind应用测试LAMP环境  这里我使用物理目录

[iyunv@vbird ~]# unzip phpwind_v9.0_gbk.zip

[iyunv@vbird ~]# cd phpwind_v9.0_gbk

[root@vbirdphpwind_v9.0_gbk]#mv upload  /usr/local/apache/htdocs/phpwind

使用浏览器访问http://192.168.2.100/phpwind可以看到出现了phpwind的安装向导




点击下一步可以看到环境检测没问题


来到phpwind目录下更改文件权限

[iyunv@vbird htdocs]# cd phpwind/

[iyunv@vbird phpwind]# chmod  -R o+w attachment/ conf/  data/ html/ src/ themes/ windid/


创建数据


安装完成后成功进入站点


压力测试

Apache HTTP Web 服务器提供了一个叫做 ab 的工具,即 Apache HTTP 服务器性能检测(benchmark)工具的缩写。ab 用于为 PHP 页面自动化处理大量的请求

对静态页面index.html进行压力测试  可以看到只有每秒800左右

[iyunv@vbird ~]# ab -n 10000 -c 1000  http://192.168.2.100/index.html


对动态页面index.php进行压力测试  可以看到只有每秒300左右

[iyunv@vbird ~]# ab -n 1000 -c 500 http://192.168.2.100/index.php


与其他开发 Web 应用程序的脚本语言(包括 Perl、Python 和 Ruby)相似,每次 HTTP 请求调用时,PHP 代码都会被解析和翻译为操作码(PHP 引擎直接执行的原语指令 —— 类似于汇编语言)再执行。在要求很低或可忽略的情况下,服务器看上去能立即执行这个复杂的解释过程。但是一旦处理的页面增加,解释 —— 从本质上说,重复工作 —— 就会对服务器造成很大的负担。在某些情况下,“编译” PHP 代码的时间会远远超过执行该代码所需的时间。节约 CPU 周期的另一种方法是减少运行 PHP 应用程序所需的重复工作。当然,没有必要每次都把同样的 PHP 代码翻译一遍。PHP 代码被翻译成操作码后,可以把它保存起来并重复使用 —— 直到原始代码被修改。确实,缓存 —— 用于保存和重用 PHP 操作码 —— 是几种 PHP 加速器内部的机制,包括开源 Alternative PHP Cache (APC)、支持 PHP 的 Turck MMCache、XCache、eAccelerator 和商业 Zend Platform。后三类加速器能够缓存和优化字节码,这为系统提供了更多的速度提升。

下面我们使用xcache对php进行缓存

安装xcache:

[iyunv@vbird ~]# tar -zxvf xcache-3.1.0.tar.gz -C /usr/local/src/

[iyunv@vbird ~]# cd /usr/local/src/xcache-3.1.0/

[iyunv@vbird xcache-3.1.0]# vim INSTALL


使用phpize把xcache作为php的扩展

[iyunv@vbird xcache-3.1.0]# /usr/local/php/bin/phpize

[iyunv@vbird xcache-3.1.0]# ./configure  

--enable-xcache

--with-php-config=/usr/local/php/bin/php-config

[iyunv@vbird xcache-3.1.0]# make && make install

来到下面目录下把xcache的扩展模块xcache.so模块拷到php的扩展配置文件/etc/php5.d/下

cd /usr/local/php/lib/php/extensions/no-debug-zts-20121212/

[iyunv@vbird no-debug-zts-20121212]# cp xcache.so /etc/php5.d/

拷贝xcache的配置模板xcache.ini到php的扩展配置文件/etc/php5.d

[iyunv@vbird xcache-3.1.0]# cp xcache.ini /etc/php5.d/


Xcache安装完成后重新启动httpd服务

我们接着来作压力测试看看xcache的效果

对静态页面index.html进行压力测试  可以看到只有每秒1300左右

[iyunv@vbird ~]# ab -n 10000 -c 1000  http://192.168.2.100/index.html



对动态页面index.php进行压力测试  可以看到只有每秒800左右

[iyunv@vbird ~]# ab -n 1000 -c 500 http://192.168.2.100/index.php




可以看到xcache缓存对php站点的响应速度有了很大的提升!



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-26931-1-1.html 上篇帖子: LAMP环境的搭建(模块)+ xcache缓存 下篇帖子: CentOS 6.6安装配置LAMP服务器(Apache+PHP5+MySQL)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表