1. 程式人生 > >yum安裝下的nginx,如何新增模組,和新增第三方模組

yum安裝下的nginx,如何新增模組,和新增第三方模組

需求:生產有個介面是通過socket通訊。nginx1.9開始支援tcp層的轉發,通過stream實現的,而socket也是基於tcp通訊。

實現方法:Centos7.2下yum直接安裝的nginx,新增新模組支援tcp轉發;重新編譯Nginx並新增 --with-stream 引數。

實現過程:

1.  檢視nginx版本模組 

[[email protected] ~]# nginx -V

 

2.  下載一個同版本可編譯的Nginx

cd /opt 
wget http://nginx.org/download/nginx-1.12.2.tar.gz 
tar xf nginx-1.12.2.tar.gz && cd nginx-1.12.2

 

3.  備份原Nginx檔案

mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx{,.bak}

 

4.  重新編譯Nginx

檢查模組是否支援,比如這次新增 limit 限流模組 和 stream 模組:
./configure –help | grep limit
這裡寫圖片描述
ps:-without-http_limit_conn_module disable 表示已有該模組,編譯時,不需要新增

./configure –help | grep stream
這裡寫圖片描述
ps:–with-stream enable 表示不支援,編譯時要自己新增該模組

根據第1步查到已有的模組,加上本次需新增的模組: --with-stream

複製程式碼
cd /opt/nginx-1.12.2

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --with-stream
複製程式碼

以上編譯時,如出現缺少依賴,一般需要安裝以下模組,安裝完再次編譯:

yum -y install libxml2 libxml2-dev libxslt-devel 
yum -y install gd-devel yum -y install perl-devel perl-ExtUtils-Embed yum -y install GeoIP GeoIP-devel GeoIP-data yum -y install pcre-devel yum -y install openssl openssl-devel

 

5.  編譯通過,繼續驗證 
繼續輸入:make  
make完成後不要繼續輸入“make install”,以免現在的nginx出現問題 
以上完成後,會在objs目錄下生成一個nginx檔案,先驗證: 

/opt/nginx-1.12.2/objs/nginx -t 
/opt/nginx-1.12.2/objs/nginx -V

 

6.  替換Nginx檔案並重啟

cp /opt/nginx-1.12.2/objs/nginx /usr/sbin/ 
nginx -s reload


7.  檢查

[[email protected] ~]# nginx -V

新增模組成功!!!