前言

LAMP网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网站服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,与微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。但由于MySQL作为SUN公司的附属品已被Oracle收购,以后是否还会继续开源,这个鬼才知道,所以CentOS7上开始采用MySQL的分支MariaDB,估计以后在LAMP中MariaDB也会取代MySQL。

工作原理

编译安装LAMP

编译安装httpd

系统环境:CentOS6.6

作为web服务器:172.16.10.100

所需软件包:apr-1.5.0.tar.bz2、apr-util-1.5.3.tar.bz2、httpd-2.4.9.tar.bz2

注意:httpd2.4需要依赖apr和arp-util 1.4以上版本

解决依赖关系

[root@scholar ~]# yum groupinstall Development tools Server Platform Development -y
[root@scholar ~]# yum -y install pcre-devel

编译安装apr和apr-util

[root@scholar ~]# tar xf apr-1.5.0.tar.bz2
[root@scholar ~]# cd apr-1.5.0
[root@scholar apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@scholar apr-1.5.0]# make && make install
[root@scholar apr-1.5.0]# cd ..
[root@scholar ~]# tar xf apr-util-1.5.3.tar.bz2
[root@scholar ~]# cd apr-util-1.5.3
[root@scholar apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/
[root@scholar apr-util-1.5.3]# make && make install

编译安装httpd

[root@scholar apr-util-1.5.3]# cd ..
[root@scholar ~]# tar xf httpd-2.4.9.tar.bz2
[root@scholar ~]# cd httpd-2.4.9
[root@scholar httpd-2.4.9]# ./configure --prefix=/usr/local/apache
--sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi
--enable-rewrite --enable-deflate --with-zlib --with-pcre
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
--enable-mpms-shared=all --with-mpm=event --enable-modules=most
[root@scholar httpd-2.4.9]# make && make install
编译参数详解:
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可实现https访问 需已安装openssl-devel
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能,URL重写
--enable-deflate:#支持压缩功能
--with-zlib:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找 需已安装pcre-devel
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-mpms-shared:#支持动态加载的MPM模块,可选参数:all
--with-mpm:#设置默认启用的MPM模式,{prefork|worker|event}
--enable-modules:#支持动态启用的模块,可选参数:all,most,few,reallyall
#编译之前可使用./configure --help查看各项参数

添加环境变量

为了方便命令使用需要添加环境变量

[root@scholar ~]# vim /etc/profile.d/httpd24.sh  #名字自定义export PATH=/usr/local/apache/bin:$PATH[root@scholar ~]# source /etc/profile.d/httpd24.sh  #重读环境变量

导出头文件

[root@scholar ~]# ln -sv /usr/local/apache/include/ /usr/include/httpd24

导出man手册

[root@scholar ~]# vim /etc/man.config MANPATH /usr/local/apache/man   #添加编译安装的man位置

提供脚本

#!/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
#!/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-/usr/local/apache/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
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 $OPTIONSRETVAL=$?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} $httpdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {echo -n $"Reloading $prog: "if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; thenRETVAL=6echo $"not reloading due to configuration syntax error"failure $"not reloading $httpd due to configuration syntax error"else# Force LSB behaviour from killprocLSB=1 killproc -p ${pidfile} $httpd -HUPRETVAL=$?if [ $RETVAL -eq 7 ]; thenfailure $"httpd shutdown"fifiecho
}start)start;;stop)stop;;status)status -p ${pidfile} $httpdRETVAL=$?;;restart)stopstart;;condrestart|try-restart)if status -p ${pidfile} $httpd >&/dev/null; thenstopstartfi;;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
esacexit $RETVAL

加入服务列表,测试脚本启动服务,查看80端口是否被监听

访问测试,查看是否正常工作

OK,没问题,httpd编译安装完成

安装MariaDB

系统环境:CentOS6.6

作为数据库服务器:172.16.10.211

所需软件包:mariadb-5.5.36-linux-x86_64.tar.gz(二进制格式包)

装备数据存放文件系统

为了安全起见,一般数据库数据是被放在其他磁盘上的,这里我们新建一个逻辑卷,并将其挂载至特定目录即可。

[root@MariaDB ~]# fdisk /dev/sdb
n
p
1+20G
t
8e
w
[root@MariaDB ~]# partx -a /dev/sdb
[root@MariaDB ~]# pvcreate /dev/sdb1
[root@MariaDB ~]# vgcreate myvg /dev/sdb1
[root@MariaDB ~]# lvcreate -L 10G -n mydata myvg
[root@MariaDB ~]# mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /dev/myvg/mydata
[root@MariaDB ~]# mkdir /mydata
[root@MariaDB ~]# vim /etc/fstab
LABEL=MYDATA            /mydata            ext4    defaults,noatime 0 0
[root@MariaDB ~]# mount -a
[root@MariaDB ~]# mkdir /mydata/data

