N26-博客作业-week12

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

(1) 建立或处理连接:接收请求或拒绝请求;
(2) 接收请求:接收来自于网络上的主机请求报文中对某特定资源的一次请求的过程;
(3) 处理请求:对请求报文进行解析,获取客户端请求的资源及请求方法等相关信息;
(4) 访问资源:获取请求报文中请求的资源;
(5) 构建响应报文:
(6) 发送响应报文:
(7) 记录日志:

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

prefork模型:多进程模型,每个进程响应一个请求;一个主进程:负责生成n个子进程,子进程也称为工作进程,每个子进程处理一个用户请求;即便没有用户请求,也会预先生成多个空闲进程,随时等待请求到达;子进程数最大不会超过1024个。
worker模型:多线程模型,每个线程响应一个请求;一个主进程:生成多个子进程,每个子进程负责生成多个线程,每个线程响应一个请求。m进程,n线程:最大的并发响应数是m*n。
event模型:事件驱动模型,每个线程响应n个请求;一个主进程:生成m个子进程,每个进程直接响应n个请求;最大并发响应数是m*n。

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

安装开发环境
[root@localhost ~]# yum groupinstall "Development Tools" "Server Platform Development" -y

编译安装Apache
(1)编译安装apr
[root@localhost ~]# tar xf apr-1.5.2.tar.gz 
[root@localhost ~]# cd apr-1.5.2/
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
root@localhost ~]# make && make install 
(2)编译安装apr-util
[root@localhost ~]# tar xf apr-util-1.5.4.tar.bz2 
[root@localhost ~]# cd apr-util-1.5.4/
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util 
  --with-apr=/usr/local/apr 
[root@localhost apr-util-1.5.4]# make && make install 
(3)httpd-2.4.16依赖于pcre-devel软件包
[root@localhost ~]# yum -y install pcre-devel  openssl-devel
编译安装httpd-2.4.25
[root@localhost ~]# tar xf httpd-2.4.25.tar.bz2 
[root@localhost ~]# cd httpd-2.4.25/
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache24 
  --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 --enable-modules=most 
  --enable-mpms-shared=all --with-mpm=prefork
[root@localhost ~]# make -j 4 && make install
[root@localhost ~]# vim /etc/profile.d/httpd.sh
添加
export PATH=/usr/local/apache24/bin:$PATH
[root@localhost ~]# . /etc/profile.d/httpd.sh 

