首页 > 其他 > 详细

fastcgi模式实现 LAMP

时间:2014-03-30 05:08:26      阅读:691      评论:0      收藏:0      [点我收藏+]

(一) LAMP组成部分及各部分通信方式


bubuko.com,布布扣


(二)LAMP分层架构

#由于apache,php,mysql属于密集型服务器,占用cpu和I/O 建议分层


bubuko.com,布布扣


(三)服务器规划

bubuko.com,布布扣

(四)安装Mysql httpd php


#注意:mysql、httpd的安装一定要在php之前,至于mysql和httpd无先后顺序

    【安装Mysql】



使用二进制程序包安装
1创建逻辑卷,用来存放mysql数据
#fdisk /dev/sda
#n ->e ->回车->回车->n->回车—>+10G->t->3->8e->w 保存退出
#partx -a /dev/sda 生成磁盘分表
#pvcreate /dev/sda3 创建物理卷
#vgcreate myvg /dev/sda3 创建卷组myvg
#lvcreate -L 4G -n mydata myvg 创建逻辑卷mydata


2创建目录,并将逻辑卷挂载上去
#mkdir /mydata/data
#vim /etc/fstab

bubuko.com,布布扣


#mount -a 挂载所有
#mount    查看当前所有已经挂载设备


bubuko.com,布布扣


3创建系统用户及系统组,保证mysql的使用安全
#groupadd -r mysql
#useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data
#chown mysql:mysql /mydata/data 更改数据目录的属主属组



4 解压mysql二进制包 并初始化数据库文件
#tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local 解压包到该目录
#cd /usr/local
#ln -sv mysql-5.5.33-linux2.6-x86_64 mysql 创建软连接
#cd /usr/local/mysql
#chown -R mysql:mysql ./*  更改mysql下的所有文件的属组属组为mysql
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data 生成数据库文件
#chown -R root ./*  将文件属主更改为root,下边需要文件的root权限
#ll /mydata/data 可查看到test mysql performance_schema三个数据库文件

bubuko.com,布布扣


5提供mysql的脚本
#cd /usr/local/mysql/support-files
#cp mysql.server /etc/rc.d/init.d/mysqld 脚本存在于二进制包中
#chkconfig --add mysqld                  添加进程为系统进程
#chkcofnig mysqld on                     开机启动服务器进程
#chkconfig --list mysqld                 查看服务进程状态



6 为mysql脚本提供配置文件
#cd /usr/local/mysql/support-files
#cp my-large.cnf /etc/my.cnf       脚本的配置文件也在二进制包中
#vim /etc/my.cnf                   编辑配置文件

bubuko.com,布布扣


7 启动服务进程,侦听端口
#service mysqld start
#ss -ntl |grep ":3306"

bubuko.com,布布扣



8 导出二进制程序,导出库文件,导出头文件,导出man帮助手册
(1)导出二进制程序
#echo ‘export PATH=/usr/local/mysql/bin:$PATH ‘ > /etc/profile.d/mysql.sh
#. /etc/profile.d/mysql.sh
(2)导出库文件
#echo ‘/user/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
#ldconfig
(3)导出头文件
#ln -sv /usr/local/mysql/include /usr/include/mysql
(4)导出man帮助手册
#echo ‘MANPATH /usr/local/mysql/man‘ >> /etc/man.config
#man -M /usr/local/mysql/man mysqld


    【编译安装httpd】



安装需要的软件包
apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
httpd-2.4.9.tar.bz2
下载
#wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2
#wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.3.tar.bz2
#wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.0.tar.bz2

bubuko.com,布布扣

依赖关系
#Development tools|Server Platform Development:gcc编译环境包组
#pcre-devel :perl正则表达式库开发包
#apr: 全称为apache portable runtime,能实现httpd跨平台运行的包


