马哥教育网络班21期+第12周课程练习

httpd学习前知识必备:

I/O类型

  • 同步和异步 synchronous asynchronous 

关注的是消息通知机制,如何通知调用者,站在被调用者的角度

同步:调用发出后不会立即返回,一旦返回即是最终结果

异步:调用发出后会立即返回消息,但不是最终结果,被调用者通过状态,通知机制,或回调函数处理结果

  • 阻塞和非阻塞 block nonblock

关注的是调用者等待调用结果时的状态,站在调用者角度

阻塞: 调用结果返回之前,调用者会被挂起,调用者只有在得到返回结果后才能继续

非阻塞: 调用结果返回之前,调用者不会被挂起,调用不会阻塞调用者,调用者不断的检查调用结果

I/O模型

  • 阻塞式blocking

磁盘数据到内核内存blocking;数据从内核内存到进程内存blocking,进程不能响应其他请求(进程被挂起)

  • 非阻塞nonblocking

磁盘数据到内核内存nonblocking;数据从内核内存到进程内存blocking,忙等待状态,进程不能响应其他请求

  • IO复用IO multiplexing

假如进程需要网络IO,磁盘IO ,进程阻塞到内核的select,epoll等函数上,没有被挂起,因此进程也可也处理网络IO或其他IO

  • 事件驱动signal driven IO

磁盘数据到内核内存nonblocking;但是有通知机制,数据从内核内存到进程内存blocking,进程可以响应其他请求

水平触发(多次通知),边缘触发(只通知一次,当进程没有收到时,之后进程可以调用相应的函数回调得到通知结果)

  • asynchronous IO AIO

进程进行IO调用,内核有通知机制,之后内核负责磁盘数据到内核内存,数据从内核内存到进程内存,进程能响应其他请求

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

  • 建立或处理连接:接收请求或拒绝请求

  • 接收请求:

  • 处理请求:对请求报文进行解析,并获取请求的资源及请求方法等相关信息

  • 访问资源:获取请求报文中请求的资源

  • 构建响应报文:

  • 发送响应报文:

  • 记录日志

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

  • prefork 多进程模型,主进程,生成多个子进程,每个子进程响应一个请求,当没有用户请求时,也

预留几个子进程等待用户请求

  • work  多线程模型,主进程,生成多个子进程,每个子进程负责产生多个线程,每个线程处理一个请求

  • event 事件驱动模型,主进程,生成多个子进程,每个子进程直接响应用户多个请求

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

  • apache配置

[root@centos apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@centos apr-util-1.5.2]# ./configure --prefix=/usr/local/apr_utils --with-apr=/usr/local/apr/
[root@centos httpd-2.4.9]# yum install *pcre* -y
[root@centos httpd-2.4.9]#  ./configure --prefix=/usr/local/apache 
--sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite
 --enable-defalte --with-zlib --with-pcre --with-apr=/usr/local/apr 
 --with-apr-util=/usr/local/apr_utils --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
修改httpd的主配置文件,添加ServerName fqdn 或 ip  PidFile "/var/run/httpd.pid" ,
其中网站根目录为 DocumentRoot "/usr/local/apache/htdocs",默认启用了中心主机
[root@centos ~]# cat /usr/local/apache/htdocs/index.html 
<html><body><h1>It works!</h1></body></html>
[root@centos ~]# curl 192.168.40.128
<html><body><h1>It works!</h1></body></html>
  • Mysql安装和配置

[root@centos local]# groupadd -r mysql
[root@centos local]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@centos ~]# ln -sv  /usr/local/mysql-5.6.13 /usr/local/mysql
[root@centos mysql]# yum install cmake
[root@centos mysql]# cmake .
[root@centos mysql]# make && make install
[root@centos scripts]# chmod +x mysql_install_db.sh 
[root@centos scripts]# ./mysql_install_db.sh --user=mysql --basedir=/usr/local/mysql 
--datadir=/mydata
[root@centos support-files]# vim /etc/my.cnf 
[root@centos support-files]# service mysql start
Starting MySQL.                                            [  OK  ]
[root@centos support-files]# cat /etc/my.cnf 
basedir =/usr/local/mysql
datadir =/mydata
port =3306
# server_id = .....
# socket = .....
--------------------
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on wordpress.* to [email protected] identified by "centos6";
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
  • 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-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
