使用Tengine替代Nginx實戰部署
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
大概是2019年3月11日,F5 Networks宣布將以6.7億美元收購Nginx,消息一出,網上很多小伙伴開始炸鍋了,紛紛議論Nginx后續的版本會不會收費之類的話。Nginx的確是一款優秀的web服務器,不過咱們中國還有一款基於Nginx二次開發的軟件叫Tengine,它是由阿里巴巴集團開源的,目前阿里巴巴的電商網站使用的就是Tengine,據說性能在Nginx之上。
淘寶網,天貓網使用就是阿里巴巴公司自己開源的Tengine這款web服務器,當然,還有其它一些公司也在使用Tengine。
一.Tengine概述
1>.什么是Tenine
Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了很多高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶網,天貓商城等得到了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平台。 從2011年12月開始,Tengine成為一個開源項目,Tengine團隊在積極地開發和維護着它。Tengine團隊的核心成員來自於淘寶、搜狗等互聯網企業。 官網地址:http://tengine.taobao.org/
2>.下載Tenine
下載地址:
http://tengine.taobao.org/download.html
二.編譯安裝Tengine
1>.停用現有的nginx服務
[root@node101.yinzhengjie.org.cn ~]# netstat -ntalp | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24954/nginx: master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 24954/nginx: master [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# nginx -s stop [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# netstat -ntalp | grep nginx [root@node101.yinzhengjie.org.cn ~]#
2>.下載Tengine的安裝包
[root@node101.yinzhengjie.org.cn ~]# cd /usr/local/src/ [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# ll total 992 drwxr-xr-x 6 root root 186 Dec 23 22:35 echo-nginx-module drwxr-xr-x 9 1001 1001 186 Dec 22 08:19 nginx-1.14.2 -rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz --2019-12-24 20:55:13-- http://tengine.taobao.org/download/tengine-2.3.2.tar.gz Resolving tengine.taobao.org (tengine.taobao.org)... 140.205.230.4 Connecting to tengine.taobao.org (tengine.taobao.org)|140.205.230.4|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2835884 (2.7M) [application/octet-stream] Saving to: ‘tengine-2.3.2.tar.gz’ 100%[===========================================================================================================>] 2,835,884 482KB/s in 5.9s 2019-12-24 20:55:19 (470 KB/s) - ‘tengine-2.3.2.tar.gz’ saved [2835884/2835884] [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# ll total 3764 drwxr-xr-x 6 root root 186 Dec 23 22:35 echo-nginx-module drwxr-xr-x 9 1001 1001 186 Dec 22 08:19 nginx-1.14.2 -rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz -rw-r--r-- 1 root root 2835884 Sep 5 16:58 tengine-2.3.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]#
3>.編譯安裝Tengine
[root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# tar -xf tengine-2.3.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# cd tengine-2.3.2/ [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# nginx -V #由於Tengine是兼容Nginx的,咱們直接復制Nginx的編譯參數來安裝Tengine,但千萬別忘記修改安裝路徑哈~ nginx version: nginx/1.14.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/yinzhengjie/softwares/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip _module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/echo-nginx-module [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# ./configure --prefix=/yinzhengjie/softwares/tengine --user=nginx --group=nginx --with-h ttp_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream
--with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/echo-nginx-module ...... [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# echo $? 0 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# make -j 4 && make install [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# echo $? 0 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# ll /yinzhengjie/softwares/ #很顯然,安裝完成啦~ total 0 drwxr-xr-x 13 nginx nginx 178 Dec 22 09:21 nginx drwxr-xr-x 6 root root 54 Dec 24 21:14 tengine [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]#
4>.檢查Tengine的版本
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -V Tengine version: Tengine/2.3.2 nginx version: nginx/1.17.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/yinzhengjie/softwares/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_real ip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
--add-module=/usr/local/src/echo-nginx-module
[root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]#
三.使用Nginx的配置文件啟動Tengine
1>.修改Tengine的子配置文件(此處請允許我先買個坑)
[root@node101.yinzhengjie.org.cn ~]# cd /yinzhengjie/softwares/tengine/ [root@node101.yinzhengjie.org.cn /yinzhengjie/softwares/tengine]# [root@node101.yinzhengjie.org.cn /yinzhengjie/softwares/tengine]# ll total 0 drwxr-xr-x 2 root root 333 Dec 24 21:14 conf drwxr-xr-x 2 root root 40 Dec 24 21:14 html drwxr-xr-x 2 root root 6 Dec 24 21:14 logs drwxr-xr-x 2 root root 19 Dec 24 21:14 sbin [root@node101.yinzhengjie.org.cn /yinzhengjie/softwares/tengine]# [root@node101.yinzhengjie.org.cn /yinzhengjie/softwares/tengine]# vim conf/nginx.conf #在Tengine的主配置文件末尾加載Nginx的配置文件,如下圖所示
2>.我們發現檢查語法時報錯啦,因為我們是在Tengine中加載的Nginx的子配置文件,而Nginx中子配置文件使用Nginx主配置文件中的變量

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf server { listen 80; listen 443 ssl; server_name node101.yinzhengjie.org.cn; access_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_org_cn_access.log my_access_json; error_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_org_cn_error.log; location / { root /yinzhengjie/data/web/nginx/static/cn; index index.html; #定義有效的請求referer,用空格隔開即可 valid_referers none blocked server_names *.baidu.com example.* ~\.google\.; #如果沒有在上面的有效鏈接定義那么均屬於無效請求referer if ($invalid_referer) { return 403; } #如果是一些常見的壓測試工具,咱們直接進給他拒絕訪問 if ($http_user_agent ~ "ApacheBench|WebBench|TurnitinBot|Sougou web spider|Grid Server"){ return 403; } } location = /favicon.ico { root /yinzhengjie/data/web/nginx/images/jd; } } [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_com.conf server { listen 80; listen 443 ssl; server_name node101.yinzhengjie.com; access_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_com_access.log my_access_json; error_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_com_error.log; location / { root /yinzhengjie/data/web/nginx/static/com; index index.html; } location = /favicon.ico { root /yinzhengjie/data/web/nginx/images/jd; } } [root@node101.yinzhengjie.org.cn ~]#

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf/nginx.conf worker_processes 4; worker_cpu_affinity 00000001 00000010 00000100 00001000; events { worker_connections 100000; use epoll; accept_mutex on; multi_accept on; } http { include mime.types; default_type text/html; server_tokens off; charset utf-8; log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"re sponsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; access_log logs/access_json.log my_access_json; ssl_certificate /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.crt; ssl_certificate_key /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; include /yinzhengjie/softwares/nginx/conf.d/*.conf; } [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/nginx/conf.d/ #這里存放着Nginx的子配置文件,關於Nginx的配置文件內容戳上面的代碼查看詳情 total 8 -rw-r--r-- 1 root root 461 Dec 24 18:16 node101_yinzhengjie_com.conf -rw-r--r-- 1 root root 972 Dec 24 19:57 node101_yinzhengjie_org.cn.conf [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -t #我們檢查語法時發現報錯啦,這是因為Nginx主配置文件中定義了一個叫"my_access_jason"的變量 nginx: [emerg] unknown log format "my_access_json" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_com.conf:6 nginx: configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf test failed [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /yinzhengjie/softwares/tengine/conf/nginx.conf #查看Tengine的默認配置文件 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include /yinzhengjie/softwares/nginx/conf.d/*.conf; } [root@node101.yinzhengjie.org.cn ~]#
3>.自定義Tengine的日志格式,名稱要和Nginx子配置文件中調用的一致
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /yinzhengjie/softwares/tengine/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"res ponsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; include /yinzhengjie/softwares/nginx/conf.d/*.conf; } [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -t #Duang~我們發現報錯信息變量,說是缺少SSL相關配置 nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_com.conf :1nginx: configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf test failed [root@node101.yinzhengjie.org.cn ~]#
4>.將Nginx的證書文件在Tengine中配置問題得到解決
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /yinzhengjie/softwares/tengine/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } ssl_certificate /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.crt; ssl_certificate_key /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"res ponsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; include /yinzhengjie/softwares/nginx/conf.d/*.conf; } [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -t nginx: the configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf syntax is ok nginx: configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf test is successful [root@node101.yinzhengjie.org.cn ~]#
5>.若不想經理上述麻煩的修改配置文件過程,直接將Nginx的主配置文件拷貝到Tengine的主配置目錄即可(埋坑結束)
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -t #經過上面的排錯過程中,終於配置文件語法沒有啥問題了。 nginx: the configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf syntax is ok nginx: configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf test is successful [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 :::22 :::* [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx #啟動Tengine [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 *:443 *:* LISTEN 0 128 :::22 :::* [root@node101.yinzhengjie.org.cn ~]#
6>.瀏覽器訪問"http://node101.yinzhengjie.org.cn/",注意觀察Web Server的版本喲~
四.隱藏Tengine的版本號
1>.修改主配置文件
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#將Nginx的ssl相關配置拷貝過來
ssl_certificate /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.crt;
ssl_certificate_key /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.key;
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
#自定義Nginx日志格式
log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"res
ponsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}';
#加載Nginx的子配置文件以供Tengine使用
include /yinzhengjie/softwares/nginx/conf.d/*.conf;
#隱藏Tengine的版本號
server_tokens off;
}
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -t
nginx: the configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/tengine/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#
2>.重新加載Tengine的配置文件
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep tengine | grep -v grep
root 671 1 0 22:14 ? 00:00:00 nginx: master process /yinzhengjie/softwares/tengine/sbin/nginx
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# pstree -p 671
nginx(671)───nginx(727)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine/sbin/nginx -s reload
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep tengine | grep -v grep
root 671 1 0 22:14 ? 00:00:00 nginx: master process /yinzhengjie/softwares/tengine/sbin/nginx
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# pstree -p 671
nginx(671)───nginx(737)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
3>.瀏覽器訪問"http://node101.yinzhengjie.org.cn/",注意觀察Web Server的版本喲~
五.生產環境中推薦使用官方最新的穩定版本
以上演示案例采用的是2019年9月80日發布的版本部署,經測試,有些特定功能該版本並沒有,於是更換為2015年12月31日發布的最新穩定版,版本不追求最新,我們運維人員最應該追求的功能穩定,安全。
1>.下載Tengine 2.1.2版本

[root@node101.yinzhengjie.org.cn ~]# cd /usr/local/src/ [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# ll total 3768 drwxr-xr-x 6 root root 186 Dec 23 22:35 echo-nginx-module drwxr-xr-x 9 1001 1001 186 Dec 22 08:19 nginx-1.14.2 -rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz drwxrwxr-x 14 root root 4096 Dec 24 21:11 tengine-2.3.2 -rw-r--r-- 1 root root 2835884 Sep 5 16:58 tengine-2.3.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz --2019-12-26 06:01:15-- http://tengine.taobao.org/download/tengine-2.1.2.tar.gz Resolving tengine.taobao.org (tengine.taobao.org)... 140.205.230.4 Connecting to tengine.taobao.org (tengine.taobao.org)|140.205.230.4|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2137295 (2.0M) [application/octet-stream] Saving to: ‘tengine-2.1.2.tar.gz’ 100%[==================================================================================================================================>] 2,137,295 458KB/s in 4.6s 2019-12-26 06:01:19 (452 KB/s) - ‘tengine-2.1.2.tar.gz’ saved [2137295/2137295] [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# ll total 5856 drwxr-xr-x 6 root root 186 Dec 23 22:35 echo-nginx-module drwxr-xr-x 9 1001 1001 186 Dec 22 08:19 nginx-1.14.2 -rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz -rw-r--r-- 1 root root 2137295 Sep 5 16:58 tengine-2.1.2.tar.gz drwxrwxr-x 14 root root 4096 Dec 24 21:11 tengine-2.3.2 -rw-r--r-- 1 root root 2835884 Sep 5 16:58 tengine-2.3.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]#
2>.查看最新版本和最穩定版本支持的編譯參數
[root@node101.yinzhengjie.org.cn /usr/local/src]# ll total 5856 drwxr-xr-x 6 root root 186 Dec 23 22:35 echo-nginx-module drwxr-xr-x 9 1001 1001 186 Dec 22 08:19 nginx-1.14.2 -rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz -rw-r--r-- 1 root root 2137295 Sep 5 16:58 tengine-2.1.2.tar.gz drwxrwxr-x 14 root root 4096 Dec 24 21:11 tengine-2.3.2 -rw-r--r-- 1 root root 2835884 Sep 5 16:58 tengine-2.3.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# tar -xf tengine-2.1.2.tar.gz [root@node101.yinzhengjie.org.cn /usr/local/src]# [root@node101.yinzhengjie.org.cn /usr/local/src]# cd tengine-2.1.2/ [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# ./configure --help | grep concat #大家看這里,2015年發布的穩定版本編譯是支持"--with-http_concat_module"配置參數的 --with-http_concat_module enable ngx_http_concat_module --with-http_concat_module=shared enable ngx_http_concat_module (shared) [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# cd ../tengine-2.3.2/ #很明顯,現在最新版本的Tengine是不支持上面提到的編譯參數的,根據淘寶官網的提示說需要使用上面的功能得單獨源碼安裝該模塊,為了簡單省事,我推薦大家直接使用穩定版本即可。 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# ./configure --help | grep concat [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]#
3>.編譯安裝穩定的Tengine版本
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# /yinzhengjie/softwares/tengine/sbin/nginx -s stop [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# /yinzhengjie/softwares/tengine/sbin/nginx -V Tengine version: Tengine/2.3.2 nginx version: nginx/1.17.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/yinzhengjie/softwares/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_s tub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/echo-nginx-module [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# ./configure --prefix=/yinzhengjie/softwares/tengine-2.1.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/echo-nginx-module ./configure: error: invalid option "--with-stream" #如果出現這個報錯那是因為2015年發布的穩定版本壓根不支持反向代理(Nginx1.9以上版本才支持的TCP反向代理功能),因此需要將含有"with-stream"的配置參數都去掉。 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# ./configure --prefix=/yinzhengjie/softwares/tengine-2.1.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --add-module=/usr/local/src/echo-nginx-module ...... [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# echo $? 0 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# make -j 4 && make install ...... [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# echo $? 0 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# ll /yinzhengjie/softwares/ total 0 drwxr-xr-x 13 nginx nginx 178 Dec 22 09:21 nginx drwxr-xr-x 11 root root 151 Dec 24 22:11 tengine drwxr-xr-x 8 root root 84 Dec 26 06:53 tengine-2.1.2 [root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]#
4>.將最新版本的Tengine的配置文件直接拷貝到最穩定版本的Tengine的配置文件中

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } #將Nginx的ssl相關配置拷貝過來 ssl_certificate /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.crt; ssl_certificate_key /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; #自定義Nginx日志格式 log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_tim e,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; #加載Nginx的子配置文件以供Tengine使用 include /yinzhengjie/softwares/nginx/conf.d/*.conf; #隱藏Tengine的版本號 server_tokens off; } [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cp /yinzhengjie/softwares/tengine/conf/nginx.conf /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf cp: overwrite ‘/yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf’? y [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -t the configuration file /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf syntax is ok configuration file /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf test is successful [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 :::22 :::* [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 *:443 *:* LISTEN 0 128 :::22 :::* [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -v Tengine version: Tengine/2.1.2 (nginx/1.6.2) [root@node101.yinzhengjie.org.cn ~]#
5>.瀏覽器訪問"http://node101.yinzhengjie.org.cn/",可以正常訪問,如下圖所示