lamp实验作业详细过程

1、请描述一次完整的http请求处理过程;

由客户端发起请求给服务端,服务端接收到请求后解析http报文内容,把处理完成后的内容反馈给客户端,再将每次请求记录在日志中。

2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。

prefork:多进程模型,一个进程响应一个请求;
worker:多进程多线程模型,一个线程响应一个请求;
event:事件驱动模型,一个进程响应n个请求;

3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。

一、编译安装httpd2.4
(1)编译安装apr-1.5.0,httpd服务依赖于apr跨平台运行环境
[root@httpd apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@httpd apr-1.5.0]# make -j 4 && make install
(2)编译安装apr-util-1.5.2工具包
[root@httpd apr-util-1.5.2]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@httpd apr-util-1.5.2]# make -j 4 && make install
(3)下载安装pcre-devel包,httpd编译时依赖
(4)编译安装httpd2.4.9
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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=most --enable-mpms-shared=all --with-mpm=event
1、--prefix=/usr/local/apache (指定安装路径)
2、--sysconfdir=/etc/httpd24 (系统配置文件路径)
3、--enable-ssl (启动ssl功能)
4、--enable-cgi (启动cgi协议)
5、--enable-rewrite (启动url重写)
6、--with-zlib (启动压缩传输)
7、--with-pcre (支持pcre正则表达式)
8、--with-apr=/usr/local/apr (依赖apr指定路径)
9、-with-apr-util=/usr/local/apr-util (依赖apr-util指定路径)
10、--enable-modules=most (启用模块级别,最大)
11、--enable-mpms-shared=all (启动动态模块装载)
12、--with-mpm=event (mpm默认采用event模式)
编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
提供SysV服务脚本/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
添加执行权限
chmod +x /etc/rc.d/init.d/httpd
加入服务列表
chkconfig --add httpd
添加环境变量httpd.sh
Vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
二、mariadb二进制格通用包安装
(1)准备数据目录:
以/mydata/data目录为例;
(2)安装配置mariadb
#useradd -r mysql (添加系统用户mysql,这样被不明用户劫持也不会得到超管权限对系统做出更大的威胁)
#tar xf mariadb-VERSION.tar.gz -C /usr/local
#cd /usr/local
#ln -sv mariadb-VERSION mysql
#cd /usr/local/mysql
#chown -R root:mysql ./*
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data (执行数据库安装脚本,指定用户和数据库文件存放物理路径)
#cp support-files/mysql.server /etc/init.d/mysqld (复制服务脚本到system的环境中)
(3) #cp support-files/my-large.cnf /etc/my.cnf
添加三个选项:
datadir = /mydata/data
innodb_file_per_table = ON
skip_name_resolve = ON
(4)启动服务,添加环境变量,/etc/init.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
执行mysql_secure_installation配置root用户和密码
三、编译安装php-5.4.26
(1) ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
1、--prefix=/usr/local/php (指定安装路径)
2、--with-mysql=/usr/local/mysql (指定依赖的数据库指定路径)
3、--with-openssl (启动OpenSSL功能)
4、--with-mysqli=/usr/local/mysql/bin/mysql_config (指定mysqli路径)
5、--enable-mbstring (支持多位元组字串)
6、--with-freetype-dir (支持多类字体)
7、--with-jpeg-dir (支持jpeg格式)
8、--with-png-dir (支持png格式)
9、-with-zlib (支持压缩传输)
10、--with-libxml-dir=/usr (支持处理xml)
11、--enable-xml (支持xml功能)
12、--enable-sockets (使php支持sockets方式内部交互)
13、--with-apxs2=/usr/local/apache/bin/apxs (把php编译成httpd的模块)
14、--with-mcrypt (支持加密解密库)
15、--with-config-file-path=/etc (指定php配置文件存放路径)
16、--with-config-file-scan-dir=/etc/php.d (配置文件查询路径)
17、--with-bz2 (支持bz2)
18、--enable-maintainer-zts (为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项)
Make –j 4 && make install
(2) 为php提供配置文件
#cp php.ini-production /etc/php.ini
四、httpd支援php配置
#vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
测试index.php与本地mysql的通讯链接
<?php
$conn=mysql_connect('127.0.0.1','root','root001');
if ($conn)
echo "Connect OK!";
else
echo "Failure.";
mysql_close();
?>
五、截图验证
apachectl -t -D DUMP_MODULES
lamp实验作业详细过程
数据库链接成功
lamp实验作业详细过程
PHP测试页面
lamp实验作业详细过程
六、安装wordpress
lamp实验作业详细过程
lamp实验作业详细过程
lamp实验作业详细过程
lamp实验作业详细过程
Ab压力测试,lamp同时部署在一台虚拟机上,并且使用php模块集成httpd的部署。-n 代表同时请求的资源数,-c 代表并发连接数。
lamp实验作业详细过程

4、建立httpd服务器(基于编译的方式进行),要求:

提供两个基于名称的虚拟主机:

(a)www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;

(b)www2.stuX.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;

(c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;

(d)通过www1.stuX.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status)

建立步骤:
1、编译安装httpd服务器
开发环境包组:Development Tools,Server Platform Development
开发程序包:pcre-devel
(1)apr-1.4+
#./configure --prefix=/usr/local/apr
#make && make install
注意:ARP类似于java虚拟机可以让httpd服务跨平台运行

(2)apr-util-1.4+
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && make install
注意:apr-util依赖于apr-1.4

