在Linux下的Tengine安装和配置

一、简介

 

 

  Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

二、安装

安装Tengine需要下载很多的依赖包,便于大家安装,我将其统一放在一起。
 

0.安装tengine依赖包readline

tar zxf readline-6.2.tar.gz&& cd readline-6.2 && ./configure && make && make install

1.安装tengine依赖包lua

tar zxf lua-5.1.5.tar.gz && cd lua-5.1.5 && make linux &&make install

2.安装tengine依赖包lua-nginx-module-master

unzip lua-nginx-module-master.zip

3.安装tengine依赖包ngx_cache_purge

tarzxf ngx_cache_purge-2.0.tar.gz

4.安装tengine依赖包headers-more-nginx-module

unzipheaders-more-nginx-module-0.19rc1.zip

5.安装tengine依赖包pcre

unzip pcre-8.32.zip

cd pcre-8.32 && ./configure && make && make install

6.安装tengine

[html]  view plain  copy
 
  1. tarzxvf tengine-1.5.1.tar.gz && cd tengine-1.5.1  
  2. ./configure--prefix=<span style="color:#ff0000;">/app/tengine</span> --with-http_stub_status_module--with-http_ssl_module --with-http_gzip_static_module --add-module=<span style="color:#ff0000;">/app/tengine/</span>ngx_cache_purge-2.0--add-module=<span style="color:#ff0000;">/app/tengine/</span>lua-nginx-module-master  --add-module=<span style="color:#ff0000;">/app/tengine/</span>headers-more-nginx-module-0.19rc1   --with-pcre=<span style="color:#ff0000;">/app/tengine/</span>pcre-8.32--with-pcre-jit --with-http_concat_module --with-http_concat_module=shared  

注意:我将tengine解压在了/app/softlib/ 目录下,因此依赖包就在/app/tengine/ 目录下。在进行./configure的时候一定要注意修改成你的依赖包的路径!(用红色标记部分)

[html]  view plain  copy
 
  1. ./configure --prefix=/app/tengine --conf-path=/app/tengine/conf/nginx.conf --with-http_concat_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-pcre=<span style="color:#ff0000;">/app/tengine/</span>pcre-8.32  

注意:我将tengine装在了 /app/tengine 下面,注意修改pcre路径。

 

7.修改配置文件nginx.conf

文件地址:/app/tengine/conf/nginx.conf

dso{

    load ngx_http_concat_module.so;

}

在http模块添加

concat on;

