1、請描述一次完整的http請求處理過程;
(1) 建立或處理連接:接收請求或拒絕請求 (2) 接收請求: (3) 處理請求:對請求報文進行解析,并獲取請求的資源及請求方法等相關信息 (4) 訪問資源:獲取請求報文中請求的資源 (5) 構建響應報文 (6) 發送響應報文 (7) 記錄日志
2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。
#prefork:多進程模型,每個進程響應一個請求; 一個主進程:負責生成n個子進程,子進程也稱為工作進程,每個子進程處理一個用戶請求;即便沒有用戶請求,也會預先生成多個空閑進程,隨時等待請求到達;最大不會超過1024個; #worker:多線程模型,每個線程響應一個請求; 一個主進程:生成多個子進程,每個子進程負責生個多個線程,每個線程響應一個請求; m進程,n線程:m*n #event:事件驅動模型,每個線程響應n個請求; 一個主進程:生成m個子進程,每個進程直接n個請求;
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.www58058.com/48982
寫的很好,圖畫的也很好,就是排版有點問題,還有一個題怎么沒寫那?