22期第十二周課堂練習

1、請描述一次完整的http請求處理過程;

(1)建立和處理連接:接收請求或者拒絕請求;

(2)接收請求:接收來自于網絡上的主機請求報文中對某特定的資源的一次請求的過程;

(3)處理請求:對請求報文進行解析,獲取客戶端請求的資源及請求方法等相關信息

(4)訪問資源:獲取請求報文中請求的資源

(5)構建響應報文;

(6)發送響應報文;

(7)記錄日志;

2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。

prefork:多進程模型,每個進程響應一個請求;

一個主進程:負責生成子進程及回收子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;

n個子進程:每個子進程處理一個請求;

工作模型:會預先生成幾個空閑進程,隨時等待用于響應用戶請求;最大空閑和最小空閑;

適用場景:它適合于沒有線程安全庫,需要避免線程兼容性問題的系統。它是要求將每個請求相互獨立的情況下最好的MPM,這樣若一個請求出現問題就不會影響到其他請求,適合于并發量適中而又追求穩定的用戶使用。

worker:多進程多線程模型,每線程處理一個用戶請求;

一個主進程:負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;

多個子進程:每個子進程負責生成多個線程;

每個線程:負責響應用戶請求;

并發響應數量:m*n

m:子進程數量

n:每個子進程所能創建的最大線程數量;

適用場景:占據更少的內存,高并發下表現更優秀。

event:事件驅動模型,多進程模型,每個進程響應多個請求;

一個主進程 :負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;

子進程:基于事件驅動機制直接響應多個請求;

適用場景:event模型是三種模型中效率最高的一種,可以突破10K的限制(即并發數1W),對海量的系統特別適用。

3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。

 1.httpd源碼編譯

(1) apr-1.4+
# ./configure --prefix=/usr/local/apr
# make && make install
(2) apr-util-1.4+
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
(3) httpd-2.4
# ./configure --prefix=/usr/local/apache24 --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-modules=most --enable-mpms-shared=all --with-mpm=prefork
# make && make install
(4)pcre-devel
# yum install pcre-devel -y
(5) openssl
# yum install openssl-devel -y
(6)導出二進制程序目錄至PATH環境變量中
  vim /etc/profile.d/httpd.sh
  export PATH=/usr/local/apache24/bin:$PATH
 (7)導出httpd頭文件
#ln -s /usr/local/apache24/include/ /usr/include/httpd/
(8)添加chkconfig啟動服務
 [root@www apache24]# cd /etc/rc.d/init.d/
 [root@www init.d]# cp httpd httpd24
  [root@www init.d]# vim httpd24
  #if [ -f /etc/sysconfig/httpd ]; then //將此行注釋掉
        . /etc/sysconfig/httpd
 #fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache24/bin/apachectl //修改路徑
