在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

tarzxvf tengine-1.5.1.tar.gz && cd tengine-1.5.1
./configure--prefix=/app/tengine --with-http_stub_status_module--with-http_ssl_module --with-http_gzip_static_module --add-module=/app/tengine/ngx_cache_purge-2.0--add-module=/app/tengine/lua-nginx-module-master  --add-module=/app/tengine/headers-more-nginx-module-0.19rc1   --with-pcre=/app/tengine/pcre-8.32--with-pcre-jit --with-http_concat_module --with-http_concat_module=shared

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


./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=/app/tengine/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;


user www www ;
worker_processes 18;
error_log  logs/error.log  crit;
pid        logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{ 
  use epoll;
  worker_connections 65535;
}
http
{
  include       mime.types;
  default_type  application/octet-stream;
  #charset  gb2312;
  server_tag              GOME;
  server_tokens off; 


  log_format access '$remote_addr	$remote_user	$http_host	[$time_local]	"$request"	$status	$body_bytes_sent	"$http_referer"	"$http_user_agent"	"$http_cookie"	"$http_x_forwarded_for"	"$request_time"';




#  log_format access '$remote_addr - $remote_user  $http_host - [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                 '"$http_user_agent" "$http_cookie"'
#                '"$http_x_forwarded_for"   "$request_time"';


  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
  sendfile on;
  tcp_nopush     on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  limit_req2_zone $http_x_forwarded_for  zone=wap:500m rate=100r/s;
  #limit_zone  crawler  $binary_remote_addr  10m;
  limit_req_zone $anti_spider zone=anti_spider:10m rate=2r/s; 


  #white_black_list_conf conf/white.list zone=white:10m;




  server
  {
    listen       	      80;
    server_name  	      m.gome.com.cn;
    index 		      index.html index.php index.htm;
    root  		      /app/htdocs/;
  #  include 		     /app/htdocs/.htaccess;


          limit_req zone=anti_spider burst=6 nodelay;
          if ($http_user_agent ~* "EgouSpider|Baiduspider") {
          set $anti_spider $http_user_agent;
                     }


		if (!-f $request_filename){


     		rewrite (.*)/index.php last;
		}
        	error_page  404    /error.html;
        	error_page  500 502 503 504   /fault.html;


        location ~ \/\.htaccess
        {
                deny all;
        }


		location ~ .*\.(php|php5)?$
    			{   
     		 fastcgi_pass  127.0.0.1:9000;
      		 fastcgi_index index.php;
      		 include  fastcgi.conf;
      		 limit_req zone=anti_spider burst=6 nodelay;
      		 if ($http_user_agent ~* "EgouSpider|Baiduspider") {
      		 set $anti_spider $http_user_agent;
             		}


#include blacksip.conf;


if ($query_string ~* "No=(.*)&sId=(.*)&d=(.*)&intcmp=(.*)")
 {
  set $No $1;
  set $sId $2;
  set $d $3;
  set $intcmp $4;
  rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-$d-$intcmp.html? permanent;
 }


 if ($query_string ~* "No=(.*)&sId=(.*)&d=(.*)")
 {
  set $No $1;
  set $sId $2;
  set $d $3;
  rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-$d-0.html? permanent;
 }


 if ($query_string ~* "No=(.*)&sId=(.*)")
 {
  set $No $1;
  set $sId $2;
  rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-$sId-0-0.html? permanent;
 }


 if ($query_string ~* "No=(.*)")
 {
  set $No $1;
  rewrite "^/product_details.html"  http://m.gome.com.cn/product-$No-0-0-0.html? permanent;
 }
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
      expires      1h;
    } 
    location ~ .*\.registered.html?$
    {
      limit_req2 zone=wap burst=30  block=3x30x1800;
    }
    access_log  /app/tengine/logs/gome_wap.access.log  access;
  }
        server{
                listen 9001;
                access_log off;
                location / {
                        check_status;
                }
                location /status {
                        stub_status on;
                }
        }
} 
 
   
 
   

配置fastcgi.conf
# vi fastcgi.conf
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200; 



# cd /etc/init.d/
# vi nginx
添加
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /app/tengine/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/app/tengine/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/app/tengine/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/app/tengine/logs/nginx
start() {
    [ -x $nginx ] || exit 5
 
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest_q || configtest || return 6
    stop
 
    start
}
reload() {
    configtest_q || configtest || return 6
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    echo
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
configtest_q() {
    configtest >/dev/null 2>&1
}
rh_status() {
   status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
# Upgrade the binary with no downtime.
upgrade() {
    local pidfile="/app/tengine/logs/${prog}.pid"
    local oldbin_pidfile="${pidfile}.oldbin"
    configtest_q || configtest || return 6
    echo -n $"Staring new master $prog: "
    killproc $nginx -USR2
    retval=$?
    echo
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        echo -n $"Graceful shutdown of old $prog: "
        killproc -p ${oldbin_pidfile} -QUIT
        retval=$?
        echo
        return 0
    else
        echo $"Something bad happened, manual intervention required, maybe restart?"
        return 1
    fi
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
      rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    force-reload|upgrade)
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
            ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"
        exit 2
esac
完成后在进行:
# chmod 755 /etc/init.d/nginx 
# chkconfig nginx on
# chkconfig --level 24 nginx off

最后一步:
将安装路径中的html文件夹下的所有文件复制到/app/htdocs/ 目录下
# cp /app/tengine/html/*  /app/htdocs



到此,配置结束。

启动:
# service nginx start



在浏览器中输入: localhost 
显示:
在Linux下的Tengine安装和配置_第1张图片

则启动成功。



你可能感兴趣的:(在Linux下的Tengine安装和配置)