第十二周作业

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

    1)建立或处理连接:接收请求或拒绝请求;

    2)接收请求:接收来自于网络的请求报文中对某资源的一次请求的过程;接收请求的方式通常是并发访问响应模型;

    3)处理请求:对请求报文进行解析,并获取请求的资源及请求方法等相关信息,解析后的报文信息首部称为元数据;

    4)构建响应报文:根据用户请求的资源MIME类型以及URL重定向进行报文响应;

    5)发送响应报文;

    6)记录日志信息。

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

    1)prefork:多进程模型,每个进程响应一个请求;一个主进程负责生成n个子进程,子进程也成为工作进程,每个子进程处理一个用户请求;即便没有用户请求,也会预先生成多个空闲进程,随时等待请求到达;最大不会超过1024个;

    优点:成熟稳定,兼容所有新老模块。
    缺点:一个进程相对占用更多的系统资源,消耗更多的内存。而且,它并不擅长处理高并发请求,理论上不会超过1024个,在大并发场景下,它会将请求放进队列中,一直等到有可用进程,请求才会被处理。
    2)worker:多线程模型,每个线程响应一个请求;一个主进程生成多个子进程,每个子进程负责生成多个线程,每个线程响应一个请求;如有m个进程,每个进程有n个线程,则可处理的请求个数为:m*n

    优点:占据更少的内存,高并发下表现更优秀。

    缺点:(1)线程的管理要比进程复杂得多。线程之间很多资源是共享的,所以它没有prefork模型那种一个进程服务一个服务请求那么安全稳定;

             (2)worker是一个线程服务一个请求,在请求没有完成之前,该线程是与它服务的请求绑定的。worker需要大量的创建进程生成线程,销毁线程,杀死进程的过程;

             (3)由于linux不是真线程的操作系统,所以worker在linux上的表现与prefork相比并没有明显优势。

    3)event:事件驱动模型,是基于信号驱动I/O 通知机制,每个线程响应n个请求;

    优点:并发能力强,并且解决了worker模型下由于线程与请求绑定而导致的线程资源浪费的问题;

    缺点:2.4之前的版本仅为测试用,只有2.4之后event才可在生产使用。

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

    二进制方式安装Mariadb

    1)创建mysql用户

]# useradd -r mysql

     2)二进制方式安装mariadb

]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local

     3)创建链接并更改安装目录权限

]# cd /usr/local
]# ln -sv mariadb-5.5.46-linux-x86_64/ mysql
]# cd mysql
]# chown -R root.mysql ./*

     4)创建数据文件目录并赋权

]# mkdir -p /mydata/data
]# chown -R mysql.mysql /mydata/data/

     5)创建mariadb配置文件

]# cd /usr/local/mysql/support-files
]# cp my-large.cnf /etc/my.cnf

     6)在配置文件中添加参数:

]# vim /etc/my.cnf
[mysqld]
.
.
.
datadir = /mydata/data
innodb_file_per_table = ON
skip_name_resolve = ON

     7)创建启动脚本

]# cd /usr/local/mysql/support-files
]# cp mysql.server /etc/rc.d/init.d/mysqld
]# chmod +x /etc/rc.d/init.d/mysqld 

     8)初始化数据库

]# cd /usr/local/mysql/
]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data

     9)启动mariadb

]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!

    编译安装Apache:

    1)安装依赖包

]# yum groupinstall "Development Tools" "Server Platform Development" -y
]# yum install pcre-devel apr-devel apr-util-devel openssl-devel -y

    2)编译安装apache

]# tar xf httpd-2.4.9.tar.bz2
]# cd httpd-2.4.9
]# ./configure --prefix=/usr/local/apache -sysconfdir=/etc/httpd \
--enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre \
--with-apr=/usr --with-apr-util=/usr --enable-modules=most \
--enable-mpms-shared=all --with-mpm=prefork
]# make && make install

    3)修改环境变量,便于httpd相关命令的使用

]# touch /etc/profile.d/httpd.sh
]# echo "export PATH=/usr/local/apache/bin:$PATH" >>/etc/profile.d/httpd.sh
]# source /etc/profile

     4)启动httpd服务

]# apachectl start
]# ps -ef|grep httpd
root      35159      1  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    35160  35159  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    35161  35159  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    35162  35159  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    35163  35159  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    35164  35159  0 15:59 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root      35166   6129  0 15:59 pts/0    00:00:00 grep --color=auto httpd

     编译安装php:

    1)安装依赖包

]# yum install libxml2-devel libmcrypt-devel bzip2-devel -y

     2)编译安装php

]# tar xf php-5.4.26.tar.bz2
]# cd php-5.4.26
]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ \
--with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config  \
--enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-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
]# make && make install

     3)生成配置文件

]# cp php.ini-production /etc/php.ini

     4)修改httpd配置文件,使其能够支持php

]# vim /etc/httpd/httpd.conf
.
.
.
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

