编译安装LAMP及分离式LAMP平台构建
前言
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端口是否被监听
所需软件包: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
[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
[root@MariaDB mysql]# vim /etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH[root@MariaDB mysql]# source /etc/profile.d/mysql.sh
[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
所需安装包: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
[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 #最大空闲子进程数
到此为止,各软件算是编译安装完了,我们通过一个实例让他们工作起来
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)
[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 #启用虚拟主机
<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>
[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。
[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" #私钥位置
将CA证书导出,重命名为*.crt格式,安装在受信任的根证书颁发机构中,测试https
OK,登陆成功,可以管理数据库啦,至此,基于https的加密通信部署完成
最后,我们补充讲解一下xcache,xcache是一个开源的 opcode 缓存器/优化器,它可以提高php的性能,加快页面生成速率,从而降低服务器负载。
为了比较加速前后的效果,在安装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
[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
转载于:https://blog.51cto.com/scholar/1635834
编译安装LAMP及分离式LAMP平台构建相关推荐
- LAMP源码编译安装及一键部署LAMP架构
文章目录 一.什么是LAMP? 1.LAMP平台概述 2.构建LAMP平台顺序 3.编译安装的优点 4.各组件的主要作用 二.LAMP架构流向 三.编译安装Apache服务 1.先关闭防火墙 2.将软 ...
- 编译安装postfix+sasl+mysql+dovecot+extmail构建完成的邮件系统(一)
编译安装postfix 在之前的文章我增提到过,目前linux常用的MTA软件有sendmail,qmail,exim,postfix.虽然目前使用最多的MTA是sendmail,但是sendmail ...
- LAMP源码编译安装之Apache
LAMP源码编译安装之Apache 一.LAMP的基本架构概述 1.LAMP架构 2.各组件的主要作用如下 二.编译安装Apache httpd服务 1.关闭防火墙,将安装Apache所需软件包传到/ ...
- Linux高级实战部署--LNMP生产环境部署(mysql,nginx,php编译安装,项目部署)
LNMP生产环境部署 一.编译安装 MySQL MySQL 类型 #### 1.MySQL Community Server - MySQL Community Server是社区版本,开源免费,但不 ...
- 编译安装nginx1.9.7+php7.0.0服务器环境
编译安装nginx1.9.7+php7.0.0服务器环境 一直以来我都通过网上的一些材料去搭建lnmp环境,通过直接yum安装nginx mysql php等软件. 但是为了原生态的编译安装最新的软件 ...
- 编译安装php apache,CentOS编译安装Apache2.4+PHP5.6
CentOS下YUM安装PHP和Apache是比较简单的,可是一般默认情况下的PHP版本是5.3,Apache版本是2.2.因为考虑到PHP版本和Apache版本越高性能越好,就打算在CentOS下编 ...
- voltdb编译安装
参考: https://blog.csdn.net/u010817321/article/details/52118254 https://blog.csdn.net/u011569805/artic ...
- 源码编译安装部署LAMP平台(使用Apache,MySQL与PHP搭建Discuz论坛实例)
文章目录 一.LAMP平台与编译安装 (一).LAMP平台概述 (二).构建LAMP平台顺序 (二).编译安装的优点 (三).各组件的主要作用 二.部署步骤 (一).编译安装Apache httpd服 ...
- 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 ...
最新文章
- XP 的共享方案(面对新人)
- 数据结构和算法分析: 第五章 散列
- 有关软件测试的证书,软件测试证书有用吗
- spring学习(46):spring的单例bean
- 主席树【bzoj3524(p3567)】[POI2014]Couriers
- 俄罗斯调查PC厂商合谋操纵市场 联想被指妨碍调查
- 鲁大师检测内存条_外观漂亮,做工精致,潜力巨大、十铨(Team)8GB×2 3200Mhz台式机内存条 火神系列 评测...
- mysql concat 能否返回数字_关于Mysql中GROUP_CONCAT函数返回值长度的坑
- 4am永远 鼠标按键设置_罗技G502 LIGHTSPEED无线游戏鼠标评测 性能超乎想象
- linux kylin 终端字体,安装Nerd Fonts字体
- USB-SC-09(假冒PL2303HXA芯片)WIN7-64位驱动之终极大法
- uni-app/小程序 DCloud appid 说明
- 彻底解决IE9 文本框无法输入文字,IE窗口闪烁问题(亲测)
- linux 目录防篡改,Linux服务器下如何创建文件防篡改规则
- 冯扬文:新冠疫情下国际航运市场趋势分析
- el元素与jstl标签
- 安装debugserver到iPhone上
- 五大基本算法及其经典问题
- QUECTEL上海移远4G通讯CAT4模组EC20CEFAG模块串口调试指南之02EC20模组硬件供电和开关机复位操作
- js点击轮播或者自动轮播图代码