(3)http-2.4
#./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --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=most --enable-mpms-shared=all --with-mpm=prefork
#make && make install
注意:编译的配置内容,按顺序解释
1.定义安装目录2.定义系统目录3.开启ssl功能模块4.开启CGI模块,能够吧动态内容通过CGI协议给后台应用服务处理4.开启rewrite功能5.依赖zlib 6.依赖pcre 7.依赖apr的安装路径8.依赖apr-util的安装路径9.开启httpd多数模块功能10.开启mpms共享模块11.默认以prefork多进程模式运行
把apache的二进制文件导出到系统环境变量,如截图

lamp实验作业详细过程
导出apache的头文件到系统目录下,如截图

lamp实验作业详细过程
定义httpd服务启动配置文件,如截图

lamp实验作业详细过程
添加到服务启动列表中chkconfig –add httpd,chkconfig –level 345 httpd on,这样就可以用service启动httpd服务了,httpd编译安装完成。如截图

lamp实验作业详细过程
lamp实验作业详细过程
配置vhosts
(a)(c)(d)
1.在httpd下/etc/httpd24/extra/vhosts.conf写入虚拟主机的配置
<VirtualHost 192.168.1.109:80> (定义虚拟主机的host地址和监听端口)
ServerName www1.stuX.com (定义域名地址)
DocumentRoot "/web/vhosts/www1" (指定文件URL根文件路径)
<Directory "/web/vhosts/www1"> (定义文件访问属性)
Options None (默认选项为空)
AllowOverride None (允许基于IP访问)
AuthType Basic (基于basic认证模式访问)
AuthName "String" (认证名称类型为字符串)
AuthUserFile "/user/user1" (指定认证文件)
Require user status (允许用户名为status)
</Directory>
ErrorLog "/var/log/httpd/www1.err" (指定错误日志保存的物理路径)
CustomLog "/var/log/httpd/www1.access" common (指定访问日志保存的物理路径)
<Location /server-status> (定义主机的status查看页面)
SetHandler server-status (设定标头)
Order allow,deny (访问白名单)
Allow from 192.168 (可以访问页面的主机所在网段)
</Location>
2.配置httpd.conf
#DocumentRoot "/usr/local/apache24/htdocs" 注释默认的文件根目录路径
Include /etc/httpd24/extra/vhosts.conf 填入默认加载虚拟主机配置的文件,这样httpd就会加载vhosts.conf的配置来启动对应的虚拟主机。
3.新建basic认证指定文件
lamp实验作业详细过程
(b)(c)
定义虚拟主机2的配置
<VirtualHost 192.168.1.109:80>
ServerName www2.stuX.com
DocumentRoot "/web/vhosts/www2"
<Directory "/web/vhosts/www2">
Options None
AllowOverride None
Require all granted
</Directory>
ErrorLog "/var/log/httpd/www2.err"
CustomLog "/var/log/httpd/www2.access" common
</VirtualHost>

测试验证截图
日志文件 lamp实验作业详细过程
主机1页面访问 lamp实验作业详细过程lamp实验作业详细过程lamp实验作业详细过程

主机2页面访问
lamp实验作业详细过程

5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;

(1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu);

(2)设置部门为Ops,主机名为www2.stuX.com,邮件为admin@stuX.com;

在CA服务器下签证
1.在系统CA目录下创建私钥
lamp实验作业详细过程
2.创建私钥密码长度为2048,导出到/etc/pki/CA/private/cakey.pem
lamp实验作业详细过程
3.自签证书
openssl req -new -x509 -key private/cakey.pem -out cacert.pem 自签证书以x509方式加密,导出为cacert.pem
认证信息
lamp实验作业详细过程
在指定路径下创建serial index.txt
lamp实验作业详细过程
在httpd服务器下创建ssl目录创建签证文件和认证请求
新增httpd.key私钥文件
lamp实验作业详细过程
新增认证请求文件
lamp实验作业详细过程
对httpd的认证请求做签署,httpd.crt签证成功后放回httpd下的ssl目录
lamp实验作业详细过程
#yum -y install mod_ssl 安装ssl模块
配置httpd关于ssl的文件
lamp实验作业详细过程
指定httpd的ca签署文件,和自身的私钥文件
lamp实验作业详细过程
在httpd.conf下开启ssl模块,指定ssl所在的配置文件
lamp实验作业详细过程
lamp实验作业详细过程
启动ssl服务
lamp实验作业详细过程
测试openssl效果
openssl s_client -connect www2.stuX.com:443 -CAfile /etc/pki/CA/cacert.pem
lamp实验作业详细过程

6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。

注意:php编译成httpd模块形式请参考第三题
PHP-FPM工作模式部署
1、 编译安装PHP-FPM
(1)./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --w
ith-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
注意:本次编译和之前的php编译安装的内容有重复,重复的内容我就不再描述,只描述新增的内容。
--enable-fpm (启动php-fpm,fastcgi传输协议)
make -j 4 && make install
(2) 为php提供配置文件:
#cp php.ini-production /etc/php.ini
(3) 配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
#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
#chkconfig php-fpm on
为php-fpm提供配置文件:
#cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf

编辑php-fpm的配置文件:
#vim /usr/local/php5/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid
接下来就可以启动php-fpm了:
#service php-fpm start
二、配置httpd
1、启用httpd的相关模块
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2、 配置主机支持fcgi
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://192.168.1.216:9000/www/magedu.com/$1
ProxyRequests Off:关闭正向代理
ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://192.168.1.216:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
3、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页
#vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
三、截图验证
lamp实验作业详细过程
lamp实验作业详细过程

转载于:https://blog.51cto.com/11412301/2084355

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值