为了安全,新建用户及组,以普通用户运行

解压安装MariaDB,权限修改

提供配置文件,初始化数据库

[root@MariaDB local]# mkdir /etc/mysql
[root@MariaDB local]# cp ./mysql/support-files/my-large.cnf /etc/mysql/my.cnf
[root@MariaDB local]# vim /etc/mysql/my.cnfthread_concurrency = 4   #运行CPU数量乘2
datadir = /mydata/data   #添加行,指明数据文件存放位置[root@MariaDB local]# cd mysql/
[root@MariaDB mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data

提供脚本

加入服务列表,启动服务,查看3306端口是否被监听

添加环境变量

[root@MariaDB mysql]# vim /etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH[root@MariaDB mysql]# source /etc/profile.d/mysql.sh

导出man手册

[root@MariaDB mysql]# vim /etc/man.config MANPATH /usr/local/mysql/man

导出头文件

[root@MariaDB ~]# ln -sv /usr/local/mysql/include  /usr/include/mysql

输出库文件给系统库查找路径

[root@MariaDB ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

测试MariaDB

OK,MariaDB安装完成

编译安装php

系统环境:CentOS6.6

作为php服务器:172.16.10.110

所需安装包:php-5.4.26.tar.bz2、xcache-3.1.0.tar.bz2(非必须,加速软件)

解决依赖关系

[root@scholar ~]#  yum groupinstall Development tools Server Platform Development -y
[root@scholar ~]#  yum -y groupinstall Desktop Platform Development
[root@scholar ~]#  yum -y install bzip2-devel libmcrypt-devel

解压编译

[root@scholar ~]# tar xf php-5.4.26.tar.bz2
[root@scholar ~]# cd php-5.4.26
[root@scholar php-5.4.26]#  ./configure --prefix=/usr/local/php --with-mysql=mysqlnd
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --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 --with-openssl
[root@scholar php-5.4.26]# make && make install

提供配置文件

[root@scholar php-5.4.26]# cp php.ini-production /etc/php.ini

为php-fpm提供脚本

为php-fpm提供配置文件

编辑配置文件

[root@scholar php]# vim etc/php-fpm.conf  #注意文件位置/usr/local/php/etc/pid =/usr/local/php/var/run/php-fpm.pidlisten = 172.16.10.110:9000pm.max_children = 25  #最大子进程数pm.start_servers = 5  #开机预启动子进程数pm.min_spare_servers = 2 #最小空闲子进程数pm.max_spare_servers = 6 #最大空闲子进程数

启动服务,检查9000端口是否被监听

到此为止,各软件算是编译安装完了,我们通过一个实例让他们工作起来

启动LAMP

案例要求:

DNS服务器:172.16.10.10

web服务器:172.16.10.100(已编译安装httpd-2.4.9)

php服务器:172.16.10.110(已编译安装php-5.4.26)

数据库服务器:172.16.10.211(已安装MariaDB-5.5.36)

要求web服务器提供3个站点:www.scholar.com(静态)、admin.scholar.com(动态,phpMyAdmin)、blog.scholar.com(动态、wordpress),站点文件目录分别为:/web/www、/web/pma、/web/blog,其中admin.scholar.com由于是管理数据库的站点,所以必须基于https进行通信。

DNS服务器配置

修改DNS正反向区域文件

正向解析

反向解析

检查语法,重启服务

web服务器配置

启用相关模块

[root@scholar ~]# vim /etc/httpd24/httpd.confLoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

启用虚拟主机

#DocumentRoot "/usr/local/apache/htdocs"   #关闭中心主机Include /etc/httpd24/extra/httpd-vhosts.conf #启用虚拟主机

使之支持php

<IfModule dir_module>DirectoryIndex index.html index.php
</IfModule>AddType application/x-httpd-php  .php
AddType application/x-httpd-php-source  .phps

配置虚拟主机

[root@scholar ~]# vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost *:80>DocumentRoot "/web/www"ServerName www.scholar.com
<Directory "/web/www">Options noneAllowOverride noneRequire all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>DocumentRoot "/web/pma"ServerName admin.scholar.comProxyRequests Off                #关闭正向代理ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.10.110:9000/web/pma/$1 #代理至php服务器
<Directory "/web/pma">Options noneAllowOverride noneRequire all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>DocumentRoot "/web/blog"ServerName blog.scholar.comProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://172.16.10.110:9000/web/blog/$1
<Directory "/web/blog">Options noneAllowOverride noneRequire all granted
</Directory>
</VirtualHost>

站点文件准备

web服务器:

[root@scholar php]# mkdir /web/{pma,blog} -pv  #此为php服务器,不要混淆
mkdir: created directory `/web/pma'
mkdir: created directory `/web/blog'
[root@scholar php]# scp 172.16.10.100:/web/pma/* /web/pma/
[root@scholar php]# scp 172.16.10.100:/web/blog/* /web/blog/
[root@scholar php]# cd /web/pma
[root@scholar pma]# cp config.sample.inc.php config.inc.php
[root@scholar pma]# vim config.inc.php $cfg['blowfish_secret'] = 'a8b7c6dhfgs';$cfg['Servers'][$i]['host'] = '172.16.10.211';[root@scholar pma]# cd ../blog/
[root@scholar blog]# cp wp-config-sample.php wp-config.php
[root@scholar blog]# vim wp-config.php /** WordPress 数据库的名称 */
define('DB_NAME', 'wpdb');/** MySQL 数据库用户名 */
define('DB_USER', 'wpuser');/** MySQL 数据库密码 */
define('DB_PASSWORD', 'wppass');/** MySQL 主机 */
define('DB_HOST', '172.16.10.211');

数据库准备

检查语法,重启服务

测试各站点,访问是否正常

至此,分离式的LAMP就可以统一正常工作了,接下来我们为admin.scholar.com提供https。

生成私钥,提供证书

签署证书,我这里本机就是CA就自签了,CA配置详见博客

启用ssl功能

[root@scholar ssl]# vim /etc/httpd24/httpd.conf LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.soInclude /etc/httpd24/extra/httpd-ssl.conf
[root@scholar ssl]# vim /etc/httpd24/extra/httpd-ssl.conf DocumentRoot "/web/pma"    #站点目录
ServerName admin.scholar.com:443    #启用ssl的站点ProxyRequests Off    #同样关闭正向向代理            ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.10.110:9000/web/pma/$1 #反向代理至php服务器
<Directory "/web/pma">Options noneAllowOverride noneRequire all granted
</Directory>SSLCertificateFile "/etc/httpd24/ssl/httpd.crt"   #证书位置SSLCertificateKeyFile "/etc/httpd24/ssl/httpd.key" #私钥位置

测试语法,重启服务,查看443端口是否被监听

将CA证书导出,重命名为*.crt格式,安装在受信任的根证书颁发机构中,测试https

成功了,我们登陆数据库看一下

OK,登陆成功,可以管理数据库啦,至此,基于https的加密通信部署完成

xcache加速

最后,我们补充讲解一下xcache,xcache是一个开源的 opcode 缓存器/优化器,它可以提高php的性能,加快页面生成速率,从而降低服务器负载。

为了比较加速前后的效果,在安装xcache之前,我们来对现在的服务器进行压力测试

编译安装xcache

[root@scholar ~]# tar xf xcache-3.1.0.tar.bz2
[root@scholar ~]# cd xcache-3.1.0
[root@scholar xcache-3.1.0]# /usr/local/php/bin/phpize
[root@scholar xcache-3.1.0]# ./configure --enable-xcache --with-php-config=
/usr/local/php/bin/php-config
[root@scholar xcache-3.1.0]# make && make install

配置xcache

[root@scholar xcache-3.1.0]# mkdir /etc/php.d
[root@scholar xcache-3.1.0]# cp xcache.ini /etc/php.d/
[root@scholar xcache-3.1.0]# vim /etc/php.d/xcache.ini [xcache-common]
;; non-Windows example:
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

安装成功,重启服务,再次测试

经过xcache加速,响应和传输速度快了好多倍,由此可见,xcache还是很实用的。

The end 

好了,LAMP就先讲解到这里啦,搭建LAMP平台还是挺费时间的,希望本文可以对你有所帮助,部署过程中遇到问题可留言,欲了解更多功能的LAMP,请关注后续文章。以上仅为个人学习整理,如有错漏,大神勿喷~~~

转载于:https://blog.51cto.com/scholar/1635834

编译安装LAMP及分离式LAMP平台构建相关推荐

  1. LAMP源码编译安装及一键部署LAMP架构

    文章目录 一.什么是LAMP? 1.LAMP平台概述 2.构建LAMP平台顺序 3.编译安装的优点 4.各组件的主要作用 二.LAMP架构流向 三.编译安装Apache服务 1.先关闭防火墙 2.将软 ...

  2. 编译安装postfix+sasl+mysql+dovecot+extmail构建完成的邮件系统(一)

    编译安装postfix 在之前的文章我增提到过,目前linux常用的MTA软件有sendmail,qmail,exim,postfix.虽然目前使用最多的MTA是sendmail,但是sendmail ...

  3. LAMP源码编译安装之Apache

    LAMP源码编译安装之Apache 一.LAMP的基本架构概述 1.LAMP架构 2.各组件的主要作用如下 二.编译安装Apache httpd服务 1.关闭防火墙,将安装Apache所需软件包传到/ ...

  4. Linux高级实战部署--LNMP生产环境部署(mysql,nginx,php编译安装,项目部署)

    LNMP生产环境部署 一.编译安装 MySQL MySQL 类型 #### 1.MySQL Community Server - MySQL Community Server是社区版本,开源免费,但不 ...

  5. 编译安装nginx1.9.7+php7.0.0服务器环境

    编译安装nginx1.9.7+php7.0.0服务器环境 一直以来我都通过网上的一些材料去搭建lnmp环境,通过直接yum安装nginx mysql php等软件. 但是为了原生态的编译安装最新的软件 ...

  6. 编译安装php apache,CentOS编译安装Apache2.4+PHP5.6

    CentOS下YUM安装PHP和Apache是比较简单的,可是一般默认情况下的PHP版本是5.3,Apache版本是2.2.因为考虑到PHP版本和Apache版本越高性能越好,就打算在CentOS下编 ...

  7. voltdb编译安装

    参考: https://blog.csdn.net/u010817321/article/details/52118254 https://blog.csdn.net/u011569805/artic ...

  8. 源码编译安装部署LAMP平台(使用Apache,MySQL与PHP搭建Discuz论坛实例)

    文章目录 一.LAMP平台与编译安装 (一).LAMP平台概述 (二).构建LAMP平台顺序 (二).编译安装的优点 (三).各组件的主要作用 二.部署步骤 (一).编译安装Apache httpd服 ...

  9. LAMP(linux下apache+mysql+php)平台编译安装的实现

    实现LAMP编译安装 httpd 2.4.1 + mysql-5.5.19 + php-5.3.10编译安装过程: 一.编译安装apache 1.解决依赖关系 httpd-2.4.1需要较新版本的ap ...

最新文章

  1. XP 的共享方案(面对新人)
  2. 数据结构和算法分析: 第五章 散列
  3. 有关软件测试的证书,软件测试证书有用吗
  4. spring学习(46):spring的单例bean
  5. 主席树【bzoj3524(p3567)】[POI2014]Couriers
  6. 俄罗斯调查PC厂商合谋操纵市场 联想被指妨碍调查
  7. 鲁大师检测内存条_外观漂亮,做工精致,潜力巨大、十铨(Team)8GB×2 3200Mhz台式机内存条 火神系列 评测...
  8. mysql concat 能否返回数字_关于Mysql中GROUP_CONCAT函数返回值长度的坑
  9. 4am永远 鼠标按键设置_罗技G502 LIGHTSPEED无线游戏鼠标评测 性能超乎想象
  10. linux kylin 终端字体,安装Nerd Fonts字体
  11. USB-SC-09(假冒PL2303HXA芯片)WIN7-64位驱动之终极大法
  12. uni-app/小程序 DCloud appid 说明
  13. 彻底解决IE9 文本框无法输入文字,IE窗口闪烁问题(亲测)
  14. linux 目录防篡改,Linux服务器下如何创建文件防篡改规则
  15. 冯扬文:新冠疫情下国际航运市场趋势分析
  16. el元素与jstl标签
  17. 安装debugserver到iPhone上
  18. 五大基本算法及其经典问题
  19. QUECTEL上海移远4G通讯CAT4模组EC20CEFAG模块串口调试指南之02EC20模组硬件供电和开关机复位操作
  20. js点击轮播或者自动轮播图代码

热门文章

  1. forget word a out 1
  2. Linux命令之df
  3. flannel 的连通与隔离 - 每天5分钟玩转 Docker 容器技术(61)
  4. mysql select in 怎么优化
  5. CmsEasy20160825前台无限制GetShell复现
  6. Apache多站点设定
  7. 数据挖掘过程中:数据预处理
  8. UITextField中文搜索
  9. 动态加载jar 并进行调用
  10. 从FTP上下载文件到本地