你的位置:首页 > 软件开发 > 操作系统 > LNMP详细介绍

LNMP详细介绍

发布时间:2017-10-17 23:00:10
1》Nginx概述: 很多人对apache非常熟悉,Nginx与Apache类似,属于WEB容器,同时也是一款高性能的HTTP和反向代理软件,它们之间最大的差别是Apache的处理速 ...

LNMP详细介绍

1》Nginx概述:

                    很多人对apache非常熟悉,Nginx与Apache类似,属于WEB容器,同时也是一款高性能的HTTP和反向代理软件,它们之间最大的差别是Apache的处理速              度很慢,而且占用很多内存资源,而Nginx却恰恰相反,在功能实现上,Apache的所有模块都是支持动静态编译,而Nginx模块都是静态编译的,同时Apache对              Fcgi的支持不好,而Nginx对Fcgi支持非常好,在处理连接方式上,Nginx支持epoll,而Apache却不支持,Nginx安装包只有几百K,而Apache绝对是个庞然大                    物;   

    Nginx其优势如下:

      Ø         作为WEB服务器, Nginx处理静态文件、索引文件,自动索引的效率非常高;

      Ø         作为代理服务器,Nginx可以实现无缓存的反向代理加速,提高网站运行速度;

      Ø         作为负载均衡服务器、Nginx可以在内部直接支持Redis和PHP,可以支持HTTP代理服务器对外进行服务,同时还支持简单的容错和利用算法进行                                    负载;

      Ø         在性能方面,Nginx是专门为性能优化开发的,采用Poll模型,最大支持5万并发连接,而且占用很少一部分内存资源;

      Ø         在稳定方面采取了分阶资源分配技术,使CPU占用资源非常的低,官方表示Nginx保持1万个没有活动的链接,只占用2.5M的内存,DDOS攻击对                                    Nginx来说基本上无效;

      Ø         在高可用性方面,Nginx支持热部署,启动速度特别迅速,因此可以不间断服务情况下,对软件版本或者配置升级,即使运行数月也无需启动,几                                    乎可以做到7*24小时不间断运行;

2》Nginx的模块与工作原理      

    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等进行交互,实现服务代理和负                                                                       载均衡等功能;

                                  LNMP详细介绍

          

        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核数;

                         LNMP详细介绍

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万

      #==================================二、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/

          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|

                  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                         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|

                    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依赖库              

      ①lib

        # cd /data/soft/

        #tar xf lib

        # cd tmp/lib

        #./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        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-lib

          --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 

            LNMP详细介绍       

      直接用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   #}

        # 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;
    #    }
    #}
}
================================================

原标题:LNMP详细介绍

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录