net25-第12周作业

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

– (1)客户端发送http请求
– (2)服务端建立或处理连接,接受请求或拒绝请求
– (3)接受请求:接受客户端对服务器某一资源的请求
– (4)处理请求:对请求报文进行解析,获取客户端请求的资源及请求方法等相关信息
– (5)访问资源:获取请求报文中请求的资源
– (6)构建响应报文
– (7)发送响应报文
– (8)记录日志

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

– prefork: 多进程模型,一个进程处理一个请求,会由一个主进程预先生成几个进程来随时响应,进程响应相对于较耗资源,所以并不适合大并发的请求处理,各个进程的故障并不互相影响,这应该最稳定的处理模型。
– worker: 多进程多线程模型,线程处理请求,会由一个主进程生成几个进程,进程生成线程来处理并发请求,同个进程里可以共享资源,所以整体来说worker模型比prefork的资源消耗少,但是都在一个进程的线程处理请求,线程的故障会影响整个进程,所以并不是很稳定。
– event: 事件驱动模型,是基于事件驱动的进程来工作的,一个进程可以响应多个请求,也是预先生成多个进程,但是采用专用的进程来监听套接字保持连接,因为监听套接字和保持TCP连接所需要的资源极小一个进程就可以处理大量的这种请求。

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

安装环境Centos 6
1、httpd-2.4
编译安装步骤:
        (1)apr-1.4+
            ./configure –prefix=/usr/local/apr
            make && make install
        (2)apr-util-1.4+
            ./configure –prefix=/usr/local/apr-util
            make && make install
        (3)httpd-2.4
            ./configure
            –prefix=/usr/local/httpd2.4
            –sysconfig=/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
            
2、mariadb-10.1.22
        (1) cmake-2.8.8
        ./configure && make && make install
        (2) mariadb
        cmake . -LH  预编译下
        cmake .
        -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
        -DMYSQL_DATADIR=/data/mysql \
        -DSYSCONFIGDIR=/etc \
        -DWITH_INNOBASE_STORAGE_ENGINE=1 \
        -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
        -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
        -DWITH_READLINE=1 \
        -DWITH_SSL=system \
        -DWITH_ZLIB=system \
        -DWITH_LIBWRAP=0 \
        -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
        -DDEFAULT_CHARSET=utf8 \
        -DDEFAULT_COLLATION=utf8_general_ci
        
        make && make install
        
        初始化数据
        ./mysql_db_install –basedir=/usr/local/mysql –datadir=/data/mysql –user=mysql
        
        加载库和头文件
        vim /etc/ld.so.conf.d/mariadb.conf
        /usr/local/mariadb
        
        ln -s /usr/local/mariadb/include /usr/include/mysql
3、php-7.1.3
        ./configure –prefix=/usr/local/php \
        –sysconfdir=/usr/local/php/etc \
        –with-curl \
        –with-freetype-dir \
        –with-gd \
        –with-gettext \
        –with-iconv-dir \
        –with-kerberos \
        –with-libdir=lib64 \
        –with-libxml-dir \
        –with-mysqli \
        –with-openssl \
        –with-pcre-regex \
        –with-pdo-mysql=/usr/local/mariadb \
        –with-pdo-sqlite \
        –with-pear \
        –with-png-dir \
        –with-xmlrpc \
        –with-xsl \
        –with-zlib \
        –with-apxs2=/usr/local/http2.4/bin/apxs \
        –enable-bcmath \
        –enable-libxml \
        –enable-inline-optimization \
        –enable-gd-native-ttf \
        –enable-mbregex \
        –enable-mbstring \
        –enable-opcache \
        –enable-pcntl \
        –enable-shmop \
        –enable-soap \
        –enable-sockets \
        –enable-sysvsem \
        –enable-xml \
        –enable-zip
        
        make && make install
    

配置httpd.conf

加载模块 LoadModule php7_module        modules/libphp7.so

添加MIME AddType application/x-httpd-php  .php
               AddType application/x-httpd-php-source  .phps

               DirectoryIndex  index.php  index.html

配置虚拟主机

               打开 # Virtual hosts
                       Include conf/extra/httpd-vhosts.conf

 

<VirtualHost *:80>
    DocumentRoot “/www”
    ServerName www.jusene.com
    DirectoryIndex  index.php
    ErrorLog “logs/dummy-host.example.com-error_log”
    CustomLog “logs/dummy-host.example.com-access_log” common
    <Directory ‘/www’>
    Options None
    AllowOverride None
    RequireAll all granted
    </Directory>
</VirtualHost>

 

测试php:

vim /www/index.php

<?php

    phpinfo();

?>

 

测试mysql

<?

$con=mysqli_connect(‘127.0.0.1′,’bbs’,’bbs’);

if($con){

print ‘ok’;

}

else {

print ‘fail’;

}

?>

下载wordpress的安装包,将它解压到/www上我们就可以按照步骤安装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);

<VirtualHost *:80>
    DocumentRoot “/web/vhosts/www1”
    ServerName www1.stuX.com
    ErrorLog “/var/log/httpd/www1.err”
    CustomLog “/var/log/httpd/www1.access” common
    <Directory ‘/web/vhosts/www1’>
    Options None
    AllowOverride None
    RequireAll all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot “/www/vhosts/www2”
    ServerName www2.stuX.com
    ErrorLog “/var/log/httpd/www2.err”
    CustomLog “/var/log/httpd/www2.access” common
    <Directory ‘/www/vhosts/www2’>
    Options None
    AllowOverride None
    RequireAll all granted
    </Directory>
</VirtualHost>