[html]  view plain  copy
 
  1. <pre name="code" class="html"><pre name="code" class="html">user www www ;  
  2. worker_processes 18;  
  3. error_log  logs/error.log  crit;  
  4. pid        logs/nginx.pid;  
  5. #Specifies the value for maximum file descriptors that can be opened by this process.  
  6. worker_rlimit_nofile 65535;  
  7. events  
  8. {   
  9.   use epoll;  
  10.   worker_connections 65535;  
  11. }  
  12. http  
  13. {  
  14.   include       mime.types;  
  15.   default_type  application/octet-stream;  
  16.   #charset  gb2312;  
  17.   server_tag              GOME;  
  18.   server_tokens off;   
  19.   
  20.   
  21.   log_format access '$remote_addr<span style="white-space:pre">  </span>$remote_user<span style="white-space:pre">   </span>$http_host<span style="white-space:pre"> </span>[$time_local]<span style="white-space:pre">  </span>"$request"<span style="white-space:pre"> </span>$status<span style="white-space:pre">    </span>$body_bytes_sent<span style="white-space:pre">   </span>"$http_referer"<span style="white-space:pre">    </span>"$http_user_agent"<span style="white-space:pre"> </span>"$http_cookie"<span style="white-space:pre"> </span>"$http_x_forwarded_for"<span style="white-space:pre">    </span>"$request_time"';  
  22.   
  23.   
  24.   
  25.   
  26. #  log_format access '$remote_addr - $remote_user  $http_host - [$time_local] "$request" '  
  27. #                  '$status $body_bytes_sent "$http_referer" '  
  28. #                 '"$http_user_agent" "$http_cookie"'  
  29. #                '"$http_x_forwarded_for"   "$request_time"';  
  30.   
  31.   
  32.   server_names_hash_bucket_size 128;  
  33.   client_header_buffer_size 32k;  
  34.   large_client_header_buffers 4 32k;  
  35.   client_max_body_size 8m;  
  36.   sendfile on;  
  37.   tcp_nopush     on;  
  38.   keepalive_timeout 60;  
  39.   tcp_nodelay on;  
  40.   fastcgi_connect_timeout 300;  
  41.   fastcgi_send_timeout 300;  
  42.   fastcgi_read_timeout 300;  
  43.   fastcgi_buffer_size 64k;  
  44.   fastcgi_buffers 4 64k;  
  45.   fastcgi_busy_buffers_size 128k;  
  46.   fastcgi_temp_file_write_size 128k;  
  47.   gzip on;  
  48.   gzip_min_length  1k;  
  49.   gzip_buffers     4 16k;  
  50.   gzip_http_version 1.0;  
  51.   gzip_comp_level 2;  
  52.   gzip_types       text/plain application/x-javascript text/css application/xml;  
  53.   gzip_vary on;  
  54.   limit_req2_zone $http_x_forwarded_for  zone=wap:500m rate=100r/s;  
  55.   #limit_zone  crawler  $binary_remote_addr  10m;  
  56.   limit_req_zone $anti_spider zone=anti_spider:10m rate=2r/s;   
  57.   
  58.   
  59.   #white_black_list_conf conf/white.list zone=white:10m;  
  60.   
  61.   
  62.   
  63.   
  64.   server  
  65.   {  
  66.     listen       <span style="white-space:pre">  </span>      80;  
  67.     server_name  <span style="white-space:pre">    </span>      m.gome.com.cn;  
  68.     index <span style="white-space:pre">        </span>      index.html index.php index.htm;  
  69.     root  <span style="white-space:pre">       </span>      /app/htdocs/;  
  70.   #  include <span style="white-space:pre">     </span>     /app/htdocs/.htaccess;  
  71.   
  72.   
  73.           limit_req zone=anti_spider burst=6 nodelay;  
  74.           if ($http_user_agent ~* "EgouSpider|Baiduspider") {  
  75.           set $anti_spider $http_user_agent;  
  76.                      }  
  77.   
  78.   
  79. <span style="white-space:pre">        </span>if (!-f $request_filename){  
  80.   
  81.   
  82.      <span style="white-space:pre">        </span>rewrite (.*)/index.php last;  
  83. <span style="white-space:pre">        </span>}  
  84.         <span style="white-space:pre">    </span>error_page  404    /error.html;  
  85.         <span style="white-space:pre">    </span>error_page  500 502 503 504   /fault.html;  
  86.   
  87.   
  88.         location ~ \/\.htaccess  
  89.         {  
  90.                 deny all;  
  91.         }  
  92.   
  93.   
  94. <span style="white-space:pre">        </span>location ~ .*\.(php|php5)?$  
  95.     <span style="white-space:pre">          </span>{     
  96.      <span style="white-space:pre">        </span> fastcgi_pass  127.0.0.1:9000;  
  97.       <span style="white-space:pre">       </span> fastcgi_index index.php;  
  98.       <span style="white-space:pre">       </span> include  fastcgi.conf;  
  99.       <span style="white-space:pre">       </span> limit_req zone=anti_spider burst=6 nodelay;  
  100.       <span style="white-space:pre">       </span> if ($http_user_agent ~* "EgouSpider|Baiduspider") {  
  101.       <span style="white-space:pre">       </span> set $anti_spider $http_user_agent;  
  102.              <span style="white-space:pre">        </span>}  
  103.   
  104.   
  105. #include blacksip.conf;  
  106.   
  107.   
  108. if ($query_string ~* "No=(.*)&sId=(.*)&d=(.*)&intcmp=(.*)")  
  109.  {  
  110.   set $No $1;  
  111.   set $sId $2;  
  112.   set $d $3;  
  113.   set $intcmp $4;  
  114.   rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-$d-$intcmp.html? permanent;  
  115.  }  
  116.   
  117.   
  118.  if ($query_string ~* "No=(.*)&sId=(.*)&d=(.*)")  
  119.  {  
  120.   set $No $1;  
  121.   set $sId $2;  
  122.   set $d $3;  
  123.   rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-$d-0.html? permanent;  
  124.  }  
  125.   
  126.   
  127.  if ($query_string ~* "No=(.*)&sId=(.*)")  
  128.  {  
  129.   set $No $1;  
  130.   set $sId $2;  
  131.   rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-0-0.html? permanent;  
  132.  }  
  133.   
  134.   
  135.  if ($query_string ~* "No=(.*)")  
  136.  {  
  137.   set $No $1;  
  138.   rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-0-0-0.html? permanent;  
  139.  }  
  140.     }  
  141.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  142.     {  
  143.       expires      30d;  
  144.     }  
  145.     location ~ .*\.(js|css)?$  
  146.     {  
  147.       expires      1h;  
  148.     }   
  149.     location ~ .*\.registered.html?$  
  150.     {  
  151.       limit_req2 zone=wap burst=30  block=3x30x1800;  
  152.     }  
  153.     access_log  /app/tengine/logs/gome_wap.access.log  access;  
  154.   }  
  155.         server{  
  156.                 listen 9001;  
  157.                 access_log off;  
  158.                 location / {  
  159.                         check_status;  
  160.                 }  
  161.                 location /status {  
  162.                         stub_status on;  
  163.                 }  
  164.         }  
  165. }   
 
 
 
 
 
