LNMP詳細介紹

1》Nginx概述:javascript

                    不少人對apache很是熟悉,Nginx與Apache相似,屬於WEB容器,同時也是一款高性能的HTTP和反向代理軟件,它們之間最大的差異是Apache的處理速              度很慢,並且佔用不少內存資源,而Nginx卻偏偏相反,在功能實現上,Apache的全部模塊都是支持動靜態編譯,而Nginx模塊都是靜態編譯的,同時Apache對              Fcgi的支持很差,而Nginx對Fcgi支持很是好,在處理鏈接方式上,Nginx支持epoll,而Apache卻不支持,Nginx安裝包只有幾百K,而Apache絕對是個龐然大                    物;   php

    Nginx其優點以下:css

      Ø         做爲WEB服務器, Nginx處理靜態文件、索引文件,自動索引的效率很是高;html

      Ø         做爲代理服務器,Nginx能夠實現無緩存的反向代理加速,提升網站運行速度;前端

      Ø         做爲負載均衡服務器、Nginx能夠在內部直接支持Redis和PHP,能夠支持HTTP代理服務器對外進行服務,同時還支持簡單的容錯和利用算法進行                                    負載;java

      Ø         在性能方面,Nginx是專門爲性能優化開發的,採用Poll模型,最大支持5萬併發鏈接,並且佔用不多一部份內存資源;node

      Ø         在穩定方面採起了分階資源分配技術,使CPU佔用資源很是的低,官方表示Nginx保持1萬個沒有活動的連接,只佔用2.5M的內存,DDOS攻擊對                                    Nginx來講基本上無效;mysql

      Ø         在高可用性方面,Nginx支持熱部署,啓動速度特別迅速,所以能夠不間斷服務狀況下,對軟件版本或者配置升級,即便運行數月也無需啓動,幾                                    乎能夠作到7*24小時不間斷運行;nginx

2》Nginx的模塊與工做原理      web

    Nginx由內核與模塊組成,內核設計很是小巧和簡潔,完成的工做很是簡單,經過配置文件將客戶端請求映射到一個location block,而經過這個localtion中的配         置每個指定都回啓動不一樣模塊,從而完成相應的工做;

   Nginx的模塊從結構上分爲

      核心模塊包含:http模塊、event模塊和mail模塊;

      基礎模塊包含; HTTP Access模塊,Http FastCGI模塊 HTTP Proxy模型和HTTP Rewrite模塊;

      第三方模塊包含:HTTP upstream request模塊,Notice模塊和HTTP Access key 模塊屬於第三方模塊;

     Nginx的模塊從功能上分3類

      Ø         Handerls(處理模塊):此類模塊直接請求,並進行輸出內容和修改headers信心操做,Handlers處理器模塊通常只能有一個;

      Ø         Filters(過濾器模塊):此類模塊主要針對其餘處理器模塊輸出內容進行修改操做,最後由Nginx輸出;

      Ø         Proxies(代理類模塊) :此類模塊式Nginx的HTTP Upstream之類的模塊,這些模塊後端一些服務器好比:FastCGI等進行交互,實現服務代理和負                                                                       載均衡等功能;

                                  

          

        nginx 能夠單個進程工做,也能夠 master+ worker模式工做,因此當使用前者模式啓動的時候,進程就是NGX_PROCESS_SINGLE ; 當使用後者的時                     候,那麼父進程就是 NGX_PROCESS_MASTER,而子進程就是 NGX_PROCESS_WORKER。使用哪一種模式能夠在配置文件中設置,默認使用後者,如                       果配置文件中 masterprocess off 開啓,那麼就使用了前者;

                    master進程主要用來管理worker進程,具體包括以下4個主要功能:
          (1)接收來自外界的信號;
          (2)向各worker進程發送信號;
          (3)監控woker進程的運行狀態;
          (4)當woker進程退出後(異常狀況下),會自動從新啓動新的woker進程;
      woker進程主要用來處理網絡事件,各個woker進程之間是對等且相互獨立的,它們同等競爭來自客戶端的請求,一個請求只可能在一個woker進程中處                          理,woker進程個數通常設置爲機器CPU核數;

                         