加载模块 
LoadModule status_module modules/mod_status.so      <Location /server-status> 
SetHandler server-status
AuthType Basic
AuthName "status page"
AuthUserFile "/usr/local/httpd2.4/conf/.htpasswd"
Require valid-user
</Location>

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

私有ca也建在同一台主机:

[root@node2 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
………………………………+++
.+++
e is 65537 (0x10001)
[root@node2 ssl]# ls
httpd.key
[root@node2 ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server’s hostname) []:www2.stuX.com
Email Address []:[email protected]

Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:            
[root@node2 ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Feb 26 18:53:32 2017 GMT
            Not After : Feb 26 18:53:32 2018 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HA
            organizationName          = MageEdu
            organizationalUnitName    = Ops
            commonName                = www2.stuX.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                FC:CA:DE:D8:79:17:B3:12:16:50:FD:27:B2:76:7F:84:AE:F6:8F:65
            X509v3 Authority Key Identifier:
                keyid:FD:CD:68:2D:2C:BF:71:2E:C7:91:AB:6F:60:20:29:65:2A:6F:82:88

Certificate is to be certified until Feb 26 18:53:32 2018 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@node2 ssl]# ls
httpd.crt  httpd.csr  httpd.key
[root@node2 ssl]#

加载配置

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf

修改配置

DocumentRoot
ServerName
SSLCertificateFile
SSLCertificateKeyFile

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

上面的编译为将php编译成httpd模块来实现的。结下来我们将它编译称fastcgi的方式来进行实现。

php-7.1.3
        ./configure –prefix=/usr/local/php \
        –sysconfdir=/usr/local/php/etc \
        –with-curl \
        –with-freetype-dir \
        –with-gd \
        –with-gettext \
        –with-iconv-dir \
        –with-kerberos \
        –with-libdir=lib64 \
        –with-libxml-dir \
        –with-mysqli \
        –with-openssl \
        –with-pcre-regex \
        –with-pdo-mysql=/usr/local/mariadb \
        –with-pdo-sqlite \
        –with-pear \
        –with-png-dir \
        –with-xmlrpc \
        –with-xsl \
        –with-zlib \
        –enable-fpm \
        –enable-bcmath \
        –enable-libxml \
        –enable-inline-optimization \
        –enable-gd-native-ttf \
        –enable-mbregex \
        –enable-mbstring \
        –enable-opcache \
        –enable-pcntl \
        –enable-shmop \
        –enable-soap \
        –enable-sockets \
        –enable-sysvsem \
        –enable-xml \
        –enable-zip
        
        make && make install

 

vim /etc/httpd.conf

加载这两个模块

mod_proxy.so

mod_proxy_fcgi.so

添加 MIME

AddType  application/x-httpd-php  .php

AddType  application/x-httpd-php-source  .phps

这个要在虚拟主机前面加上,就因为在后面加导致找不到文件。

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

在虚拟主机中配置
<VirtualHost  *:80>
     DocumentRoot  “/www”
     ServerName  magedu.com
     ProxyPassMatch  ^/(.*\.php)$  fcgi://127.0.0.1:9000/www/$1
    <Directory  “/www”>
    Options  None
    AllowOverride  None
     Reauire all granted
    </Directory>
</VirtualHost>

 

 

原创文章,作者:N25_随心,如若转载,请注明出处:http://www.178linux.com/72097

(0)
N25_随心N25_随心
上一篇 2017-05-15 15:01
下一篇 2017-05-15 15:45

相关推荐

  • linux基础学习之进程管理和任务计划

    内容:   进程相关概念(用户空间、内核空间,进程、线程)   进程及系统相关工具(ps、top、pgrep、pidof、kill)   调整nice值(nice、renice)   作业管理(jobs、fg、bg、kill,&)   计划任务(at、crontab) 一、进程相关概念 内核的功用:进…

    Linux干货 2016-09-07
  • 计算机组成及Linux入门知识

    计算机的基本组成: 存储器:     实现记忆功能的部件用来存放计算程序及参与运算的各种数据 运算器:     负责数据的算术运算和逻辑运算即数据的加工处理 控制器:     负责对程序规定的控制信息进行分析,控制并协调输入,输出操作或内存访问 输入设备:    实现计算程序和原始数据的输入 输出设备:    实现计算结果输出 组成的联系: 图一 图二 计算…

    Linux干货 2016-09-16
  • Shell脚本使用示例

    目录如下:  1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 2、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到/root/etcYYYY-mm-dd中 3、编写脚本/root/bin/disk.s…

    Linux干货 2016-08-30
  • Linux的终端类型

    一、了解终端   在早期的年代,主机不是很多,都是一系列的大型主机,简单来说就是用户很多,但主机很少,不可能做到人手一台,但可以在主机上连接一个分屏器,在分屏器上可以连接鼠标键盘以及显示器,这些东西是没有计算能力的,仅仅担任输入和输出的工作,运算和处理都是由主机来完成的。   简单来说终端是用户与主机交互,是必然用到的…

    Linux干货 2016-10-14
  • 马哥教育网络19期+第十五周课程练习

    1、总结sed和awk的详细用法;   a).sed命令 sed可以实现grep的大部分功能,而且还可以查找替换 [root@localhost ~]# sed '10'p -n 1.txt [root@localhost ~]# sed &#039…

    Linux干货 2016-08-22
  • 马哥教育网络班20期+第三周博客作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一用户登录多次,则只显示一次即可。 [root@llww3317 ~]# who    #显示当前用户登录信息 root     tty1    &nbsp…

    Linux干货 2016-06-26

评论列表(1条)

  • 马哥教育
    马哥教育 2017-06-20 10:04

    如果可以多注意一下排版问题的话会更好