配置fastcgi.conf
[html]  view plain  copy
 
  1. # vi fastcgi.conf  
  2. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;  
  3. fastcgi_param  SERVER_SOFTWARE    nginx;  
  4. fastcgi_param  QUERY_STRING       $query_string;  
  5. fastcgi_param  REQUEST_METHOD     $request_method;  
  6. fastcgi_param  CONTENT_TYPE       $content_type;  
  7. fastcgi_param  CONTENT_LENGTH     $content_length;  
  8. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;  
  9. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;  
  10. fastcgi_param  REQUEST_URI        $request_uri;  
  11. fastcgi_param  DOCUMENT_URI       $document_uri;  
  12. fastcgi_param  DOCUMENT_ROOT      $document_root;  
  13. fastcgi_param  SERVER_PROTOCOL    $server_protocol;  
  14. fastcgi_param  REMOTE_ADDR        $remote_addr;  
  15. fastcgi_param  REMOTE_PORT        $remote_port;  
  16. fastcgi_param  SERVER_ADDR        $server_addr;  
  17. fastcgi_param  SERVER_PORT        $server_port;  
  18. fastcgi_param  SERVER_NAME        $server_name;  
  19. # PHP only, required if PHP was built with --enable-force-cgi-redirect  
  20. fastcgi_param  REDIRECT_STATUS    200;   
 
 
[html]  view plain  copy
 
  1. # cd /etc/init.d/  
[html]  view plain  copy
 
  1. # vi nginx  
[html]  view plain  copy
 
  1. 添加  
