N21沉舟11周作业

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

(1) 建立或处理连接:接收请求或拒绝请求
(2) 接收请求:
(3) 处理请求:对请求报文进行解析,并获取请求的资源及请求方法等相关信息
(4) 访问资源:获取请求报文中请求的资源
(5) 构建响应报文
(6) 发送响应报文
(7) 记录日志

http.jpg

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

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

http_mpm多路处理模块.jpg

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

解决依赖关系
# yum -y groupinstall "Desktop Platform Development" 
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
安装apr 1.52和 apr-util1.54
#wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz安装pcre-devel#groupadd -r apache
编译安装httpd 2.4.23
#wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz
#tar 
#cd
./configure --prefix=/usr/local/apr
make & make install
tar 
cd
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make & make install
#yum install pcre-devel
#yum install openssl-devel
#创建用户名和组
useradd -r -g apache   apache
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.23.tar.gz
 tar
cd
./configure --prefix=/usr/local/apache --sysconf=/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
编译安装mariadb
1、准备数据目录
             以/mydata/data为例
2、配置mariaDB
            #groupadd -r -g ### mysql
            #useradd -r -g ### -u ### mysql
            #tar xf ******.gz   -C /usr/local
            #ln -sv  ***** mysql
            #cd /usr/local/mysql
            #chown -R root:mysql ./*
            #scripts/mysql_install_db --datadir=/mydqta/data  --user=mysql
            #cp supper_file/mysql.server  /etc/rc.d/init.d/mysqld
3、配置文件
            配置文件查找次序
                   /etc/my.cnf ---->/etc/mysql/my.cnf---> --default-extra-file=/path/to/conf-file--->~/.my.cnf
            #cp support_files/my-large.cnf  /etc/mysql/my.cnf
               添加三个选项
                    datadir=/mydata/data
                    innodb_file_pre_table=on          #使用单独配置文件
                    skip_name_resolve=on             #跳过主机名称反写
 安全初始化
             mysql/bin/mysql_secure_installation
编译安装php
安装依赖
yum install openssl-devel  libxml2-devel
安装libcurl7.28
 wget https://curl.haxx.se/download/curl-7.28.0.tar.gz --no-check-certificate
tar
cd
./configure --prefix=/usr/local/curl
下载php
http://cn2.php.net/distributions/php-5.6.26.tar.gz
tar
cd
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql --with-mysql --with-curl=/usr/local/curl
make & make install
修改配置文件:
php-fpm脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
生成php-fpm配置文件
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
修改 /usr/local/etc/php-fpm.conf
user = daemon
group = daemon
listen = /dev/shm/php-fpm.sock
listen.owner = daemon
listen.group = daemon
pm = static
pm.max_children = 4
pm.max_requests = 2048
修改/etc/httpd24/httpd.conf
添加
AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps
 DirectoryIndex  index.php  index.html
去掉mod_proxy.so和mod_proxy_fcgi.so之前的注释,确保他们被apache加载
在行尾添加
<FilesMatch \.php$>
         SetHandler "proxy:fcgi://127.0.0.1:9000"</FilesMatch>
运行service php-fpm start,并查看9000端口是否监听
安装wordpress
 wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
tar xvf  wordpress-4.5.3-zh_CN.tar.gz
mv workpress-4.5.3 /var/www/html/
mv workpress-4.5.3 wd
使用http://host_IP/wd 开始安装

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

注释配置文件中DocumentRoot条目 ,创建如下配置块
<VirtualHost *:80>
    DocumentRoot "/web/vhosts/www1"
    ServerName  www1.stuX.com
    ErrorLog "/var/log/httpd/www1.err"
    CustomLog "/var/log/httpd/www1.access" common
<Location /server-status>
    SetHandler server-status
    Options None
    AllowOverride None
    AuthType Basic
    AuthName "this zone just admin visit!"
    AuthUserFile "/etc/httpd24/ssl/pw"
    Require user tom
</Location>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/web/vhosts/www2"
    ServerName www2.stuX.com
    ErrorLog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www1.access" common
</VirtualHost>
#使用htpasswd -c /etc/httpd24/ssl/pw tom创建tom用户和密码

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

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

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





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

   #环境centos 6.3 , httpd2.4 ,
