動態加載模塊方式擴展Tengine功能實戰


             動態加載模塊方式擴展Tengine功能實戰

                                          作者:尹正傑

版權聲明:原創作品,謝絕轉載!否則將追究法律責任。

 

 

 

一.編譯安裝Tengine-2.1.2

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]# 
[root@node101.yinzhengjie.org.cn /usr/local/src]# wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz

2>.編譯安裝穩定的Tengine版本

[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 --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]# 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
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# 

[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 08:06 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]# 

3>.開啟Tengine的多文件合並功能失敗

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine-2.1.2/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 ~]# cat /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf
[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;

       #開啟多文件合並功能,該功能需要加載Tengine獨有的模塊
       concat on;

       #定義有效的請求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 ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -t        #注意看提示,Tengine說不支持
nginx: [emerg] unknown directive "concat" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf:14
configuration file /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf test failed
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

4>.查看Tengine的版本,觀察是否有"ngx_http_concat_module"相關的模塊

[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -V        #從編譯參數來看,編譯安裝時壓根就沒有編譯Tengine相關模塊
Tengine version: Tengine/2.1.2 (nginx/1.6.2)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
TLS SNI support enabled
configure arguments: --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
nginx: [emerg] unknown directive "concat" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf:14 [root@node101.yinzhengjie.org.cn ~]#

5>.對比Nginx和Tengeine是否支持多文件合並

[root@node101.yinzhengjie.org.cn /usr/local/src]# ll
total 5860
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
drwxr-xr-x 13 50469 users    4096 Dec 26 06:52 tengine-2.1.2
-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]# 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]# 
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.3.2]# ./configure --help | grep concat        #我們發現2019年8月20號發布的Tengine版本並沒有直接支持ngx_http_concat_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]# 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年12月31日發布最新的穩定版本是支持"多文件合並"功能的。
  --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 ../nginx-1.14.2/  
[root@node101.yinzhengjie.org.cn /usr/local/src/nginx-1.14.2]# 
[root@node101.yinzhengjie.org.cn /usr/local/src/nginx-1.14.2]# ./configure --help | grep concat         #很顯然,多文件合並是是Tengine獨有的功能,Nginx並不支持。
[root@node101.yinzhengjie.org.cn /usr/local/src/nginx-1.14.2]# 

6>.Tengine支持動態加載模塊

[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# ./configure --help | grep concat
  --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]# 

溫馨提示:
  --with-http_concat_module:
    這個是Tengine的靜態模塊
  --with-http_concat_module=shared 
    這個就是Tengine的動態模塊

動態加載模塊描述:   這個模塊主要是用來運行時動態加載模塊,而不用每次都要重新編譯Tengine.   如果你想要編譯官方模塊為動態模塊,你需要在configure的時候加上類似這樣的指令(
--with-http_xxx_module),./configure --help可以看到更多的細節.   如果只想要安裝官方模塊為動態模塊(不安裝Nginx),那么就只需要configure之后,執行 make dso_install命令.   動態加載模塊的個數限制為128個.   如果已經加載的動態模塊有修改,那么必須重起Tengine才會生效.   只支持HTTP模塊.   模塊 在Linux/FreeeBSD/MacOS下測試成功.

博主推薦閱讀:
   http://tengine.taobao.org/document_cn/dso_cn.html

 

二.傳統方式完整編譯安裝(擴展Tengine支持多文件合並功能的方案1)

1>.重新配置Tengine支持的參數

