Tengine高性能部署之—安裝篇


一、Tengine簡介

Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了很多高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶網,天貓商城等得到了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平臺


二、功能描述

  • 繼承Nginx-1.6.2的所有特性,兼容Nginx的配置;

  • 動態模塊加載(DSO)支持。加入一個模塊不再需要重新編譯整個Tengine;

  • 支持SO_REUSEPORT選項,建連性能提升爲官方nginx的三倍;

  • 支持SPDY v3協議,自動檢測同一端口的SPDY請求和HTTP請求;

  • 流式上傳到HTTP後端服務器或FastCGI服務器,大量減少機器的I/O壓力;

  • 更加強大的負載均衡能力,包括一致性hash模塊、會話保持模塊,還可以對後端的服務器進行主動健康檢查,根據服務器狀態自動上線下線,以及動態解析upstream中出現的域名;

  • 輸入過濾器機制支持。通過使用這種機制Web應用防火牆的編寫更爲方便;

  • 支持設置proxy、memcached、fastcgi、scgi、uwsgi在後端失敗時的重試次數

  • 動態腳本語言Lua支持。擴展功能非常高效簡單;

  • 支持管道(pipe)和syslog(本地和遠端)形式的日誌以及日誌抽樣;

  • 支持按指定關鍵字(域名,url等)收集Tengine運行狀態;

  • 組合多個CSS、JavaScript文件的訪問請求變成一個請求;

  • 自動去除空白字符和註釋從而減小頁面的體積

  • 自動根據CPU數目設置進程個數和綁定CPU親緣性;

  • 監控系統的負載和資源佔用從而對系統進行保護;

  • 顯示對運維人員更友好的出錯信息,便於定位出錯機器;

  • 更強大的防***(訪問速度限制)模塊;

  • 更方便的命令行參數,如列出編譯的模塊列表、支持的指令等;

  • 可以根據訪問文件類型設置過期時間;

三、下載並解壓

tengine的下載地址:   http://tengine.taobao.org/

我們在linux下下載tengine:

# wget http://tengine.taobao.org/download/tengine-2.1.1.tar.gz

解壓tengine-2.1.1.tar.gz:

# tar -zxvf tengine-2.1.1.tar.gz

進入解壓後的目錄:

cd tengine-2.1.1/

安裝需要的依賴軟件包:

# yum -y install gcc openssl openssl-devel pcre-devel pcre ngx_cache_purge


四、編譯安裝Tengine

調用configure編譯

./configure --prefix=/usr/local/tengine-2.1.1 --dso-path=/usr/local/tengine-2.1.1/modules --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_concat_module --http-log-path=/var/log/tengine-2.1.1/access.log --error-log-path=/var/log/tengine-2.1.1/error.log

安裝:

make && make install


五、啓動Tengine

/usr/local/tengine-2.1.1/sbin/nginx

chown nobody.nobody -R /usr/local/tengine-2.1.1/html

chmod 700 -R /usr/local/tengine-2.1.1/html


六、編輯Tengine服務腳本


vi /etc/rc.d/init.d/tengine

#!/bin/sh

#

#nginx - this script starts and stops the nginx daemon

#

# chkconfig:   - 85 15

# processname: nginx

# config:      /usr/local/tengine-2.1.1/conf/nginx.conf

# pidfile:     /usr/local/tengine-2.1.1/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="/usr/local/tengine-2.1.1/sbin/nginx"

prog=$(basename $nginx)

lockfile="/var/lock/subsys/nginx"

pidfile="/usr/local/tengine-2.1.1/logs/${prog}.pid"

NGINX_CONF_FILE="/usr/local/tengine-2.1.1/conf/nginx.conf"

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 -p $pidfile $prog

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

restart() {

    configtest_q || return 6

    stop

    start

}

reload() {

    configtest_q || return 6

    echo -n $"Reloading $prog: "

    killproc -p $pidfile $prog -HUP

    echo

}

configtest() {

    $nginx -t -c $NGINX_CONF_FILE

}

configtest_q() {

    $nginx -t -q -c $NGINX_CONF_FILE

}

rh_status() {

    status $prog

}

rh_status_q() {

    rh_status >/dev/null 2>&1

}

# Upgrade the binary with no downtime.

upgrade() {

    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6

    echo -n $"Upgrading $prog: "

    killproc -p $pidfile $prog -USR2

    retval=$?

    sleep 1

    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then

        killproc -p $oldbin_pidfile $prog -QUIT

        success $"$prog online upgrade"

        echo 

        return 0

    else

        failure $"$prog online upgrade"

        echo

        return 1

    fi

}

# Tell nginx to reopen logs

reopen_logs() {

    configtest_q || return 6

    echo -n $"Reopening $prog logs: "

    killproc -p $pidfile $prog -USR1

    retval=$?

    echo

    return $retval

}

case "$1" in

    start)

        rh_status_q && exit 0

        $1

        ;;

    stop)

        rh_status_q || exit 0

        $1

        ;;

    restart|configtest|reopen_logs)

        $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|reopen_logs}"

        exit 2

esac

;wq保存退出

賦予文件執行權限:

# chmod 775 /etc/rc.d/init.d/tengine

設置開機啓動:

# chkconfig tengine on

重啓Tengine:

# service tengine restart

七、隱藏Tengine版本信息

即在tengine配置文件nginx.conf中的


http{

    server_tokens off;

    server_info off;

    server_tag off;


}  中寫入上面三句重啓服務即可


到此,Tengine編譯安裝也就完成了,關於Tengine性能上的優化在這就不闡述了,可以參考自己的服務器配置信息及生產環境所需做必要的內核與其他相關參數的修改。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章