N21沉舟11周作業

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

(1) 建立或處理連接:接收請求或拒絕請求
(2) 接收請求:
(3) 處理請求:對請求報文進行解析,并獲取請求的資源及請求方法等相關信息
(4) 訪問資源:獲取請求報文中請求的資源
(5) 構建響應報文
(6) 發送響應報文
(7) 記錄日志

http.jpg

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

#prefork:多進程模型,每個進程響應一個請求;
      一個主進程:負責生成n個子進程,子進程也稱為工作進程,每個子進程處理一個用戶請求;即便沒有用戶請求,也會預先生成多個空閑進程,隨時等待請求到達;最大不會超過1024個;
#worker:多線程模型,每個線程響應一個請求;
      一個主進程:生成多個子進程,每個子進程負責生個多個線程,每個線程響應一個請求;
         m進程,n線程:m*n
#event:事件驅動模型,每個線程響應n個請求;
    一個主進程:生成m個子進程,每個進程直接n個請求;

http_mpm多路處理模塊.jpg

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

(0)
N21-沉舟N21-沉舟
上一篇 2016-09-26
下一篇 2016-09-26

相關推薦

  • 用戶與組管理

    如何成為linux用戶?     在linux系統中,要想從系統中獲取資源、對系統進行管理和控制,就需要向系統申請一個賬號,從而實現特定用途,當申請到賬號后,要對它設置口令,這樣用戶賬號就申請成功了,然后可以登陸系統,當用戶登陸系統時,需要通過系統的認證,認證成功后才給予授權,在用戶的使用過程中還會對用戶進行審計。 為什么要設置…

    Linux干貨 2016-08-08
  • linux中用ACL實現靈活的權限管理

    ACL是什么?? ACL英文原意是Access Control List(訪問控制列表).它能夠實現靈活的權限管理,除了文件的所有者,所屬組和其他人,設置相應的權限外,ACL允許你給任何用戶或是用戶組設置任何文件/目錄的訪問權限(注意的是有些不支持數字模式的權限給定) ACL有什么用?? 作為UGO權限管理的補充,acl有GUO辦不到或者是難以辦到的功能 &…

    Linux干貨 2016-08-05
  • FHS文件系統各目錄功能

    前言 FHS將文件根據不同的用途和特性分成了可共享的(shareable)和不可共享的(unshareable),可變的(variable)和靜態的(static)。不同的文件位于不同的目錄里面,將目錄分開了將有利于對文件的管理。 文件系統 可共享的 文件可以被存儲于某一個主機上,然后供其他主機使用。如果想訪問其他主機上可共享的文件,可以將其他主機目錄掛載到…

    Linux干貨 2016-10-17
  • 網絡中多網卡和多ip中的高可用

    一、虛擬網卡實現一個網卡多個地址 1、單個網卡實現多個ipv4地址,只需要在該網卡的配置文件的目錄新增網卡配置文件即可。進入網卡"eth0"的目錄下 2、新增網卡配置文件"ifcfg-eth0:0"和"ifcfg-eth0:1" 3、關掉NetworkManager服務 4、重啟網卡,讓系統重讀配置…

    Linux干貨 2016-09-10
  • Hadoop HDFS分布式文件系統設計要點與架構

    Hadoop簡介:一個分布式系統基礎架構,由Apache基金會開發。用戶可以在不了解分布式底層細節的情況下,開發分布式程序。充分利用集群的威力高速運算和存儲。Hadoop實現了一個分布式文件系統(Hadoop Distributed File System),簡稱HDFS。HDFS有著高容錯性的特點,并且設計用來部署在低廉的(low-cost)硬件…

    Linux干貨 2015-04-13
  • 文件相關操作練習

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限: 2、編輯/etc/group文件,添加組hadoop: 3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop: 4、復制/etc/sk…

    2017-11-17

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-27 09:23

    寫的很好,圖畫的也很好,就是排版有點問題,還有一個題怎么沒寫那?

欧美性久久久久