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)
上一篇 2016-09-26 07:43
下一篇 2016-09-26 07:43

相关推荐

  • 作业–文本处理工具

    1、找出ifconfig命令结果中本机的所有IPv4地址。 [root@liang ~]# ifconfig        #centos6下 eth0      Link encap:Et…

    Linux干货 2016-08-10
  • 博客作业-N22第二周

    1、linux上的文件管理类命令都有那些,其常用的使用方法及其相关示例演示。 答: cp 复制文件 [root@localhost network-scripts]# cp ifcfg-eno16777736 ifcfg-eno.bak [root@localhost network-scripts]# ls ifcfg-eno16777736  …

    Linux干货 2016-08-22
  • redis主/从配置及基于sentinel的故障转移

     一、NoSQL基础概念: ACID:原子性、一致性、隔离性、持久性;特性:数据量大、数据变化非常大(数据增长化、流量分布变化、数据间耦合结构变化)、数据源很多; CAP、BASECAP C:多个数据节点的的数据一致;A:用户发出请求后的有限时间范围内返回结果;P:network partition,网络发生分区后,服务是否依可用;CAP理论:一个分布式系统…

    Linux干货 2017-12-18
  • shell脚本基础

    shell脚本编程基础 1、基本格式 首先在编写shell的开始要声明一下该shell所用的脚本类型,我们也称为shebang机制 eg: #!/bin/bash # Description … 2、bash中的变量的种类 (1)、本地变量 生效范围: 当前shell进程,对当前shell之外的进程及子进程均无效 (2)、环境变量 生效范围: 当前she…

    Linux干货 2017-08-04
  • Linux文件系统-基础学习-文件管理-20160727

    Linux文件系统–基础学习–文件管理 Linux下的文件类型 –:普通文件 :这些文件一般是用一些相关的应用程序创建。它的第一个字符是 – d: 目录文件 :目录在Linux是一个比较特殊的文件。它的第一个字符是 d b: 块设备 :这个种类的文件,是用mknode来创建,用rm来删除,它的第一个字符是b c…

    Linux干货 2016-08-04
  • 第二天作业

    一、Linux 文件管理类命令   cd、pwd、mkdir、rmdir、ls、cp、rm、mv、cat、tac、more、less、head、tail、touch     1、目录类相关命令     cd:change directory 切换目录     pwd:print …

    Linux干货 2016-08-22

评论列表(1条)

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

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