AddType application/x-httpd-php .php

     5)测试httpd与php

]# vim /usr/local/apache/htdocs/index.php
<?php
        phpinfo()
?>

第十二周作业

    6)测试php与mariadb的联动

]# vim /usr/local/apache/htdocs/index.php
<?php
        $conn = mysql_connect('127.0.0.1','root','');
        if ($conn)
                echo "OK";
        else
                echo "Failure";
?>

第十二周作业

    测试成功,开始安装WordPress

    1)数据库中创建用户

MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpuser@'192.168.0.%' identified by 'magedu';
MariaDB [(none)]> flush privileges;

     2)将wordpress安装包解压到主页目录下

]# cd /usr/local/apache/htdocs
]# unzip wordpress-3.3.1-zh_CN.zip

     3)修改wordpress配置文件

]# cd wordpress
]# cp wp-config-sample.php wp-config.php
]# vim wp-config.php
define('DB_NAME', 'wpdb');

/** MySQL 数据库用户名 */
define('DB_USER', 'wpuser');

/** MySQL 数据库密码 */
define('DB_PASSWORD', 'magedu');

/** MySQL 主机 */
define('DB_HOST', '192.168.0.111');

    4)通过页面进行安装

第十二周作业

    5)安装完成,打开BLOG

第十二周作业

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)创建主页目录,日志目录和主页文件

]# mkdir -p /web/vhosts/{www1,www2}
]# mkdir -p /var/log/httpd
]# echo "www1.stuX.com" >/web/vhosts/www1/index.html
]# echo "www2.stuX.com" >/web/vhosts/www2/index.html

     2)创建认证用户

]# htpasswd -c -m /etc/httpd/.htpasswd status

     3)创建虚拟主机配置文件

]# cd /etc/httpd/extra/
]# vim vhosts.conf
<VirtualHost 192.168.0.111:80>
    DocumentRoot "/web/vhosts/www1"                      #主页目录
    <Directory "/web/vhosts/www1">
        Options None
        AllowOverride None
        Require all granted
    </Directory>

    <Location /server-status>                            
        SetHandler server-status
        AuthType Basic                                   #认证模块
        AuthName "Admin Realm, show something"
        AuthUserFile "/etc/httpd/.htpasswd"              #指定认证文件
        Require user status                              #指定认证用户
    </Location>
    ServerName www1.stuX.com
    ErrorLog "/var/log/httpd/www1.err"                   #错误日志文件        
    CustomLog "/var/log/httpd/www1.access" common        #登录日志文件
</VirtualHost>

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

     4)修改httpd主配置文件,使自定义的虚拟机配置文件生效

]# cd /etc/httpd/
]# vim httpd.conf
Include /etc/httpd/extra/vhosts.conf

     5)重启httpd服务,使配置生效

]# apachectl restart

     6)修改客户端的hosts文件

192.168.0.111 www1.stuX.com   www2.stuX.com

     7)客户端使用浏览器访问页面进行测试

第十二周作业

第十二周作业