配置服务脚本
[root@localhost ~]cd /etc/rc.d/init.d/
[root@localhost init.d]cp httpd httpd24
vim httpd24
apachectl=/usr/local/apache24/bin/apachectl
httpd=${HTTPD-/usr/local/apache24/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

chkconfig --add httpd24
chkconfig --level 2345 httpd24 on

[root@localhost ~]# service httpd24 start

编译安装MySQL
#添加mysql用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql -s /sbin/nologin mysql 
#安装mysql依赖的软件包
[root@localhost ~]# yum -y install cmake ncurses-devel
#编译安装mysql 
[root@localhost ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/mysql-5.6.26/
[root@localhost mysql-5.6.26]# cmake  --DCMAKE_INSTALL_PREFIX=/usr/local/mysql  
  --DMYSQL_UNIX_ADDR=/tmp/mysql.sock   --DDEFAULT_CHARSET=utf8  
  --DDEFAULT_COLLATION=utf8_general_ci  --DWITH_EXTRA_CHARSETS=all  
  --DWITH_MYISAM_STORAGE_ENGINE=1 --DWITH_INNOBASE_STORAGE_ENGINE=1  
  --DWITH_MEMORY_STORAGE_ENGINE=1  --DWITH_READLINE=1  --DENABLED_LOCAL_INFILE=1  
  --DMYSQL_DATADIR=/usr/local/mysql/data  --DMYSQL-USER=mysql
[root@localhost mysql-5.6.26]# make -j 4 && make install
[root@localhost mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
[root@localhost ~]# sed  -i 's#^datadir=#datadir=/usr/local/mysql/data#' /etc/init.d/mysqld
[root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/adatadir = /usr/local/mysql/data' /etc/my.cnf
[root@localhost ~]# sed -i '/^\[mysqld\]/abasedir = /usr/local/mysql' /etc/my.cnf
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf
  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /bin/
[root@localhost ~]# service mysqld start

安装PHP
#安装PHP依赖的软件包
[root@localhost ~]# yum -y install libxml2-devel
#编译安装PHP
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
[root@localhost php-5.6.13]# ./configure --prefix=/usr/local/php 
  --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs 
  --with-config-file-path=/usr/local/php
[root@localhost php-5.6.13]# make && make install 
[root@localhost php-5.6.13]# cp php.ini-production /usr/local/php/php.ini
[root@localhost ~]# sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#  sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd24/httpd.conf 
[root@localhost ~]# sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd24/httpd.conf 
[root@localhost ~]# service httpd  restart

wordpress程序的安装
[root@localhost ~]# wordpress-4.7.5.zip
[root@localhost ~]# unzip wordpress-4.7.5.zip
[root@localhost ~]# cp -f wordpress/ /web/vhosts/
[root@localhost htdocs]# cd /web/vhosts/wordpress
[root@localhost wordpress]# cp wp-config-sample.php wp-config.php

创建数据库
[root@localhost ~]# mysql
mysql> CREATE DATABASE wpdb;
mysql> GRANT ALL ON wpdb.* TO wpuser@'192.168.12.%' IDENTIFIED BY 'wppass'; 
mysql> \q

[root@localhost wordpress]# vim wp-config.php
define('DB_NAME', 'wpdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wppass');

[root@localhost ~]# vim /etc/http24/httpd.conf
<VirtualHost *:80>
    ServerName www.wp.com
    DocumentRoot "/web/vhosts/wordpress"
    Errorlog "/var/log/httpd/wp.err"
    CustomLog "/var/log/httpd/wp.access" common
    <Directory "/web/vhosts/wordpress">
        Options None
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

[root@localhost ~]# service httpd  restart
[root@localhost ~]# vim /etc/hosts
192.168.12.136 www.wp.com

在浏览器中输入
www.wp.com
设置注册用户的用户名和密码,完成安装wordPress

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);

编译安装httpd
(1) apr-1.4+
    tar -xf apr-1.5.2.tar.bz2 
    cd apr-1.5.2
    ./configure  --prefix=/usr/local/apr
    make && make install
    
(2) apr-util-1.4+
    tar xf apr-util-1.5.4.tar.bz2 
    cd apr-util-1.5.4
    ./configure  --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr
    make && make install
    
(3) httpd-2.4
    tar xf httpd-2.4.25.tar.bz2
    cd httpd-2.4.25
    ./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
    
配置服务脚本
cd /etc/rc.d/init.d/
cp httpd httpd24
vim httpd24
apachectl=/usr/local/apache24/bin/apachectl
httpd=${HTTPD-/usr/local/apache24/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

chkconfig --add httpd24
chkconfig --level 2345 httpd24 on

配置虚拟主机      
mkdir -f /web/vhosts/{www1,www2}
vim /web/vhosts/www1/index.html
<h1>www1.stux.com</h1>
vim /web/vhosts/www2/index.html
<h1>www2.stux.com</h1>
vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    ServerName www1.stux.com
    DocumentRoot "/web/vhosts/www1"
    Errorlog "/var/log/httpd/www1.err"
    CustomLog "/var/log/httpd/www1.access" common
    <Directory "/web/vhosts/www1">
        Options None
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName www2.stux.com
    DocumentRoot "/web/vhosts/www2"
    Errorlog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
    <Directory "/web/vhosts/www2">
        Options None
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

修改host
vim /etc/hosts
192.168.12.136 www1.stux.com
192.168.12.136 www2.stux.com

配置安全域
htpasswd -c -m /etc/httpd24/.htpasswd status
password:status
vim /etc/httpd24/httpd.conf
<Location /server-status>
    SetHandler server-status
    Order allow,deny
    Allow from www1.stux.com
    AuthType Basic
    AuthName "Need Authentication!"
    AuthUserFile "/etc/httpd24/.htpasswd"
    require user status
</Location>

5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;
   (1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu);
   (2)设置部门为Ops,主机名为www2.stuX.com,邮件为admin@stuX.com;

CA服务器(192.168.12.130)
cd /etc/pki/CA/
(umask 077;openssl genrsa -out private/cakey.pem 2048)
openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
证书信息输入
touch serial index.txt
echo 01 > serial

httpd服务器(192.168.12.136)
cd /etc/httpd24
mkdir ssl
cd /etc/pki/CA/
(umask 077;openssl genrsa -out httpd.key 1024)
openssl req -new -key httpd.key -out httpd.csr
证书信息输入
scp httpd.csr root@192.168.12.130:/tmp/

CA服务器签署证书
openssl ca -in /tmp/http.csr -out certs/httpd.crt
scp /certs/httpd.crt root@192.168.12.136:/etc/httpd24/ssl/

httpd服务器配置
vim /etc/httpd24/httpd.conf
Listen 443
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
<VirtualHost *:443>
    ServerName www2.stux.com
    SSLCertificateFile /etc/httpd24/ssl/httpd.crt
    SSLCertificateKeyFile /etc/pki/CA/private/httpd.key
    DocumentRoot "/web/vhosts/www2"
    Errorlog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
    <Directory "/web/vhosts/www2">
        Options None
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
Include /etc/httpd24/extra/httpd-ssl.conf

vim /etc/httpd24/extra/httpd-ssl.conf
DocumentRoot "/web/vhosts/www2"
ServerName www2.stux.com:443
ServerAdmin admin@stux.com
SSLCertificateFile /etc/httpd24/ssl/httpd.crt
SSLCertificateKeyFile /etc/pki/CA/private/httpd.key

httpd -t
service httpd24 restart

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

httpd模块形式编译安装PHP
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
#以httpd模块方式运行,所以需要在编译时指定apache的apxs2的目录路径 
  --with-apxs2=/usr/local/apache/bin/apxs 
[root@localhost php-5.6.13]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd 
  --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir 
  --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/lib64 --enable-xml  
  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs 
  --with-mcrypt=/usr/local/libcrympt  --with-config-file-path=/etc 
  --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
[root@localhost php-5.6.13]# make -j 4 && make install
[root@localhost php-5.6.13]# cp php.ini-production /etc/php.ini && cd
#编辑apache配置文件
[root@localhost ~]#sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd/httpd.conf
[root@localhost ~]#service httpd  restart
[root@localhost ~]#echo '<?php phpinfo();  ?>' >/usr/local/apache/htdocs/index.php
访问http://192.168.12.130/index.php进行测试

以fpm模式运行
[root@localhost ~]# sed -i '1a/usr/local/libmcrypt/lib' /etc/ld.so.conf
[root@localhost ~]# sed -i '2a/usr/local/mysql/lib' /etc/ld.so.conf
[root@localhost ~]# yum install php-pear -y
[root@localhost ~]# ldconfig
[root@localhost ~]# echo 'ldconfig' >> /etc/rc.local
[root@localhost ~]# tar xf php-5.6.13.tar.bz2 
[root@localhost ~]# cd php-5.6.13/
#以fpm模式运行,使能fpm选项,--enable-fpm, --with-apxs2一项就不需要启用了
[root@localhost php-5.6.13]# ./configure --prefix=/usr/local/php 
  --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql 
  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir 
  --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml 
  --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem 
  --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm 
  --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash 
  --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap 
  --with-mcrypt=/usr/local/libmcrypt
[root@localhost php-5.6.13]# make -j 4 && make install
[[root@localhost php-5.6.13]# cp php.ini-production /usr/local/php/php.ini && cd
[root@localhost php-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default 
  /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.6.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.13]#  chmod +x /etc/init.d/php-fpm
[root@localhost php-5.6.13]# chkconfig php-fpm on
[root@localhost php-5.6.13]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@localhost php-5.6.13]# netstat -antup | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      
  9769/php-fpm: maste 
#编辑apache配置文件
[root@localhost ~]# sed -i 's/^#LoadModule proxy_fcgi/LoadModule proxy_fcgi/' 
  /etc/httpd/httpd.conf
[root@localhost ~]# sed -i 's/^#LoadModule proxy_module/LoadModule proxy_module/' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i 's/index.html/index.html index.php/' /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '377a    AddType application/x-httpd-php .php' 
  /etc/httpd/httpd.conf
[root@localhost ~]#sed -i '378a    AddType application/x-httpd-php-source .phps' 
  /etc/httpd/httpd.conf
[root@localhost ~]#service httpd  restart
[root@localhost ~]#echo '<?php phpinfo();  ?>' >/usr/local/apache/htdocs/index.php
访问http://192.168.12.130/index.php进行测试 


原创文章,作者:浙江-咲,如若转载,请注明出处:http://www.178linux.com/76797

(0)
浙江-咲浙江-咲
上一篇 2017-05-23
下一篇 2017-05-23

相关推荐

  • 安装CentOS 7.2操作系统

        工具:     VMware Workstation     http://www.vmware.com/cn/products/workstation/workstation-evaluation.html  &nbsp…

    Linux干货 2016-08-04
  • Linux之bash shell脚本编程入门篇(三)之循环以及函数function的使用

    bash shell脚本编程入门篇(三)之循环 什么是循环执行?     将某代码段重复运行多次     重复运行多少次:         循环次数事先已知    &nb…

    Linux干货 2016-08-22
  • N28 第三周【2】:用户和组管理

    用户和组管理 前言 Linux用户管理非常关键且重要,Linux的所有进程都是以不同的身份拥有不同的权限来运行和调度资源的。但是我们不用费劲心思去管理,因为系统将用户划分成为了两部分:无所不能的root用户和普通用户。同时呢,又将普通用户分为系统用户和登录用户。对于Linux,他会用UID去快速识别用户身份,对于我们,可以用用户名去识别。 接下来介绍一下用户…

    Linux干货 2017-12-19
  • 第七周

    创建一个10G分区,并格式化为ext4的文件系统 划分分区 partxprobe:重读分区表   建立文件系统,acl机制          挂载文件系统          写文件 &nbs…

    Linux干货 2016-12-11
  • 网络班23期学习宣言

    马哥Linux运维学院 学习宣言 亲爱的小伙伴:        欢迎大家报名马哥Linux运维网络学习班,跟随马哥学习Linux技术,成就Linux大牛之梦。在这里,我们不仅可以学习到最优秀的技术课程,还可以跟着追梦的小伙伴们一起学习、一起进步。 为了督促大家一直积极认真努力的学习,请各位同学在评论区写出你的学习宣言。…

    2016-09-05
  • 马哥教育网络20期—nginx

    Nginx 一. Nginx 特性 二. Nginx 基本架构 三. Nginx 基本功能 四. Nginx 安装 五. Nginx 配置文件 六. Nginx http服务功能测试 七. Nginx LNMP 一. Nginx 特性 模块化,目前只能将模块编译进Nginx,暂时不支持动态装卸载模块.(httpd优势) 可靠性,一个主进程(master)控制…

    Linux干货 2016-06-26

评论列表(1条)

  • luoweiro
    luoweiro 2017-06-26 22:56

    实验过程很详细,如果有关于压测相关的性能数据就好了,比如perfork,worker模式这些对比数据,然后再结合工作机制去调整验证,掌握的会更加扎实。