1解决httpd依赖关系
#yum -y gruopinstall "Development tools" "Server Platform Development"
#yum -y install "pcre-devel"
编译安装apr
#tar xf apr-1.5.0.tar.bz2
#cd apr-1.5.0
#./configure --prefix=/usr/local/apr
#make && make install
编译安装apr-util
#tar xf arp-util-1.5.3.tar.bz2
#cd apr-util-1.5.3
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && install



2 安装httpd
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./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 --enables-modules=most --enable-mpms-shared=most --with-mpm=event
# make && make install


编译参数详解
各编译参数详解
--prefix:    #安装路径
--sysconfdir:#指定配置文件路径
--enable-so: #DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可以实现https访问
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite: #启用rewrite功能
--enable-deflate: #支持压缩
--with-zlib:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找
--with-apr: #指定apr安装路径
--with-apr-util: #指定apr-util安装路径
--enable-modules:#支持动态启用的模块,可选参数有“all”,“most”,“few”,“reallyall”
--enable-mpms-shared:#支持动态加载的MPM模块,可选“all”
--with-mpm:#设置默认启用的MPM模式



3 提供httpd服务脚本
编译安装默认没有服务脚本
# vim /etc/rc.d/init.d/httpd
脚本内容如下
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve #        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
                                                                                                                                                                         
# 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/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
                                                                                                                                                                         
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
                                                                                                                                                                         
stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $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=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
                                                                                                                                                                         
# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac
                                                                                                                                                                         
exit $RETVAL



4 编辑配置文件 添加pidfile路径
# vim /etc/httpd/httpd.conf
# 内容如下
# Pidfile  "/var/run/httpd.pid"
# pidfile介绍
# (1) pid文件的内容:pid文件为文本文件,内容只有一行, 记录了该进程的ID用cat命令可以看到。
# (2) pid文件的作用:防止进程启动多个副本。只有获得pid文件(固定路径固定文件名)写入权限(F_WRLCK)的进程才能正常启动并把自身的PID写入该文件中。其它同一个程序的多余进程则自动退出


bubuko.com,布布扣



5 添加httpd进程到系统服务进程,并启动
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd
# service httpd start
# ss -tnl | grep ":80"


bubuko.com,布布扣


6 后续操作 导出头文件,导出man帮助手册,导出二进制程序
#注意:编译安装默认没有库文件
导出二进制程序
#echo ‘export PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.d/httpd.sh
#. /etc/profile.d/httpd.sh
导出头文件 创建软连接即可
# ln -sv /usr/local/apache/include /usr/include/httpd
导出man帮助手册
# echo ‘MANPATH /usr/local/apache/man‘
# man -M /usr/local/apache/man httpd


    【编译安装fpm-php】

     

     

1 配置好epel源和本地yum源
  解决依赖关系
# yum -y groupinstall "Desktop Platform Development"
# yum -y bzip2-devel mcrype-devel mhash-devel


   

2 安装编译php
# tar xf php-5.4.26.tar.bz2
# cd /php-5.4.26
# ./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 --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
# make
# make install

 

   配置php-fpm


1 为php提供配置文件
# cd /php-5.4.26
# cp php.ini-produciton /etc/php.ini


   

2 为php-fpm提供服务启动脚本(编译安装默认不会生成)
# 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      将php-fpm进程添加为系统服务进程
# chkconfig php-fpm on         开机启动
# chkconfig --list php-fpm     查看启动情况


   

3 为php-fpm脚本提供配置文件
# cp /usr/local/php/php-fpm.conf.default /usr/local/php/php-fpm.conf
  编辑php-fpm配置文件
# vim /usr/local/php/php-fpm.conf
  配置线程池并提供pid
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid


   

4 启动php-fpm服务进程
# service php-fpm start
# ps aux | grep php-fpm
































本文出自 “西风瘦猪” 博客,转载请与作者联系!

fastcgi模式实现 LAMP,布布扣,bubuko.com

fastcgi模式实现 LAMP

原文:http://jungege.blog.51cto.com/4102814/1386543

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!