[html]  view plain  copy
 
  1. #!/bin/sh  
  2. #  
  3. # nginx - this script starts and stops the nginx daemon  
  4. #  
  5. # chkconfig:   - 85 15  
  6. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \  
  7. #               proxy and IMAP/POP3 proxy server  
  8. # processname: nginx  
  9. # config:      /etc/nginx/nginx.conf  
  10. # config:      /etc/sysconfig/nginx  
  11. # pidfile:     /app/tengine/logs/nginx.pid  
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. # Check that networking is up.  
  17. [ "$NETWORKING" = "no" ] && exit 0  
  18. nginx="/app/tengine/sbin/nginx"  
  19. prog=$(basename $nginx)  
  20. NGINX_CONF_FILE="/app/tengine/conf/nginx.conf"  
  21. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx  
  22. lockfile=/app/tengine/logs/nginx  
  23. start() {  
  24.     [ -x $nginx ] || exit 5  
  25.    
  26.     [ -f $NGINX_CONF_FILE ] || exit 6  
  27.     echo -n $"Starting $prog: "  
  28.     daemon $nginx -c $NGINX_CONF_FILE  
  29.     retval=$?  
  30.     echo  
  31.     [ $retval -eq 0 ] && touch $lockfile  
  32.     return $retval  
  33. }  
  34. stop() {  
  35.     echo -n $"Stopping $prog: "  
  36.     killproc $prog  
  37.     retval=$?  
  38.     echo  
  39.     [ $retval -eq 0 ] && rm -f $lockfile  
  40.     return $retval  
  41. }  
  42. restart() {  
  43.     configtest_q || configtest || return 6  
  44.     stop  
  45.    
  46.     start  
  47. }  
  48. reload() {  
  49.     configtest_q || configtest || return 6  
  50.     echo -n $"Reloading $prog: "  
  51.     killproc $nginx -HUP  
  52.     echo  
  53. }  
  54. configtest() {  
  55.   $nginx -t -c $NGINX_CONF_FILE  
  56. }  
  57. configtest_q() {  
  58.     configtest >/dev/null 2>&1  
  59. }  
  60. rh_status() {  
  61.    status $prog  
  62. }  
  63. rh_status_q() {  
  64.     rh_status >/dev/null 2>&1  
  65. }  
  66. # Upgrade the binary with no downtime.  
  67. upgrade() {  
  68.     local pidfile="/app/tengine/logs/${prog}.pid"  
  69.     local oldbin_pidfile="${pidfile}.oldbin"  
  70.     configtest_q || configtest || return 6  
  71.     echo -n $"Staring new master $prog: "  
  72.     killproc $nginx -USR2  
  73.     retval=$?  
  74.     echo  
  75.     sleep 1  
  76.     if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then  
  77.         echo -n $"Graceful shutdown of old $prog: "  
  78.         killproc -p ${oldbin_pidfile} -QUIT  
  79.         retval=$?  
  80.         echo  
  81.         return 0  
  82.     else  
  83.         echo $"Something bad happened, manual intervention required, maybe restart?"  
  84.         return 1  
  85.     fi  
  86. }  
  87. case "$1" in  
  88.     start)  
  89.         rh_status_q && exit 0  
  90.         $1  
  91.         ;;  
  92.     stop)  
  93.       rh_status_q || exit 0  
  94.         $1  
  95.         ;;  
  96.     restart|configtest)  
  97.         $1  
  98.         ;;  
  99.     force-reload|upgrade)  
  100.         rh_status_q || exit 7  
  101.         upgrade  
  102.         ;;  
  103.     reload)  
  104.         rh_status_q || exit 7  
  105.         $1  
  106.         ;;  
  107.     status|status_q)  
  108.         rh_$1  
  109.         ;;  
  110.     condrestart|try-restart)  
  111.         rh_status_q || exit 7  
  112.         restart  
  113.             ;;  
  114.     *)  
  115.         echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"  
  116.         exit 2  
  117. esac  
完成后在进行:
[html]  view plain  copy
 
  1. # chmod 755 /etc/init.d/nginx   
  2. # chkconfig nginx on  
  3. # chkconfig --level 24 nginx off  
 
最后一步:
将安装路径中的html文件夹下的所有文件复制到/app/htdocs/ 目录下
[html]  view plain  copy
 
  1. # cp /app/tengine/html/*  /app/htdocs  



到此,配置结束。
 
启动:
[html]  view plain  copy
 
  1. # service nginx start  
在浏览器中输入: localhost 
显示:

则启动成功。

http://blog.csdn.net/Zhao_S/article/details/42454599

猜你喜欢

转载自aoyouzi.iteye.com/blog/2284875