# make
# make test
# make intall
# cp php.ini-production /etc/php.ini
# vim /etc/httpd/httpd.conf
   AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps
   DirectoryIndex  index.php  index.html
[root@centos ~]# tar zxf wordpress-4.5.3-zh_CN.tar.gz /test/
  • 测试

[root@centos test]# mv wordpress /usr/local/apache/htdocs/

之后在浏览器中输入http://web/wordpress 按照导向安装完成即可,重点编辑wp-config.php文件来定义wordpress使用的数据库,登录用户名密码等信息

QQ截图20160817102744.jpg

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

禁用中心主机
[root@centos ~]# vim /etc/httpd24/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs"
Include /etc/httpd24/extra/httpd-vhosts.conf
配置虚拟主机
[root@centos ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 
<VirtualHost 192.168.40.128:80>
    DocumentRoot "/web/vhost/www1/"
    ServerName www1.test.com
    ErrorLog "/var/log/httpd/www1.err"
    CustomLog "/var/log/httpd/www1.access" common
<Directory "/web/vhost/www1">
 AllowOverride None
    Options None
    Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.40.128:80>
    DocumentRoot "/web/vhost/www2/"
    ServerName www2.stuX.com
    ErrorLog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
<Directory "/web/vhost/www2/">
 AllowOverride None
    Options None
    Require all granted
</Directory>
</VirtualHost>
[root@centos ~]# vim /etc/hosts
127.0.0.1 www1.stuX.com www2.stuX.com
[root@centos ~]# mkdir -p /web/vhost/{www1,www2} && echo "www1.site" > /web/vhost/www1/index.html && echo "www2.site" 
> /web/vhost/www2/index.html
[root@centos ~]# /usr/local/apache/bin/apachectl restart
[root@centos ~]# curl www1.stuX.com
www1.site
[root@centos ~]# curl www2.stuX.com
www2.site
更改第二个虚拟主机为下面所示
<VirtualHost 192.168.40.128:80>
    DocumentRoot "/web/vhost/www2/"
    ServerName www2.stuX.com
    ErrorLog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
<Directory "/web/vhost/www2/">
 AllowOverride None
    Options None
    Require all granted
</Directory>
<Location /server-status>
AuthType Basic
AuthName "Only for Admin"
AuthUserFile "/usr/local/apache/.htpasswd"
Require valid-user
SetHandler server-status
 AllowOverride None
    Options None   
</Location>
</VirtualHost>
[root@centos bin]# ./htpasswd -m -c /usr/local/apache/.htpasswd admin
New password: 
Re-type new password: 
Adding password for user admin
[root@centos bin]# curl www2.stuX.com/server-status
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>

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

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

   (2)设置部门为Ops,主机名为www2.stuX.com,邮件为[email protected]

[root@centos CA]# touch index.txt serial
[root@centos CA]# echo 01 > serial 
[root@centos CA]# (umask 077;openssl genrsa -out ./private/cakey.pem 1024)
Generating RSA private key, 1024 bit long modulus
.......................................................++++++
.......++++++
e is 65537 (0x10001)
[root@centos CA]# openssl req -new  -x509 -key ./private/cakey.pem -out ./cacert.pem
[root@centos CA]# cd /usr/local/apache/
[root@centos apache]# mkdir ssl
[root@centos apache]# (umask 077;openssl genrsa -out ./ssl/http.key 1024)
[root@centos CA]# cd /usr/local/apache/
[root@centos apache]# mkdir ssl
[root@centos apache]# (umask 077;openssl genrsa -out ./ssl/http.key 1024)
Generating RSA private key, 1024 bit long modulus
..................................++++++
.......................................++++++
e is 65537 (0x10001)
[root@centos apache]# openssl req -new -key ./ssl/http.key -out ./ssl/http.crst -days 3600
[root@centos apache]# openssl ca -in ./ssl/http.crst -out ./ssl/http.crt -days 3600
[root@centos ~]# cd /usr/local/apache/ssl/
[root@centos ssl]# ls
http.crst  http.crt  http.key
之后修改/etc/httpd24/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include /etc/httpd24/extra/httpd-ssl.conf
然后编辑/etc/httpd24/extra/httpd-ssl.conf如下
<VirtualHost _default_:443>
    DocumentRoot "/web/vhost/www2/"
    ServerName www2.stuX.com
    ErrorLog "/var/log/httpd/www2.err"
    CustomLog "/var/log/httpd/www2.access" common
<Directory "/web/vhost/www2/">
 AllowOverride None
    Options None
    Require all granted
</Directory>
SSLCertificateFile "/usr/local/apache/ssl/http.crt"
SSLCertificateKeyFile "/usr/local/apache/ssl/http.key"
</VirtualHost>

测试

QQ截图20160817160801.jpg

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

  • 把php编译成httpd以fpm工作为独立守护进程的方式来支持httpd,需要在上例编译http的基础上修改和配置php编译时要加上–enable-fpm选项

[root@centos ~]# cd /usr/local/php-5.6.24/sapi/fpm/
[root@centos fpm]# ls
config.m4       init.d.php-fpm.in  php-fpm.8        php-fpm.service     tests
CREDITS         LICENSE            php-fpm.8.in     php-fpm.service.in
fpm             Makefile.frag      php-fpm.conf     status.html
init.d.php-fpm  php-fpm            php-fpm.conf.in  status.html.in
[root@centos fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@centos php-5.6.24]# chkconfig --add php-fpm
[root@centos php-5.6.24]# chkconfig php-fpm on
[root@centos fpm]# cd /usr/local/php/etc/
[root@centos etc]# ls
pear.conf  php-fpm.conf.default
[root@centos etc]# mv php-fpm.conf.default php-fpm.conf
[root@centos etc]# service php-fpm start
Starting php-fpm  done
[root@centos etc]# ss -antl    
LISTEN      0      128               127.0.0.1:9000                     *:*     
[root@centos htdocs]# cp test.php /web/vhost/www2/
#LoadModule php5_module        modules/libphp5.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
在上面的例子的www2.stuX.虚拟主机站点添加下面两行
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/web/vhost/www2/$1
  • 测试

QQ截图20160818125532.jpg

  • 总结 关于http,php,mysql编译选项,由于篇幅有限请多–help了解

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

(0)
SnooSnoo
上一篇 2016-08-15 14:31
下一篇 2016-08-15 16:39

相关推荐

  • Mysql 报错解决–PID file could not be found!

    今天想把之前在cetnos6上编译安装的mariadb改下PATH环境变量,操作几次之后,关闭或重启mysql就失败了,提示如下: [root@web1 ~]# service mysqld stop MySQL server PID file could not&nb…

    系统运维 2016-09-19
  • N25第二周作业

    第二周作业 一、Linux上的文件管理类命令有哪些,其常用的使用方法以及相关实例演示 演示用结构  [root@centos01 yanshi]# tree -a /tmp/yanshi/   /tmp/yanshi/ ├── a │   └── 1…

    Linux干货 2016-12-14
  • N29 第一周作业

    1、描述计算机的组成及其功能。
    2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
    3、描述Linux的哲学思想,并按照自己的理解对其进行解释性描述。
    4、说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,并配合相应的示例来阐述。
    5、如何在Linux系统上获取命令的帮助信息,请详细列出,并描述man文档的章节是如何划分的。
    6、请罗列Linux发行版的基础目录名称命名法则及功用规定

    Linux干货 2018-03-05
  • http协议简介

        http:Hyper Text Transfer Protocol,超文本传输协议。是互联网上应用最为广泛的一种网络协议。所有的WWW文件都必须遵守这个标准。设计HTTP最初的目的是为了提供一种发布和接收HTML页面的方法。1960年美国人Ted Nelson构思了一种通过计算机处理文本信息的方法,并称之为超文本(hyp…

    Linux干货 2015-11-18
  • Zabbix 发现功能中文文档

    说明:本文译自 zabbix 官方文档 Discovery 一节,包括 Network Discovery, Auto Registration和Low level discovery,同时对文章进行了补充以及更详细的说明。适用于Zabbix 2.0 版本。 发现包括三种类型: 网络发现 ( Network discovery) 主动客户端自动注册 ( Ac…

    Linux干货 2015-03-12
  • 文件权限

    浅谈文件权限 Linux系统中的每个文件和目录都有访问许可权限,用他来确定谁能通过何种方式对文件和目录进行访问和操作。  文件权限: 文件或目录的访问权限分为只读,只写和可执行三种。  文件的权限主要针对三类对象进行定义:          owne…

    Linux干货 2016-08-07

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-22 15:06

    写的很好,排版还可以在漂亮一点,加油