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.www58058.com/48557