3》進程控制    

    對Nginx進程的控制主要是經過master進程來作到的,主要有兩種方式:

    1)手動發送信號
        master接收信號以管理衆woker進程,那麼,能夠經過kill向master進程發送信號,好比kill -HUP pid用以通知Nginx從容重啓。所謂從容重啓就是不中                        斷服務:master進程在接收到信號後,會先從新加載配置,而後再啓動新進程開始接收新請求, 並向全部老進程發送信號告知再也不接收新請求並在處理完                     全部未處理完的請求後自動退出;

    2)自動發送信號
        能夠經過帶命令行參數啓動新進程來發送信號給master進程,好比./nginx -s reload用以啓動一個新的Nginx進程,而新進程在解析到reload參數後會向                       master進程發送信號(新進程會幫咱們把手動發送信號中的動做自動完成)。固然也能夠這樣./nginx -s stop來中止Nginx;

4》Nginx的安裝與配置

      1>安裝依賴庫

           # yum -y install gcc openssl-devel zlib-devel

      2>安裝pcre-delvel庫           

        # cd /soft/

        # tar xf pcre-8.01.tar.gz -C tmp/

        # cd tmp/pcre-8.01/

        #./configure && make && make install

     3>安裝libmd5        

        # cd /soft/

        #tar xf libmd5-0.8.2b.tar.gz -C tmp/

    4>安裝Nginx        

      # cd /soft/

      # tar nginx-0.8.55.tar.gz -C tmp/

      # cd tmp/nginx-0.8.55/

      #CONFOPTS="

        --user=user_00 \

        --group=users \

        --with-http_realip_module \

        --with-http_stub_status_module \

        --with-http_gzip_static_module \

        --with-md5=/soft/md5/ \

        --with-sha1=auto/lib/sha1 \

        --with-pcre=/soft/pcre-8.01 \

        --without-select_module \

        --without-poll_module \

        --without-http_ssi_module \

        --without-http_userid_module \

        --without-http_geo_module \

        --without-http_map_module \

        --without-http_memcached_module \

        --without-mail_pop3_module \

        --without-mail_imap_module \

        --without-mail_smtp_module \

        --prefix=/usr/local/services/nginx-0.8.55 \

      "

      #./configure $ CONFOPTS >/dev/null

      # make >/dev/null && make install >/dev/null

      #chown  user_00.users /data/www/pvp.fanhougame.net –R   

 

    編譯參數詳解:

      --with-http_realip_module

    此模塊支持顯示真實來源IP地址,主要用於NGINX作前端負載均衡服務器使用。

      -with-http_stub_status_module

    這個模塊能夠取得一些nginx的運行狀態,

      --with-http_gzip_static_module

    這個模塊在一個預壓縮文件傳送到開啓Gzip壓縮的客戶端以前檢查是否已經存在以「.gz」結尾的壓縮文件,這樣能夠防止文件被重複壓縮。

      --with-md5=/soft/md5/

    設定md5庫文件路徑

      --with-sha1=auto/lib/sha1

    設定sha1庫文件路徑

      --with-pcre=/soft/pcre-8.01

    設定PCRE庫路徑

      --without-select_module

    標準鏈接模式。默認狀況下自動編譯方式。您能夠啓用或禁用經過使用-select_module和不帶- select_module配置參數這個模塊

      --without-poll_module

    不使用poll模塊

      --without-http_ssi_module

    不使用ngx_http_ssi_module模塊,此模塊處理服務器端包含文件(ssi)的處理.

      --without-http_userid_module

    不使用ngx_http_userid_module模塊

      --without-http_geo_module

    這個模塊基於客戶端的IP地址建立一些ngx_http_geoip_module變量,並與MaxMindGeoIP文件進行匹配,該模塊僅用於 0.7.63和0.8.6版本以後。但效果不太                 理想,對於城市的IP記錄並非特別準確,不過對於網站的來源訪問區域的分析大體有必定參考性;

      --without-http_map_module

    不使用ngx_http_map_module模塊

      --without-http_memcached_module

    不使用ngx_http_memcached_module模塊

      --without-mail_pop3_module

    不容許ngx_mail_pop3_module模塊

      --without-mail_imap_module

    不容許ngx_mail_imap_module模塊

      --without-mail_smtp_module

    不容許ngx_mail_smtp_module模塊

   5>配置說明      

      配置文件位置:/usr/local/nginx/conf/nginx.conf

    1.       Nginx配置文件分爲4個部分

    2.       main(全局設置)

    3.       server(主機設置)

    4.       upstream(負載均衡設置)

    5.       localtion(URL匹配特定位置的設置)

    這四個 server繼承main  location繼承server  upstream即不會繼承其它設置也不會被繼承.

    主配置文件Nginx.conf內容以下:

    #==================================一全局配置#========================

    user  user_00 users;  #這個模塊指令,指Nginx Worker 運用的用戶和組,默認爲nobody

    worker_processes  8;  #指定了要開啓的進程數,每進程佔用10M~12M的內存,建議和CPU的核心數量同樣多的進程就好了。

    error_log  logs/error.log; #全局錯誤日誌

    #error_log  logs/error.log  notice;

    #error_log  logs/error.log  info;  

    pid        logs/nginx.pid;  #:用來指定進程ID的存儲位置.

    #Specifies the value for maximum file descriptors that can be opened by this process.

    #events 用來指定Nginx工做模式以及鏈接數上限

    events {

          use epoll;  #使用epoll高效模式,適用於Linux,Unix使用kqueue

          worker_connections  100000; #定義Ningx沒個進程最大的鏈接數。默認爲1024,受到文件句柄的約束。

      }

    worker_rlimit_nofile 100000; #打開的文件句柄數量最高爲10萬

      #==================================2、HTTP配置========================

    http {

          include       mime.types;  #實現對配置文件所包含的文件設定

          default_type  application/octet-stream; #屬於HTTP核心模塊,默認設定爲二進制流

          server_tokens off;   #禁止錯誤頁面裏顯示nginx的版本號

      # 定義日誌處理的格式

        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

        #                  '$status $body_bytes_sent "$http_referer" '

        #                  '"$http_user_agent" "$http_x_forwarded_for"';

      # 定義它的hash表爲128K

          server_names_hash_bucket_size 128;

          client_header_buffer_size 32k; #客戶端請求頭部的緩衝區大小,通常一個請求頭的大小不會超過1k

          large_client_header_buffers 4 32k; #客戶請求頭緩衝大小 nginx默認會用client_header_buffer_size這個buffer來讀取header值

          client_max_body_size 8m; #設定經過nginx上傳文件的大小

      #sendfile指令指定 nginx 是否調用sendfile 函數(zero copy 方式)來輸出文件,

          #對於普通應用,必須設爲on。

        #若是用來進行下載等應用磁盤IO重負載應用,可設置爲off,以平衡磁盤與網絡IO處理速度,下降系統uptime。

        sendfile          on;

        tcp_nopush        on; #此選項容許或禁止使用socke的TCP_CORK的選項,此選項僅在使用sendfile的時候使用

        tcp_nodelay       on;

        #keepalive_timeout  0;

        keepalive_timeout 60; #keepalive超時時間。鏈接保持活動時間超過這個,將被關閉掉

    #===================重要位置============

          fastcgi_connect_timeout 300; #指定鏈接到後端FastCGI的超時時間。

          fastcgi_send_timeout 300; #向FastCGI傳送請求的超時時間,這個值是指已經完成兩次握手後向FastCGI傳送請求的超時時間。

          fastcgi_read_timeout 300; #接收FastCGI應答的超時時間,這個值是指已經完成兩次握手後接收FastCGI應答的超時時間。

          fastcgi_buffer_size 254k; #指定讀取FastCGI應答第一部分須要用多大的緩衝區

          fastcgi_buffers 16 256k; #指定本地須要用多少和多大的緩衝區來緩衝FastCGI的應答。

          fastcgi_busy_buffers_size 512k; #這個指令我也不知道是作什麼用,只知道默認值是fastcgi_buffers的兩倍。

          fastcgi_temp_file_write_size 512k; #在寫入fastcgi_temp_path時將用多大的數據塊,默認值是fastcgi_buffers的兩倍。

          gzip              on; #該指令用於開啓或關閉gzip模塊(on/off)

          gzip_min_length   1k; #設置容許壓縮的頁面最小字節數,頁面字節數從header頭得content-length中進行獲取 

          gzip_buffers      4 16k; #設置系統獲取幾個單位的緩存用於存儲gzip的壓縮結果數據流

          gzip_http_version 1.0; #識別http的協議版本

          gzip_comp_level   2;   #gzip壓縮比,1壓縮比最小處理速度最快

        #匹配mime類型進行壓縮,不管是否指定,」text/html」類型老是會被壓縮的

          gzip_types        text/plain application/x-javascript text/css application/xml text/javascript;

          gzip_vary         on; #和http頭有關係,加個vary頭,給代理服務器用的

          charset      utf-8;  #字符集爲utf-8

          access_log   off;    # 平常日誌關閉

          log_not_found off;   # 平常日誌關閉

              error_page  400 403 405 408  /40x.html;  # 錯誤返回頁面

              error_page  500 502 503 504  /50x.html;  # 錯誤返回頁面

      #===================Server虛擬機配置保持默認============

        server {

            listen       80 default;   #默認監聽端口號爲80

            server_name  _;

      return       444;

          }

      #===================自定義虛擬機配置文件===========

    include vhost/vhost.www.fanhougame.com;

    }

         

    主配虛擬Server配置文件以下:

        server {

              listen       80 ; #監聽端口號

        #域名爲

              server_name  10.0.0.201;

              # 指定網站的目錄

        root         /data/www/oa.com/www.fanhougame.com ;

      # localtion模塊指定網站首頁名稱

            location / {

                  index index.php index.html index.htm;

                if (!-e $request_filename) {

                    return 444;

                    }

              }

      #:返回的錯誤信息

          error_page   500 502 503 504  /50x.html;

          location = /50x.html {

                root   /usr/local/nginx/html;

          }

    #能夠指定多個localtion進行不一樣的指令處理,這裏是指定php的sock

            location ~ \.php$ {

                fastcgi_pass   unix:/tmp/php-cgi-5313-web.sock;

                fastcgi_index  index.php;

                include        fastcgi_params;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                fastcgi_param SERVER_NAME $http_host;

                fastcgi_ignore_client_abort on;

            }

     #指定對網頁圖片格式進行緩存max表示10年,也能夠是30d(天)

            location ~ \.(swf|js|css|xml|gif|jpg|jpeg|png|bmp)$ {

                  error_log    off;

                  access_log   off;

        #expires      30d;

                  expires      max;

            }

      }

