• 动态加载模块方式扩展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/",如下图所示。

  • 相关阅读:
    如何在fragment里面嵌套viewpager?
    textview限制字数,结尾显示。。。。。
    限制imageview大小
    iOS开发核心动画之画图板
    iOS开发核心动画之九宫格解锁
    iOS开发核心动画之Quartz2D绘图
    iOS开发核心动画之触摸手指识别
    iOS开发网络多线程之断点下载
    iOS开发网络多线程之网络请求文件解析
    iOS开发网络多线程之Runloop无限循环
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12099502.html
Copyright © 2020-2023  润新知