1、請描述一次完整的http請求處理過程;
http全稱超文本傳輸協議,屬于應用層協議;常見客戶端應用是各種瀏覽器。
一次服務器端完整http請求處理過程:
(1)建立或處理連接:接收請求或拒絕請求;
(2)接收請求:接收來自于網絡上的主機請求報文中對某特定資源的一次請求過程;
http傳輸前要使用TCP協議通過三次握手建立連接(TCP是傳輸層的傳輸控制協議,是一種面向連接的、可靠的基于字節流的傳輸層控制協議)
(3)處理請求:對請求報文進行解析,獲取客戶端請求資源及請求方法等相關信息;
(4)訪問資源:獲取請求報文中請求的資源;
(5)構件響應報文;
(6)發送響應報文;
(7)記錄日志。
————————————————————————————————————–
2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。
處理模型:
(1)單進程I/O模型:啟動一個進程處理用戶請求;一次只能處理一個請求,多個請求被串行響應;
響應1+1+1+…
(2)多進程I/O結構:并行啟動多個進程,每個進程響應一個請求;一個客戶端可以發多個請求;
響應n
(3)復用的I/O結構:一個進程響應n個請求:
多線程模式:一個進程生成n個線程,一個線程處理一個請求;響應n*1個;
事件驅動:一個進程直接響應n個請求;響應1*n個;
(4)復用的多進程I/O結構:啟動m個進程,每個進程生產n個線程,響應請求m*n個。
————————————————————————————————
3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。
方法一:源碼編譯安裝LAMP在CentOS 7上:
下載mariadb-10.0.13.tar.gz,httpd-2.4.9.tar.bz2,php-5.4.26.tar.bz2
(1)安裝mariadb
yum install -y gcc gcc-c++ libtool automake autoconf cmake python-devel libxml2-devel libpng-devel c url-devel freetype-devel mesa-libGL-devel mysql-server mysql-devel libvorbis-devel tar xf mariadb-10.0.13.tar.gz -C /usr/local ln -sv mariadb-10.0.13 mysql cd mysql/ cmake . -LH make make install useradd mysql chown -R root.mysql ./* mkdir /mydata/data -p chown -R mysql.mysql /mydata/data/ mkdir /etc/mysql cp support_files/my-medium.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf [mysqld]后添加幾行代碼 datadir=/mydata/data innodb_file_per_table=ON skip_name_resolve=ON cp support-files/mysql.service /etc/rc.d/init.d/mysqld chkconfig --add mysqld scripts/mysql_install_db --user=mysql --datadir=/mydata/data service mysqld start vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH ./etc/profile.d/mysql.sh vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib ldconfid
(2)安裝httpd 2.4
yum -y groupinstall "開發工具" "服務器開發平臺" yum install -y pcre-devel apr-util-devel apr-devel openssl-devel tar xf httpd-2.4.9.tar.bz2 -C /usr/local cd /usr/local cd httpd-2.4.9 ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-arp-util=/usr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork make -j 4 && make install vim /etc/profile.d/httpd.sh export PATH=/usr/local/apache24/bin:$PATH apachectl start ss -tnl 訪問http://192.168.1.103,顯示http測試頁
(3)安裝php
yum install libxml2-devel libmcrypt-devel ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apx2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 make -j 4 && make install 在php安裝目錄下 cp php.ini-production /etc/php.ini cd /etc/http24 cp httpd.conf {,.backup} vim httpd.conf AddType application/x-httpd-php .php DirectoryIndex index.php index.html apachectl stop apachectl start vim /usr/ocal/apcahe24/htdocs/index.php <?php phpinfo(); ?> rm /usr/local/apache24/htdocs/index.html 訪問http://192.168.1.103
方法二:直接安裝部署LAMP在CentOS 7上:
(1)安裝httpd
yum install httpd -y #安裝httpd rpm -ql httpd #查看httpd安裝的文件 systemctl start httpd.service #啟動服務 systemctl status httpd.service #查看服務狀態 ss -tnl #查看80端口監聽 瀏覽器訪問http://192.168.1.101,顯示測試頁安裝成功 mkdir -pv /web/host1 #創建新的Main server文檔頁面路徑 vim /web/host1/index.html #創建首頁文件,添加一行html代碼 <h1> New Location. </h1> vim /etc/httpd/conf/httpd.conf #編輯配置文件 DocumentRoot "/var/www/html" 修改成 DocumentRoot "/web/host1" <Directory "/var/www"> 修改成 <Directory "/web/host1"> 瀏覽器訪問http://192.168.1.101,顯示New Location.頁
(2)安裝php
yum install php #安裝php rpm -ql php systemctl restart httpd.service #php作為httpd的模塊安裝 重啟httpd服務 systemctl status httpd.service ss -tnl mv /web/host1/index.html /web/host1/index.php #將index.html修改成index.php vim /web/host1/index.php #修改首頁文件,加入幾行代碼 <?php phpinfo(); ?> systemctl restart httpd.service #重啟服務 瀏覽器訪問http://192.168.1.101,顯示php信息頁
(3)安裝mariadb
yum install maridb-server -y yum install php-mysql -y vim /web/host1/index.php #修改php代碼 <?php $conn=mysql_connection('192.168.1.101','testuser','testpass'); if($conn) echo "ok"; else echo "failure"; ?> vim /etc/my.cnf.d/server.cnf [mysqld] skip_name_resolve=ON #禁止登錄反解主機名 mysql >GRANT ALL ON testdb.* TO testuser@'192.168.1.102' IDENTIFIED BY 'testpass';//數據庫登錄授權 >FLUSH PRIVILEGES; systemctl start httpd.service #啟動服務 systemctl start mariadb.service 瀏覽器訪問http://192.168.1.101,顯示ok
(4)安裝wordpress,下載wordpress-4.5.tar.gz放在/web/host1/目錄下
cd /web/host1 tar xf wordpress-4.5.tar.gz cd wordpress cp wp-config-sample.php wp-config.php mysql #連接數據庫 >GRANT ALL ON wpdb.* TO wpuser@192.168.1.101 IDENTIFIED BY 'wpdb'; >CREATE DATABASE wpdb; >exit vim wp-config.php #配置連接的數據庫名稱、用戶、密碼和主機信息 define('DB_NAME','wpdb'); define('DB_USER','wpuser'); define('DB_PASSWORD','wppass'); define('DB_HOST','192.168.1.101'); 訪問http://192.168.1.101/wordpress,填寫信息,安裝生成
————————————————————————————————
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);
將/etc/httpd/conf/httpd.conf文件中的DocumentRoot行注釋,Directory中的路徑刪除 在/etc/httpd/conf.d中創建配置文件vhosts.conf,寫入 <VirtualHost 192.168.1.101:80> ServerName www1.stu.com DocumentRoot "/web/vhosts/www1" Options none </VirtualHost> <Location "/web/vhosts/www1/server-status"> sethandler server-status options none authtype basic authname "log" authuserfile "/etc/httpd/conf/.htpasswd" require user "tom" </Location> <VirtualHost 192.168.1.101:80> ServerName www2.stu.com DocumentRoot "/web/vhosts/www2" </VirtualHost>
vim /web/vhosts/www1/index.html <h1>www1.stu.com</h1> vim /web/vhosts/www2/index.html <h1>www2.stu.com</h1> vim /etc/httpd/conf/httpd.conf #開啟httpd內置模塊 LoadMoudule status_module modules/mod_status.so
vim /etc/hosts #添加DNS解析記錄 192.168.1.101 www1.stu.com www2.stu.com
htpasswd -c -m /etc/httpd/conf/.htpasswd tom #創建賬號密碼文件
systemctl start httpd.service
5、為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;
(1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu);
(2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com;
192.168.1.103作為CA服務器,192.168.1.101作為https服務器
.103
cd /etc/pki/CA/ (umask 077;openssl genrsa -out private/cakey.pem 2048) openssl req -new -x509 -key private/cakey.pem -out cacert.pem #生成CA自己的證書 #填寫CA證書信息:CN HA ZZ MageEdu Ops ca.maedu.com caadmin@magedu.com touch serial index.txt echo 01>serial
.101
cd /etc/httpd mkdir ssl/ (umask 077;openssl genrsa -out httpd.key 1024) #創建私鑰 openssl req -new -key httpd.key -out httpd.csr #填寫證書信息:CN HA ZZ MageEdu Ops www2.stu.com webadmin@stu.com scp httpd.csr root@192.168.1.103:/tmp/
.103
openssl ca -in /tmp/httpd.csr -out certs/httpd.crt scp certs/httpd.crt 192.168.1.101:/etc/httpd/ssl/
.101
yum -y install mod-ssl systemctl restart httpd.service ss -tnl #監聽443端口
.103
openssl s_client -connect www2.stu.com:443 -CAfile /etc/pki/CA/cacert.pem
6、在LAMP架構中,請分別以php編譯成httpd模塊形式和php以fpm工作為獨立守護進程的方式來支持httpd,列出詳細的過程。
(1)php編譯成httpd模塊形式
yum install libxml2-devel libmcrypt-devel ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 make & make install
(2)php以fpm工作為獨立守護進程方式
yum install php-fpm -y yum install httpd -y vim /etc/httpd/conf.d/fcgi.conf DirectoryIndex index.php ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1 httpd -t systemctl start httpd.service vim /var/www/html/index.php <?php phpinfo() ?>
訪問172.16.100.67/index.php和172.16.100.67驗證
原創文章,作者:N22_Elephant,如若轉載,請注明出處:http://www.www58058.com/54524