一.Tengine是什麼html
Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了不少高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶網,天貓商城等獲得了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平臺。
從2011年12月開始,Tengine成爲一個開源項目,Tengine團隊在積極地開發和維護着它。Tengine團隊的核心成員來自於淘寶、搜狗等互聯網企業。Tengine是社區合做的成果,咱們歡迎你們參與其中,貢獻本身的力量。nginx
繼承Nginx-1.6.2的全部特性,兼容Nginx的配置;c++
動態模塊加載(DSO)支持。加入一個模塊再也不須要從新編譯整個Tengine;web
支持SO_REUSEPORT選項,建連性能提高爲官方nginx的三倍;shell
流式上傳到HTTP後端服務器或FastCGI服務器,大量減小機器的I/O壓力;瀏覽器
更增強大的負載均衡能力,包括一致性hash模塊、會話保持模塊,還能夠對後端的服務器進行主動健康檢查,根據服務器狀態自動上線下線,以及動態解析upstream中出現的域名;安全
輸入過濾器機制支持。經過使用這種機制Web應用防火牆的編寫更爲方便;bash
支持設置proxy、memcached、fastcgi、scgi、uwsgi在後端失敗時的重試次數服務器
動態腳本語言Lua支持。擴展功能很是高效簡單;
支持按指定關鍵字(域名,url等)收集Tengine運行狀態;
自動去除空白字符和註釋從而減少頁面的體積
自動根據CPU數目設置進程個數和綁定CPU親緣性;
能夠根據訪問文件類型設置過時時間;
……
二. 安裝 Tengine
2.1 編譯環境準備
yum -y install gcc gcc-c++ autoconf automake wget yum -y install zlib zlib-devel openssl openssl-devel pcre-devel pcre gd-devel groupadd nginx useradd -g nginx -s/sbin/nologin -M nginx
zlib:nginx提供gzip模塊,須要zlib庫支持
openssl:nginx提供ssl功能
pcre:支持地址重寫rewrite功能
concat:支持js,CSS的樣式文件合併,減小nginx服務器請求連接數
安裝jemalloc,優化nginx內存管理
wget http://www.canonware.com/download/jemalloc/jemalloc-4.0.4.tar.bz2 tar xjf jemalloc-4.0.4.tar.bz2 cd jemalloc-4.0.4 ./configure make && make install echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf ldconfig
2.2編譯安裝
cd /opt/ wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz tar zxvf tengine-2.1.2.tar.gz cd tengine-2.1.2 ./configure \ --user=nginx \ --group=nginx \ --with-jemalloc \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_concat_module \ --with-pcre \ --with-http_sysguard_module \ --with-http_realip_module \ --with-http_image_filter_module
make
make install
2.3啓動Tengine
/usr/local/nginx/sbin/nginx
2.4設置Tengine開機啓動
cat >> /etc/init.d/nginx <<EOF #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ \${NETWORKING} = "no" ] && exit 0 [ -x \$nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e \$nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting \$prog: " daemon \$nginxd -c \${nginx_config} RETVAL=$? echo [ \$RETVAL = 0 ] && touch /var/lock/subsys/nginx return \$RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping \$prog: " killproc \$nginxd RETVAL=\$? echo [ \$RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading \$prog: " #kill -HUP `cat \${nginx_pid}` killproc \$nginxd -HUP RETVAL=\$? echo } # See how we were called. case "\$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status \$prog RETVAL=\$? ;; *) echo $"Usage: \$prog {start|stop|restart|reload|status|help}" exit 1 esac exit \$RETVAL EOF
授予執行權限
chmod +x /etc/init.d/nginx chkconfig nginx --level 345 on
三.測試
3.1 用瀏覽器訪問主機80端口
出現如圖所示界面即表示Tengine安裝完成!