第十二周作业

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

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

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

    1)CA服务器端生成私钥

]# cd /etc/pki/CA/
]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
.........+++
.....................................................................+++
e is 65537 (0x10001)

     2)CA服务端生成自签证书

]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
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]:MagEdu 
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www2.stuX.com
Email Address []:admin@stuX.com
]# touch serial index.txt
]# echo 01 >serial 

     

    3)web服务器端生成私钥

]# cd /etc/httpd/
]# mkdir ssl
]# cd ssl/
]# (umask 077;openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
...............++++++
..++++++
e is 65537 (0x10001)

    4)web服务器端生成证书签署请求

]# openssl req -new -key httpd.key -out httpd.csr
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]:MagEdu
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www2.stuX.com
Email Address []:admin@stuX.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

     5)web服务器将证书签署请求发送给CA服务器

]# scp httpd.csr root@192.168.0.120:/tmp/

     6)CA服务器签署证书

]# openssl ca -in /tmp/httpd.csr -out certs/httpd.crt

     7)CA服务器将证书发送给web服务器端

]# scp certs/httpd.crt root@192.168.0.111:/etc/httpd/ssl

     8)web服务器安装mod_ssl模块

]# yum install mod_ssl -y

     9)编辑ssl模块配置文件

]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/web/vhosts/www2"
ServerName www2.stuX.com
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

     10)重启httpd服务

]# apachectl restart

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

fpm方式:

    1)安装httpd,php-fpm,mariadb,php-mysql

]# yum install php-fpm httpd mariadb-server php-mysql -y

     2)创建fcgi配置文件

]# cd /etc/httpd/conf.d/
]# vim fcgi.conf
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

     3)修改httpd主配置文件,指定首页默认文件为index.php

]# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

     4)创建php测试页面

]# cd /var/www/html/
]# vim index.php
<?php
    phpinfo()
?>

     5)启动http和php-fpm服务

]# systemctl reload httpd.service
]# systemctl start php-fpm.service

php以模块方式来支持httpd的方式在上面第3题已经提供了部署过程,这里不再赘述。

原创文章,作者:N26-西安-方老喵,如若转载,请注明出处:http://www.178linux.com/71598

(1)
N26-西安-方老喵N26-西安-方老喵
上一篇 2017-03-27
下一篇 2017-03-27

相关推荐

  • N26-第五周

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;  ~]# grep “^[[:space:]]\+$” /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; ~]# grep &#82…

    Linux干货 2017-03-02
  • 107-tomcat

    一.编程语言基础  1.1 编程语言: 硬件级:微码编程,汇编语言 系统级:C,C++,…

    2016-12-02
  • 设计模式(七)组合模式Composite(结构型)

    1. 概述 在数据结构里面,树结构是很重要,我们可以把树的结构应用到设计模式里面。 例子1:就是多级树形菜单。 例子2:文件和文件夹目录 2.问题 我们可以使用简单的对象组合成复杂的对象,而这个复杂对象有可以组合成更大的对象。我们可以把简单这些对象定义成类,然后定义一些容器类来存储这些简单对象。客户端代码必须区别对象简单对象和容器对象,而实际上大多数情况下用…

    Linux干货 2015-07-01
  • Linux第五周总结

    1、显示当前系统上root、fedora或user1用户的默认shell 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); 3、使用echo命令输出一个绝对路径,使用gerp取出其基名;     扩展:取出其路径名 4、找出ifconfig命令结果中的…

    2017-07-30
  • grep和正则表达式

    grep       作用:文本搜索工具,根据用户指定的“模式(过滤条件)”对目标文件逐行进行匹配检查;打印匹配到的行;       模式:由正则表达式的元字符及文本所编写出的过滤条件    语法:【选项】【文件】  &…

    2017-08-04
  • 手动自制Mini Linux

        linux系统内核非常的精简,而且基于一切皆文件的思想,使得我们可以再现有系统上挂载一个空硬盘,利用现有系统编译一个内核和相关程序文件并拷贝到空硬盘上。我们就可以用空硬盘来单独运行一个精简的linux系统,这对于依赖于注册表的windows系统来说是不可能实现的。本文简要介绍一下一个mini linux的安装制…

    Linux干货 2016-05-03

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-30 14:18

    非常非常棒,再接再励。