#编译为fpm
  
安装依赖
yum install openssl-devel  libxml2-devel
安装libcurl7.28
 wget https://curl.haxx.se/download/curl-7.28.0.tar.gz --no-check-certificate
tar
cd
./configure --prefix=/usr/local/curl
下载php
http://cn2.php.net/distributions/php-5.6.26.tar.gz
tar
cd
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql --with-mysql --with-curl=/usr/local/curl
make & make install
修改配置文件:
php-fpm脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
生成php-fpm配置文件
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
修改 /usr/local/etc/php-fpm.conf
user = daemon
group = daemon
listen = /dev/shm/php-fpm.sock
listen.owner = daemon
listen.group = daemon
pm = static
pm.max_children = 4
pm.max_requests = 2048
修改/etc/httpd24/httpd.conf
添加
AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps
 DirectoryIndex  index.php  index.html
去掉mod_proxy.so和mod_proxy_fcgi.so之前的注释,确保他们被apache加载
在行尾添加
<FilesMatch \.php$>
         SetHandler "proxy:fcgi://127.0.0.1:9000"</FilesMatch>
运行php-fpm,并查看9000端口是否监听
##############################################################################

#编译为模块
1、解决依赖关系:
请配置好yum源(系统安装源及epel源)后执行如下命令:
# yum -y groupinstall "Desktop Platform Development" 
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
2、编译安装php-5.4.26
下载源码包
http://cn2.php.net/distributions/php-5.6.26.tar.gz
# tar xf php-5.6.26.tar.gz
# cd php-5.6.26
# ./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
说明:
这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
# make
# make test
# make intall
为php提供配置文件:
# cp php.ini-production /etc/php.ini
新增加环境变量
# 
cat
 /etc/profile.d/apache.
sh
PATH
=/usr/local/php/
bin:$PATH
export PATH
3、 编辑apache配置文件httpd.conf,以apache支持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示例如下:
    <?php
    phpinfo();      
    ?>

原创文章,作者:N21-沉舟,如若转载,请注明出处:http://www.178linux.com/48982

(0)
N21-沉舟N21-沉舟
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:43

相关推荐

  • ☞yum源的生成与配置{ local;cdrom;http;ftp;}

    ☞yum源的生成与配置{ local;cdrom;http;ftp;} 本文是继上一篇文章“CentOS程序安装的3种方式{ 源码包安装 | rpm包安装 | yum安装;}”的补充,上篇文章http://www.178linux.com/38812主要介绍了基于cdrom的yum源制作和配置以及归纳了详细的yum命令。本文继续介绍基于本地file、远程ht…

    Linux干货 2016-08-24
  • OpenSSL 的使用详解

    OpenSSL 是一个开源项目,其组成主要包括一下三个组件:     openssl:多用途的命令行工具     libcrypto:加密算法库     libssl:加密模块应用库,实现了ssl及tls openssl可以实现:秘钥证书管…

    Linux干货 2016-09-23
  • 第三周博客作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who (unknown) :0           2016-12-15 2…

    Linux干货 2016-12-20
  • 10分钟学会理解和解决MySQL乱码问题

    本文将详细介绍MySQL乱码的成因和具体的解决方案。在阅读本文之前,强烈建议对字符集编码概念还比较模糊的同学 阅读下博主之前对相关概念的一篇科普:十分钟搞清字符集和字符编码 MySQL出现乱码的原因 要了解为什么会出现乱码,我们就先要理解:从客户端发起请求,到MySQL存储数据,再到下次从表取回客户端的过程中,哪些环节会有编码/解码的行为。为了更好的解释这个…

    2015-03-17
  • 常用RAID级别浅析

    简介:    RAID为独立冗余磁盘阵列的简称,它可以通过软件或硬件技术把多个较小的磁盘整合成一个较大的磁盘。从而实现较大的 磁盘存储,容错及数据保护功能,较快的数据读写等功能. 实现方式:      硬件实现方式:通过bios参数调整来实现      软件实…

    2017-06-17
  • 运维自动化之系统安装

    自动化安装系统,cobbler的安装使用

    Linux干货 2018-01-15

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-27 09:23

    写的很好,图画的也很好,就是排版有点问题,还有一个题怎么没写那?