1、请描述一次完整的http请求处理过程; (1) 建立或处理连接:接收请求或拒绝请求 (2) 接收请求:接收来自于网络的请求报文中对某资源的一次请求的过程;并发访问响应模型(Web I/O): //服务器接受客户端的请求 单进程I/O结构:启动一个进程处理用户请求,而且一次只处理一个;多个请求被串行响应; //一个进程只有一个线程 多进程I/O结构:并行启动多个进程,每个进程响应一个请求; (3) 处理请求:对请求报文进行解析,并获取请求的资源及请求方法等相关信息 (4) 访问资源:获取请求报文中请求的资源;web服务器,即存放了web资源的服务器,负责向请求者提供对方请求的静态资源,或动态运 行后生成的资源;这些资源放置于本地文件系统某路径下,此路径通常称为DocRoot (5) 构建响应报文 (6) 发送响应报文 (7) 记录日志 2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。 prefork:多进程模型,每个进程响应一个请求;一个主进程:负责生成n个子进程,子进程也称为工作进程,每个子进程处理一个用户请 求;即便没有用户请求,也会预先生成多个空闲进程,随时等待请求到达;最大不会超过1024个; //完成请求后不会销毁,放到空闲进 程中,就不会重复创建销毁了 worker:多线程模型,每个线程响应一个请求; //和prefork不相上下 一个主进程:生成多个子进程,每个子进程负责生个多个线程,每个线程响应一个请求; m进程,n线程:m*n event:事件驱动模型,每个线程响应n个请求;一个主进程:生成m个子进程,每个进程直接n个请求;m*n 3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。 apr [root@node2 LAMP]# tar xf apr-util-1.5.4 [root@node2 LAMP]# cd apr-1.5.2 [root@node2 apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@node2 apr-1.5.2]# make && make install 出现错误 rm: cannot remove `libtoolT': No such file or directory RM='$RM'改为RM='$RM -f' apr-util [root@node2 LAMP]# tar xf apr-util-1.5.4 [root@node2 LAMP]# cd apr-util-1.5.4 [root@node2 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@node2 apr-util-1.5.4]# make && make install httpd 2.4 [root@node2 LAMP]# tar xf httpd-2.4.23.tar.bz2 [root@node2 LAMP]# cd httpd-2.4.23 [root@node2 httpd-2.4.23]# ./configure --prefix=/usr/local/apache --sysconfdir=/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-modulse=most --enable-mpms-shared=all --with-mpm=event [root@node2 httpd-2.4.23]# make && make install [root@node2 /]# cp /etc/rc.d/init.d /etc/rc.d/init/httpd24 [root@node2 /]# service httpd24 start 正在启动 httpd:/bin/bash: /usr/sbin/httpd: No such file or directory [失败] [root@node2 init.d]# vim httpd24 apachectl=/usr/sbin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} [root@node2 /]# mkdir /mysql [root@node2 /]# groupadd -r mysql [root@node2 /]# useradd -g mysql -r -s /sbin/nologin -M -d /mysql mysql [root@node2 /]# chown -R mysql:mysql /mysql [root@node2 LAMP]# tar xf mariadb-10.0.12.tar.gz -C /usr/local [root@node2 LAMP]# cd /usr/local/ [root@node2 local]# ln -sv mariadb-10.0.12 mysql "mysql" -> "mariadb-10.0.12" [root@node2 local]# cd mysql/ [root@node2 /]# yum -y install cmake ncurses-devel [root@node2 mariadb-10.0.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data/ -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci [root@node2 mariadb-10.0.12]# make -j 10 && make install [root@node2 local]# chown -R mysql:mysql mariadb-10.0.12 [root@node2 mariadb-10.0.12]# scripts/mysql_install_db --user=mysql --datadir=/mysql [root@node2 mariadb-10.0.12]# cp /usr/local/mariadb-10.0.12/support-files/mysql.server /etc/rc.d/init.d/mysqld [root@node2 init.d]# vim /etc/rc.d/init.d/mysql basedir=/usr/local/mysql datadir=/mysql [root@node2 support-files]# cp /usr/local/mariadb-10.0.12/support-files/my-large.cnf /etc/my.cnf [root@node2 support-files]# vim /etc/my.cnf basedir=/usr/local/mysql datadir=/mysql [root@node2 init.d]# chmod 755 mysqld [root@node2 init.d]# service mysqld start Starting MySQL.. SUCCESS! *:57494 *:* [root@node2 init.d]# [root@node2 /]# /usr/local/mariadb-10.0.12/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. MariaDB [(none)]> 3.编译安装php 解决依赖关系: yum -y groupinstall "Desktop Platform Development" yum -y install bzip2-devel libmcrypt-devel libxml2-devel [root@node2 LAMP]# tar xf php-5.4.26.tar.bz2 [root@node2 php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysql=/usr/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=/e tc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts [root@node2 php-5.4.26]# make && make install [root@node2 php-5.4.26]# cp php.ini-production /etc/php.ini //提供配置文件 [root@node2 php-5.4.26]# vim /etc/httpd24/httpd.conf //启用php模块 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 定位至DirectoryIndex index.html 修改为:DirectoryIndex index.php index.html 4.安装wordpress [root@node2 LAMP]# tar xf wordpress-4.5.3-zh_CN.tar.gz -C /usr/local/apache/htdocs/ [root@node2 LAMP]# cd /usr/local/apache/htdocs/wordpress [root@node2 LAMP]# cp wp-config-sample.php wp-config.php # vim !$ define('DB_NAME', 'mysql'); /** MySQL数据库用户名 */ define('DB_USER', 'admin'); /** MySQL数据库密码 */ define('DB_PASSWORD', '123456'); /** MySQL主机 */ define('DB_HOST', 'localhost'); 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@node1 /]# htpasswd -c -m /etc/httpd/conf.d/.htpasswd tom [root@node1 /]# mkdir -pv /web/vhosts/{www1,wwww2} [root@node1 /]# echo "<h1>www1 </h1>" /web/vhosts/www1/index.html [root@node1 /]# echo "<h1>www2 </h1>" /web/vhosts/www2/index.html <VirtualHost *:80> DocumentRoot "/web/vhosts/www1" ServerName www1.stuX.com ErrorLog "/var/log/http/www1.error" CustomLog "/var/log/http/www1.access" common <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 192.168.1 Options None AllowOverride None AuthType Basic AuthUserFile "/etc/httpd24/httpd.conf/.passwd" require user </location> </VirtualHost> <VirtualHost *:80> DocumentRoot "/web/vhosts/www2" ServerName www2.stuX.com ErrorLog "/var/log/http/www2.error" CustomLog "/var/log/http/www2.access" common </VirtualHost> 5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点; (1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu); (2)设置部门为Ops,主机名为www2.stuX.com,邮件为admin@stuX.com; [root@node1 /]# cd /etc/pki/CA/ [root@node1 CA]# touch index.txt [root@node1 CA]# echo 01 > serial [root@node1 CA]# (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048) Generating RSA private key, 2048 bit long modulus ......................+++ .....................................................................................................+++ e is 65537 (0x10001) [root@node1 CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 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 []:admin@stuX.com [root@node1 httpd]# openssl ca -in /etc/httpd/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365 6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。 编译成httpd模块 [root@node1 /]# yum -y groupinstall "Desktop Platform Development" [root@node1 /]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel [root@node1 apache]# tar xf php-5.4.26.tar.bz2 [root@node1 apache]# cd php-5.4.26 [root@node1 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 [root@node1 php-5.4.26]# make && make install [root@node1 php-5.4.26]# cp php.ini-production /etc/php.ini root@node1 /]# vim /etc/httpd24/httpd.conf <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 编译成fpm [root@node1 apache]# tar xf php-5.4.26.tar.bz2 [root@node1 apache]# cd php-5.4.26 [root@node1 php-5.4.26]# ./configure --prefix=/usr/local/php5 --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 --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 [root@node1 php-5.4.26]# make && make install [root@node1 php-5.4.26]# cp php.ini-production /etc/php.ini [root@node1 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm [root@node1 php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm [root@node1 php-5.4.26]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf [root@node1 php-5.4.26]# vim /usr/local/php5/etc/php-fpm.conf pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8 pid = /usr/local/php5/var/run/php-fpm.pid [root@node1 php-5.4.26]# vim /etc/httpd24/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 以上
原创文章,作者:N21_619463772,如若转载,请注明出处:http://www.178linux.com/48557