httpd=${HTTPD-/usr/local/apache24/bin/httpd} //修改路徑
prog=httpd
pidfile=${PIDFILE-/usr/local/apache24/logs/httpd.pid} //修改路徑
lockfile=${LOCKFILE-/var/lock/subsys/httpd24} //修改路徑
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
[root@www init.d]# chkconfig --add httpd24
[root@www init.d]# chkconfig --list httpd24
httpd24        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@www init.d]# service httpd24 start
Starting httpd:                                            [  OK  ]
[root@www init.d]# service httpd24 status
httpd (pid  37687) is running...
[root@www init.d]# ss -ntl |grep 80
LISTEN     0      128                      :::80                      :::*

 2.mysql二進制安裝

 1.創建mysql用戶與組
 [root@www mysql]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
 2.創建Mysql目錄并修改屬主與屬組
 [root@localhost ~]# mkdir -pv /mydata/data/
 [root@localhost mysql]# chown mysql:mysql /mydata/data/
 3.解壓mysql安裝包到/usr/local
 [root@www mnt]# tar -zxf mysql-5.5.54-linux2.6-x86_64.tar.gz -C /usr/local/
 4.創建軟連接
 [root@www local]# ln -sv mysql-5.5.54-linux2.6-x86_64 mysql
 5.修改/usr/local/mysql/目錄下所有文件和子目錄的屬主,屬組:
  [root@localhost mysql]# chown -R root:mysql ./*
  6.創建/etc/mysql/目錄,并復制 support-files/my-large.cnf到/etc/mysql/目錄下,更名為my.cnf
  [root@localhost mysql]# mkdir /etc/mysql
  [root@localhost mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
  7.編輯/etc/mysql/my.cnf文件:
  [root@localhost mysql]# vim /etc/mysql/my.cnf
  (在[mysqld]段下面加入以下三行)
  datadir = /mydata/data
  skip_name_resolve = ON
  innodb_file_per_table = ON
  8.初始化mysql數據庫:
  [root@localhost mysql]# scripts/mysql_install_db –user=mysql –datadir=/mydata/data
  9.創建mysql服務啟動腳本:
  [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  [root@localhost mysql]# chkconfig –add mysqld
  10.把/etc/my.cnf文件移到/tmp目錄下:
  [root@localhost mysql]#  mv /etc/my.cnf /tmp/
  11.啟動mysql服務:
  [root@localhost mysql]# service mysqld start
  12.修改PATH變量:
  [root@localhost mysql]# vim /etc/profile.d/mysql.sh
  export PATH=/usr/local/mysql/bin:$PATH
  13.重載配置文件:
   [root@localhost mysql]# . /etc/profile.d/mysql.sh
  14.添加/usr/local/mysql/lib/目錄下的庫文件到系統搜索路徑下:
   [root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
    /usr/local/mysql/lib
   15.重新加載模塊,并查看 
   [root@localhost mysql]# ldconfig
   [root@www local]# ldconfig  -p |grep mysql
	libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16
	libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
	libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16
	libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so

 3.php源碼編譯

1.安裝依賴包
[root@www php-5.4.26]# yum install libxml2-devel libmcrypt-devel
2.檢查
[root@www 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-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
3.編譯并安裝
[root@www php-5.4.26]# make -j 4 && make install
4.復制配置文件至/etc/php.ini
[root@www php-5.4.26]# cp php.ini-production /etc/php.ini
5.修改/etc/httpd.conf
[root@localhost httpd24]# vim httpd.conf
加入下面兩行:
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
6.新建一個php頁面測試
[root@localhost httpd24]vim /usr/local/apache24/htdocs/index.php
<?php
         phpinfo()
 ?>
 7.測試成功的話,再進行測試與mysql連接
[root@localhost httpd24]vim /usr/local/apache24/htdocs/index.php
 <?php
          $conn = mysql_connect('127.0.0.1','root','');
          if ($conn)
               echo "ok";
          else
               echo "failure";
?>

 4.wordpress源碼編譯 

 

1.切換到/usr/local/apache24/htdocs/目錄下:
[root@localhost ~]# cd /usr/local/apache24/htdocs/
2.解壓縮:
[root@localhost htdocs]# tar -xf wordpress-4.5.3-zh_CN.tar.gz
3.切換到wordpress目錄下:
[root@localhost htdocs]# cd wordpress/
復制一份wordpress配置文件:
4.[root@localhost wordpress]# cp wp-config-sample.php wp-config.php
登陸mariadb數據數據庫:
5.[root@localhost wordpress]# mysql
授權用戶:
ariaDB [(none)]> grant all on wpdb.* to wpuser@'%' identified by '123456';
創建數據庫:
MariaDB [(none)]> create database wpdb;
6.編輯wo-config.php文件;
[root@localhost wordpress]# vim wp-config.php
/** WordPress數據庫的名稱 */define('DB_NAME', 'wpdb');        /(修改為wpdb數據庫)
/** MySQL數據庫用戶名 */                define('DB_USER', 'wpuser');            (修改為wpuser用戶)
/** MySQL數據庫密碼 */define('DB_PASSWORD', '123456');        /(修改密碼為123456)
/** MySQL主機 */define('DB_HOST', '192.168.180.130');        /(修改192.168.180.130這臺主機可以訪問mysql)
至此所有配置完成。
7.可通過網頁http://192.168.180.130/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);

1.創建目錄與日志文件
[root@www ~]# mkdir /web/vhosts/www{1,2} -p
[root@www ~]# touch /var/log/httpd/www{1,2}.{err,access}
[root@www ~]# vim /web/vhosts/www1/index.html
<p> www1 </p>
[root@www ~]# vim /web/vhosts/www2/index.html
<p> www2 </p>

2.編輯httpd主配置文件/etc/httpd/conf/httpd.conf

NameVirtualHost 192.168.2.164:80
<VirtualHost 192.168.2.164:80>
  DocumentRoot /web/vhosts/www1
  ServerName www.a.com
   ErrorLog "/var/log/httpd/www1.err"
   CustomLog "/var/log/httpd/www1.access" combind
  <Location /server-status>
        SetHandler server-status
        Authtype   Basic
        Authname   "status area"
        AuthUserFiLE "/etc/httpd/users/.htpasswd"
        Require  valid-user
  </Location>
</VirtualHost>
<VirtualHost 192.168.2.164:80>
  DocumentRoot /web/vhosts/www2
  ServerName www.b.com
   ErrorLog "/var/log/httpd/www2.err"
   CustomLog "/var/log/httpd/www2.access" combind
</VirtualHost>

3.創建用戶認證文件

[root@www ~]# mkdir /etc/httpd/users
[root@www ~]# htpasswd -c -m /etc/httpd/users/.htpasswd tom
New password:
Re-type newpassword:
Adding passwordfor user status
[root@www ~]## service httpd restart

5、為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;

   (1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu);

   (2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com;

 1.創建私有CA

(1)生成私鑰
[root@localhost ~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
Generating RSA private key, 4096 bit long modulus
.......................++
.........................................................................................++
e is 65537 (0x10001)
 (2)生成自簽名證書
 [root@localhost ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
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
(3)為CA提供所需要的文件和目錄
[root@localhost ~]# mkdir -pv /etc/pki/CA/{certs,crl,newcerts}
[root@localhost ~]# touch /etc/pki/CA/{serial,index.txt}
[root@localhost ~]# echo 01 > /etc/pki/CA/serial

2.http服務器向CA申請證書

(1) 用到證書的主機生成私鑰;
[root@localhost ~]# mkdir /etc/httpd/ssl
[root@localhost ~]# cd /etc/httpd/ssl
[root@localhost ssl]#  (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
(2) 生成證書簽署請求
~]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
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

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:Ops 
(3) 將請求通過可靠方式發送給CA主機;

(4) 在CA主機上簽署證書;
~]# openssl ca -in /etc/httpd/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Dec 11 16:31:18 2016 GMT
            Not After : Dec 11 16:31:18 2017 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HA
            organizationName          = MageEdu
            organizationalUnitName    = Ops
            commonName                = www2.stuX.com
            emailAddress              = admin@stuX.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                42:64:3B:CE:2B:0D:D8:0A:33:00:61:89:F4:78:49:8E:17:18:95:FC
            X509v3 Authority Key Identifier: 
                keyid:E4:B9:8C:C4:EB:B8:72:7F:6A:87:37:0F:A6:54:04:4A:CE:B2:90:8E

Certificate is to be certified until Dec 11 16:31:18 2017 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

3.配置http服務器加密傳輸

1.安裝ssl模塊
[root@localhost certs]# yum install mod_ssl -y
[root@localhost certs]# rpm -q mod_ssl
mod_ssl-2.2.15-29.el6.centos.x86_64
2.修改/etc/httpd/conf.d/ssl.conf
Listen 443
<VirtualHost 192.168.180.130:443>
         DocumentRoot /web/vhosts/www2
         ServerName  www2.stuX.com:443
         SSLEngine on
         SSLCertificateFile  /etc/pki/CA/certs/httpd.crt
         SSLCertificateKeyFile  /etc/httpd/ssl/httpd.key
</VirtualHost>
3.重啟httpd服務
[root@localhost ssl]# service httpd restart
Stopping httpd:                        [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                [  OK  ]

6、在LAMP架構中,請分別以php編譯成httpd模塊形式和php以fpm工作為獨立守護進程的方式來支持httpd,列出詳細的過程

原創文章,作者:a295053193,如若轉載,請注明出處:http://www.www58058.com/62841

(0)
a295053193a295053193
上一篇 2016-12-26
下一篇 2016-12-26

相關推薦

  • redis-cli的一些有趣也很有用的功能

    redis-cli我們最常用的三個參數就是-h、-p、-a選項,分配用來指定連接的redis-server的host、port和登錄密碼。通過redis-cli –help發現,redis-cli還提供了其他很多的參數和功能。 1)-x-x選項從標準輸入(stdin)讀取最后一個參數。 比如從管道中讀取輸入: echo -en &quot…

    Linux干貨 2016-04-13
  • bash的特性總結

    什么是bash:       shell作為用戶與計算機內核交互的接口,是用戶與計算機溝通的橋梁,而bash(borne again shell)是眾多shell里面最為流行一種,bash作為眾多shell里面的一種有著眾多的特性,掌握bash的眾多特性將會是我們今后學習linux必經之路。&nbs…

    Linux干貨 2015-10-27
  • 學習伊始宣言

    學習后的狀態 以人事相宜為追求,優化職業資質 以勝任愉快為目標,保持職業體能 以創造績效為主導,開發職業意識 以適應市場為基點,修養職業道德 學習宣言 如果不踏出第一步就永遠也不可能到達目的地,讓我們從此刻出發

    Linux干貨 2016-11-28
  • 編譯安裝——吐血經驗,內附腳本

    程序包編譯安裝: 源碼包:name-VERSION-release.src.rpm         rpm由源碼包安裝后,使用rpmbuild命令制作成二進制格式的rpm包,而后再安裝        &nbsp…

    Linux干貨 2016-08-24
  • MySQL Fabric 安裝部署

    MySQL Fabric  是一個用于管理 MySQL 服務器群的可擴展框架。該框架實現了兩個特性 — 高可用性 (HA) 以及使用數據分片的橫向擴展。這兩個特性既可以單獨使用,也可以結合使用。 環境: 安裝MySQL Fabric 配置MySQL Fabric MySQL Fabric 安裝管理數據庫fabric 啟動MySQL Fab…

    數據庫運維 2016-06-03
  • N25第三周作業

    一、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。 [root@centos01 ~]# who | cut -d " " -f1 | uniq -u root qufudcj 二、取出最后…

    Linux干貨 2016-12-26

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-01-04 15:57

    寫的很好,按照你的步驟來,完全可以搭建出來想要的東西,排版也很棒,繼續保持

欧美性久久久久