5》啓動與平滑重啓

    # cd /usr/local/services/nginx-0.8.55/sbin/

    # ./nginx –t 檢測配置文件是否有錯誤

    # ./nginx 啓動nginx

    # ./nginx -s reload

6》 Nginx經常使用配置實例      

   1>負載均衡配置實例

      Master:10.0.0.201

      Master Web 10.0.0.201:81

      Slave1 Web 10.0.0.202:80

      Slave2 Web 10.0.0.203:80

      Master Nginx和WEB基本上和4.5配置相同

      Master 負載均衡配置以下:

      在Nginx.cnf增長以下:

      include vhost/vhost.aatest.com;

      在conf/vhost/vhost.aatest.com 編輯內容爲;

      upstream www.aatest.com {

            server  10.0.0.201:81 weight=1 max_fails=3 fail_timeout=20s;

            server  10.0.0.202:80 weight=1 max_fails=3 fail_timeout=20s;

            server  10.0.0.203:80 weight=1 max_fails=3 fail_timeout=20s;

            }

        server{

              listen 80;

              server_name www.aatest.com;

          location / {

                proxy_pass         http://www.aatest.com;

                proxy_set_header   Host             $host;

                proxy_set_header   X-Real-IP        $remote_addr;

                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

              }

          }

        ~ 

      Slave1 Web 10.0.0.202:80和Slave2 Web 10.0.0.203:80

        配置以下:

          server {

              listen       80 ; #監聽端口號

              #域名爲

              server_name  www.aatest.com;

              # 指定網站的目錄

                    root         /opt/zeng ;

                    # localtion模塊指定網站首頁名稱

            location / {

                index index.php index.html index.htm;

                if (!-e $request_filename) {

                    return 444;

                    }

              }

                    #:返回的錯誤信息

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

               root   /usr/local/nginx/html;

            }

                  #能夠指定多個localtion進行不一樣的指令處理,這裏是指定php的sock

            location ~ \.php$ {

                fastcgi_pass   unix:/tmp/php-cgi-5313-web.sock;

                fastcgi_index  index.php;

                include        fastcgi_params;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                fastcgi_param SERVER_NAME $http_host;

                fastcgi_ignore_client_abort on;

            }

                  #指定對網頁圖片格式進行緩存max表示10年,也能夠是30d(天)

             location ~ \.(swf|js|css|xml|gif|jpg|jpeg|png|bmp)$ {

                    error_log    off;

                    access_log   off;

                              #expires      30d;

                    expires      max;

              }

        }

 7》 Nginx與PHP(FastCGI)的安裝

       1>什麼是FastCGI?

          FastCGI是一個可伸縮、高速在HTTPserver和動態腳本語言間通訊的接口,多數的HTTPserver 都支持FastCGI,包括Apache、Nginx和lighttpd等,                       FastCGI被許多腳本語言支持,其中就有PHP;

     2>Nginx+FastCGI運行原理          

        Nginx不支持對外部程序的的調用或者解析,全部的外部程序(包括PHP)都必須經過FastCGI來調用 ,FastCGI接口 在 Linux下是socket文件(這個                           socket文件能夠socket,也但是ip) ,爲了調用CGI程序,還須要一個FastCGI的wrapper,當 Nginx發送將CGI請求發送給這個socket的時候,通g過                                FastCGI接口,wrapper接收到請求,而後派生出一個新的線程,這個線程調用外部程序或者腳本而且讀取返回數據,而後wrapper在將返回的數據經過                          FastCGI接口,沿着固定的socket傳遞給Nginx,而後將返回的數據發送給客戶端;           

      Nginx-->發送一個CGI請求-->FastCGI(warpper)接收到這個請求--->派生出一個新的線程--->調用外部程序或者腳本返回數據--->wrapper將數據沿着固定的                      socket傳遞給Nginx-->由Nginx在把這個數據返回給用戶.

    靜態請求:Nginx直接返回.

    動態請求:

      A用戶發一塊兒一個 cgi請求—→Nginx→內核接受-->處理模塊→FastCGI→warpper→線程→php腳本收集所須要的數據.-→FastCGI(固定文件存在)或者                            ip:port存在→Nginx---用戶.

      3>PHP與PHP-FPM的安裝及優化

           PHP-FPM也是一個第三方的FastCGI進程管理。它做爲的PHP補丁一塊兒開發,編譯的時候跟着一塊兒編譯安裝被編譯到PHP內核當中。PHP-FPM在處理                     高併發方面是很是優秀的,它的一個優勢就是把動態語言和HTTP server分離開來,Http server處理靜態請求。PHP-FPM處理動態請求,全部呢PHP/PHP-                     FPM 和Nginx組合的時候二者常常會安裝到一臺機器上面;

    4>安裝Mysql          

         數據庫層,說明:php在編譯時要mysql的配置,這樣PHP遠程鏈接mysql纔有用;

      # cd /data/soft/

      # tar xf mysql-5.1.49.tar.gz -C tmp/

      # cd tmp/mysql-5.1.49/

      #CONFOPTS=" \

        --with-charset=utf8 \

        --with-plugins=partition,federated,innobase,myisam \

        --enable-static \

        --enable-assembler \

        --enable-thread-safe-client \

        --with-client-ldflags=-all-static-ltinfo \

        --with-mysqld-ldflags=-all-static-ltinfo \

        --with-big-tables \

        --with-mysqld-user=mysql \

        --without-debug \

        --without-ndb-debug \

        --localstatedir=/usr/local/services/mysql-5.1.49/var \

        --prefix=/usr/local/services/mysql-5.1.49 \

        "

        #./configure $CONFOPTS >/dev/null

        # make >/dev/null && make install >/dev/null

      5>安裝PHP依賴庫              

      ①libxml2-2.7.7.tar.gz

        # cd /data/soft/

        #tar xf libxml2-2.7.7.tar.gz –C tmp/

        # cd tmp/libxml2-2.7.7/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ②curl-7.21.4.tar.gz

        # cd /data/soft/

        # tar xf curl-7.21.4.tar.gz -C tmp/

        # cd tmp/curl-7.21.4/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ③jpegsrc.v8b.tar.gz

        # cd /data/soft/

        #tar xf jpegsrc.v8b.tar.gz –C tmp/

        #cd tmp/jpeg-8b/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ④libpng-1.4.3.tar.gz

        # cd /data/soft/

        # tar xf libpng-1.4.3.tar.gz -C tmp/

        # cd tmp/libpng-1.4.3/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ⑤freetype-2.4.1.tar.gz

        # cd /data/soft/

        # tar xf freetype-2.4.1.tar.gz -C tmp/

        # cd tmp/freetype-2.4.1/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ⑥libevent-2.0.10-stable.tar.gz

        # cd /data/soft/

        # tar xf libevent-2.0.10-stable.tar.gz –C tmp/

        # cd tmp/libevent-2.0.10-stable/

        #./configure --prefix=/usr/local/services --disable-debug-mode >/dev/null

        #make >/dev/null && make install >/dev/null

      ⑦re2c-0.13.5.tar.gz

        # cd /data/soft/

        # tar xf re2c-0.13.5.tar.gz -C tmp/

        # cd tmp/re2c-0.13.5/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

      ⑧libmcrypt-2.5.8.tar.gz

        # cd /data/soft/

        # tar xf libmcrypt-2.5.8.tar.bz2 -C tmp/

        # cd tmp/libmcrypt-2.5.8/

        #./configure --prefix=/usr/local/services >/dev/null

        #make >/dev/null && make install >/dev/null

        # cd libltdl/

        # ./configure --prefix=/usr/local/services --enable-ltdl-install >/dev/null

        #make >/dev/null && make install >/dev/null

     6>安裝PHP           

        wget http://php.net/distributions/php-5.3.13.tar.gz

        php-5.3.13.tar.gz

        # cd /data/soft/

        # tar xf php-5.3.13.tar.gz -C tmp/

        #cd tmp/php-5.3.13/

        #CONFOPTS="

          --enable-zend-multibyte \

          --enable-mbstring \

          --enable-sockets \

          --enable-pdo \

          --enable-zip \

          --enable-fpm \

          --with-gd \

          --with-fpm-user=user_00 \

          --with-fpm-group=user_00 \

          --with-zlib \

          --with-config-file-path=/usr/local/services/php-5.3.13/etc \

          --with-libxml-dir=/usr/local/services \

          --with-curl=/usr/local/services \

          --with-png-dir=/usr/local/services \

          --with-jpeg-dir=/usr/local/services \

          --with-freetype-dir=/usr/local/services \

          --with-mysql=/usr/local/services/mysql-5.1.49 \

          --with-pdo-mysql=/usr/local/services/mysql-5.1.49 \

          --with-mysqli=/usr/local/services/mysql-5.1.49/bin/mysql_config \

          --prefix=/usr/local/services/php-5.3.13 \

        "

        # ./configure $CONFOPTS

        # make >/dev/null && make install >/dev/null

      編譯錯誤解決:

        /var/lib/mysql/mysql.sock

        configure: error: Cannot find libmysqlclient under /usr.

        Note that the MySQL client library is not bundled anymore!

      解決方法:

        cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so

       7>安裝PHP擴展          

      ①eaccelerator-0.9.6.1.tar.bz2

      # cd /data/soft/

      #tar xf eaccelerator-0.9.6.1.tar.bz2 -C tmp/

      #cd tmp/eaccelerator-0.9.6.1/

      #/usr/local/services/php-5.3.13/bin/phpize 

                   

      直接用yum 安裝 yum install m4* autoconf*

    #./configure --prefix=/usr/local/services/eaccelerator-0.9.6.1 --enable-eaccelerator --with-php-config=/usr/local/services/php-5.3.13/bin/php-config > /dev/null

    #make >/dev/null && make install >/dev/null

    #mkdir /tmp/eaccelerator

    #chmod 777 /tmp/eaccelerator                     

    ②memcached-1.4.13.tar.gz

      (服務器端要前安裝,下面的編譯擴展模塊要用到)

      # cd /data/soft/

        #tar xf memcached-1.4.13.tar.gz -C tmp/

       # cd tmp/memcached-1.4.13/

       #./configure --enable-64bit --with-libevent=/usr/local/services --prefix=/usr/local/services/memcached-1.4.13 >/dev/null

       # make >/dev/null && make install >/dev/null

    ③libmemcached-0.48.tar.gz

      # cd /data/soft/

      #tar xf libmemcached-0.48.tar.gz -C tmp/

      #cd tmp/libmemcached-0.48/

      #CONFOPTS="

        --disable-libinnodb

        --without-libinnodb-prefix

        --with-libevent-prefix=/usr/local/services

        --with-memcached=/usr/local/services/memcached-1.4.13/bin/memcached

        --prefix=/usr/local/services

      "

      #./configure $CONFOPTS >/dev/null

      #make >/dev/null && make install >/dev/null     

    ④igbinary-1.0.2.tgz

      # cd /data/soft/

      # tar xf igbinary-1.0.2.tar.gz -C tmp/

      #cd tmp/igbinary-1.0.2/

      #/usr/local/services/php-5.3.13/bin/phpize

      #./configure --enable-igbinary --with-php-config=/usr/local/services/php-5.3.13/bin/php-config >/dev/null

      #make >/dev/null && make install >/dev/null 

    ⑤memcache-3.0.5.tgz

      # cd /data/soft/

      # tar xf memcache-3.0.5.tgz -C tmp/

      #cd tmp/memcache-3.0.5/

      #/usr/local/services/php-5.3.13/bin/phpize

      #CONFOPTS=" \

        --enable-memcache \

        --with-php-config=/usr/local/services/php-5.3.13/bin/php-config \

        "

      #./configure $CONFOPTS >/dev/null

      #make >/dev/null && make install >/dev/null 

    ⑥memcached-1.0.2.tgz(注意安裝的順序,igbinary-1.1.1.tgz是依賴庫)

      # cd /data/soft/

      # tar xf memcached-1.0.2.tgz -C tmp/

      # cd  tmp/memcached-1.0.2/

      #/usr/local/services/php-5.3.13/bin/phpize

      #CONFOPTS=" \

        --enable-memcached \

        --enable-memcached-igbinary \

        --enable-memcached-json \

        --with-libmemcached-dir=/usr/local/services \

        --with-php-config=/usr/local/services/php-5.3.13/bin/php-config \

        --prefix=/usr/local/services \

        "

      #./configure $CONFOPTS >/dev/null

      #make >/dev/null && make install >/dev/null   

    ⑦owlient-phpredis-2.1.1-1-g90ecd17.tar.gz

      # cd /data/soft/

      #tar xf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz -C tmp/

      # cd tmp/owlient-phpredis-90ecd17/

      #/usr/local/services/php-5.3.13/bin/phpize

      #./configure --with-php-config=/usr/local/services/php-5.3.13/bin/php-config >/dev/null

      #make >/dev/null && make install >/dev/null 

       8>拷貝配置文件:

      # cd /usr/local/services/php-5.3.13/etc

      # cp php-fpm.conf.default php-fpm.conf

      # cp /soft/php/php-5.3.13/php.ini-production php.ini

 8》PHP配置文件優化與調整

      1>在php-fpm.conf 裏面調整         

      ;listen = 127.0.0.1:9000

      listen = /tmp/php-cgi.tuge.sock   #以socke的方式訪問.注視掉.ip端口的方式.

      ; Default Value: log/php-fpm.log

      error_log = /data/php_log/tuge.php.error  #根據不一樣的項目名.定義不一樣的.sock 和日誌.

      # 調整進程數量

      pm.max_children:靜態方式下開啓的php-fpm進程數量。

      pm.start_servers:動態方式下的起始php-fpm進程數量。

      pm.min_spare_servers:動態方式下的最小php-fpm進程數量。

      pm.max_spare_servers:動態方式下的最大php-fpm進程數量。

      2>在php.ini 加入擴展模塊.          

      在尾部添加:

      [eaccelerator]

      zend_extension="/usr/local/services/php-5.3.20/lib/php/extensions/eaccelerator.so"

      eaccelerator.shm_size="16"

      eaccelerator.cache_dir="/tmp/eaccelerator"

      eaccelerator.enable="1"

      eaccelerator.optimizer="1"

      eaccelerator.check_mtime="1"

      eaccelerator.debug="0"

      eaccelerator.filter=""

      eaccelerator.shm_max="0"

      eaccelerator.shm_ttl="0"

      eaccelerator.shm_prune_period="0"

      eaccelerator.shm_only="0"

      eaccelerator.compress="1"

      eaccelerator.compress_level="9" 

      擴展模塊增長

      extension_dir = "/usr/local/services/php-5.3.13/lib/php/extensions"

      extension = memcached.so

      extension = redis.so

      extension = memcache.so

      extension = igbinary.so 

      移動擴展模塊位置

      # cd  /usr/local/services/php-5.3.13/lib/php/extensions/no-debug-non-zts-20090626/

      # mv /usr/local/services/php-5.3.13/lib/php/extensions/no-debug-non-zts-20090626/*  /usr/local/services/php-5.3.13/lib/php/extensions

9》啓動PHP       

  修改Nginx的虛擬主機的sock位置

  fastcgi_pass   unix:/tmp/php-cgi.gongda.sock;

  啓動PHP

  # cd /usr/local/services/php-5.3.13/sbin

  # ./php-fpm

==================================

php下的nginx配置文件nginx.conf

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       80;        server_name  10.0.2.159;root  /data/www;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {                       index  index.php index.html;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        location ~ \.php$ {           root           html;        #    fastcgi_pass   127.0.0.1:9000;        #                fastcgi_pass   unix:/lianlian/lnmp/tmp/chw.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;            include        fastcgi_params;        }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}================================================

相關文章
相關標籤/搜索