[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -V            #查看Tengine的編譯參數,由於配置文件存在目前不支持的指令,會有報錯信息
Tengine version: Tengine/2.1.2 (nginx/1.6.2)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
TLS SNI support enabled
configure arguments: --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
nginx: [emerg] unknown directive "concat" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf:14
[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 
--with-http_concat_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]# 

2>.編譯安裝Tengine

[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# md5sum /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx        #觀察MD5值
fa194cbc9b3f3a0834eefa88aa83a184 /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx
[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]# md5sum /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx        #我們不難發現MD5值有所變化。
3456227b9c7d9e5f31e74695f69156ff  /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# 

3>.再次校驗Tengine的配置文件(我們整個過程並沒有)

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine-2.1.2/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 ~]# cat /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf
[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;

       #開啟多文件合並功能
       concat on;

       #定義有效的請求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_org.cn.conf
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# /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 /usr/local/src/tengine-2.1.2]# 
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -V
Tengine version: Tengine/2.1.2 (nginx/1.6.2)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
TLS SNI support enabled
configure arguments: --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 --with-http_concat_moduleloaded modules:
    ngx_core_module (static)
    ngx_errlog_module (static)
    ngx_conf_module (static)
    ngx_dso_module (static)
    ngx_syslog_module (static)
    ngx_events_module (static)
    ngx_event_core_module (static)
    ngx_epoll_module (static)
    ngx_procs_module (static)
    ngx_proc_core_module (static)
    ngx_openssl_module (static)
    ngx_regex_module (static)
    ngx_http_module (static)
    ngx_http_core_module (static)
    ngx_http_log_module (static)
    ngx_http_upstream_module (static)
    ngx_http_v2_module (static)
    ngx_http_static_module (static)
    ngx_http_gzip_static_module (static)
    ngx_http_autoindex_module (static)
    ngx_http_index_module (static)
    ngx_http_concat_module (static)
    ngx_http_auth_basic_module (static)
    ngx_http_access_module (static)
    ngx_http_limit_conn_module (static)
    ngx_http_limit_req_module (static)
    ngx_http_realip_module (static)
    ngx_http_geo_module (static)
    ngx_http_map_module (static)
    ngx_http_split_clients_module (static)
    ngx_http_referer_module (static)
    ngx_http_rewrite_module (static)
    ngx_http_ssl_module (static)
    ngx_http_proxy_module (static)
    ngx_http_fastcgi_module (static)
    ngx_http_uwsgi_module (static)
    ngx_http_scgi_module (static)
    ngx_http_memcached_module (static)
    ngx_http_empty_gif_module (static)
    ngx_http_browser_module (static)
    ngx_http_user_agent_module (static)
    ngx_http_upstream_ip_hash_module (static)
    ngx_http_upstream_consistent_hash_module (static)
    ngx_http_upstream_check_module (static)
    ngx_http_upstream_least_conn_module (static)
    ngx_http_upstream_keepalive_module (static)
    ngx_http_upstream_dynamic_module (static)
    ngx_http_stub_status_module (static)
    ngx_http_write_filter_module (static)
    ngx_http_header_filter_module (static)
    ngx_http_chunked_filter_module (static)
    ngx_http_v2_filter_module (static)
    ngx_http_range_header_filter_module (static)
    ngx_http_gzip_filter_module (static)
    ngx_http_postpone_filter_module (static)
    ngx_http_ssi_filter_module (static)
    ngx_http_charset_filter_module (static)
    ngx_http_userid_filter_module (static)
    ngx_http_footer_filter_module (static)
    ngx_http_trim_filter_module (static)
    ngx_http_headers_filter_module (static)
    ngx_http_upstream_session_sticky_module (static)
    ngx_http_reqstat_module (static)
    ngx_http_echo_module (static)
    ngx_http_copy_filter_module (static)
    ngx_http_range_body_filter_module (static)
    ngx_http_not_modified_filter_module (static)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -V

4>.啟動Tengine

[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 ~]# 

5>.瀏覽器訪問"http://node101.yinzhengjie.org.cn/",如下圖所示。

 

 

三.動態加載模塊方式(擴展Tengine支持多文件合並功能的方案2)

1>.停止Tengine服務並刪除第二步編譯安裝的軟件包(目的就是為了再次模擬第一步出現的故障)

[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 -s stop
[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 ~]# rm -rf /yinzhengjie/softwares/tengine-2.1.2/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 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
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

2>.重新編譯安裝Tengine-2.1-2,不要添加"--with-http_concat_module"模塊

[root@node101.yinzhengjie.org.cn ~]# cd /usr/local/src/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 --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]# 
[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 08:57 tengine-2.1.2
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# 

3>.重現無法支持多文件合並功能模塊的現象

[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
nginx: [emerg] unknown directive "concat" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf:14
configuration file /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf test failed
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

4>.重新編譯Tengine2.1.2支持動態模塊

[root@node101.yinzhengjie.org.cn ~]# md5sum /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx 
268b7f447c1f1d520d932fcc56b179ba  /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cd /usr/local/src/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 --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 --with-http_concat_module=shared
......
[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/tengine-2.1.2/modules/     #目前該模塊是空的。
total 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 dso_install                        #此處我們只需要編譯支持模塊即可,無序執行make install啦~
......
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]#
[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/tengine-2.1.2/modules/     #注意,我們發現模塊目錄竟然有相應的模塊啦,需要注意的是Tengine支持的動態加載模塊個數為128個喲~
total 92
-rwxr-xr-x 1 root root 93264 Dec 26 09:09 ngx_http_concat_module.so
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# 
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# md5sum /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx 
268b7f447c1f1d520d932fcc56b179ba  /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx
[root@node101.yinzhengjie.org.cn /usr/local/src/tengine-2.1.2]# 

5>.修改Tengine的主配置文件加載上面我們編譯的模塊

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine-2.1.2/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 ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf        #未修改之前的Tengine配置文件
[root@node101.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -t            #我們發現主配置文件未加載模塊時校驗失敗了
nginx: [emerg] unknown directive "concat" in /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf:14
configuration file /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf test failed
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# vim /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf        #編輯Tengine的主配置文件,讓其加載咱們的動態編譯模塊。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/tengine-2.1.2/conf/nginx.conf
worker_processes  1;

#在全局配置中加載咱們的模塊
dso {
    load ngx_http_concat_module.so;
}

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 ~]# /yinzhengjie/softwares/tengine-2.1.2/sbin/nginx -t            #在Tengine的主配置文件加載concat模塊后,我們發現這里並不報錯啦~
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 ~]# 

6>.啟動Tengine

[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 ~]# 

7>.瀏覽器訪問"http://node101.yinzhengjie.org.cn/",如下圖所示。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM