天天看點

centos7 yum安裝的nginx添加子產品概述正文  結束

此文章已不再更新,檢視最新版内容和更多内容:

《Centos7 nginx 不中斷服務添加新子產品或第三方子產品》

--------------------------------------------------- 分隔符 ---------------------------------------------------

概述

    nginx作為一個超常用的web伺服器,負載均衡器,被廣泛使用。而nginx的各種功能是需要通過各種子產品來實作的,經常會遇到安裝時并沒有安裝此子產品,但後面由于業務需求等會使用到未安裝的子產品,此時就需要在原來nginx的基礎上添加新子產品,也可能是第三方子產品,而根據安裝nginx的方式,添加子產品的方法也不一樣。

    nginx源碼安裝,添加子產品,請參考我另一篇博文:

《centos7.2 源碼編譯安裝nginx,新增編譯子產品,實作tcp反向代理》

正文

    這裡詳細說明以下,通過yum安裝的nginx,如何新增子產品。整體思路是,需要下載下傳yum安裝的nginx相同版本的nginx源碼,然後通過源碼進行編譯,在編譯中添加新的子產品,然後将編譯完成後的nginx可執行檔案進行替換。已實作添加子產品。

1. 檢視現有nginx版本與編譯的參數

# 檢視版本與編譯參數,就是下面結果中的configure arguments:後面的參數,後面重新編譯時需要帶上
$ nginx -V
           
centos7 yum安裝的nginx添加子產品概述正文  結束

2. 下載下傳相同版本nginx

# 官網下載下傳nginx-1.12.2 并解壓
$ wget http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -zxvf nginx-1.12.2.tar.gz
           

3. 備份原有nginx和配置

# 暫時備份到使用者目錄下,以備操作錯誤時,進行還原
$ cp /usr/sbin/nginx ~/nginx.back
$ cp -r /ect/nginx ~/nginx.conf.back
           

4. 編譯nginx,添加子產品

# 安裝編譯的依賴包
yum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data gperftools redhat-rpm-config

# 進入nginx,進行編譯,編譯時需要将上面檢視到的現有nginx的參數都帶上,然後在最後面添加你需要新增的子產品
$ cd nginx-1.12.2

# 因為這裡我示例添加第三方子產品nginx-auth-ldap,需要安裝openldap-devel
$ yum install openldap-devel -y

# 其中最後的--add-module=為我這裡示例的需要增加的第三方子產品的存放路徑,第三方子產品需要提前下載下傳好
# 不管是第三方子產品,還是自身子產品,都直接在最後添加參數即可。
$ ./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-google_perftools_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' --add-module=/root/nginx-auth-ldap



# 編譯,注意:這裡很多說不能make install,隻make就好了,其實不然,
# 在執行./configure指令時則已經查出了原有nginx的各個檔案的路徑,如果原來沒有nginx,則會預設安裝到/usr/local/nginx目錄下。
# 直接執行make install 則會自動替換原來的nginx,無須手動,也不會中斷nginx程序。
$ make && make install

           

5. 檢查新nginx,重新開機生效

# 編譯後,會自動替換原有nginx,檢視nginx配置,是否還是之前的,檢視conf.d内的配置是否還在
$ cat /etc/nginx/nginx.conf 
$ ls /etc/nginx/conf.d

# 檢視nginx參數,看看我們新增的子產品在不在
$ nginx -V

# 重新開機nginx生效
$ systemctl restart nginx
           

檢視新的nginx,結果如下,會發現,我們新增的第三方子產品已經加在了最末尾

centos7 yum安裝的nginx添加子產品概述正文  結束

結束

    編譯安裝後,原有的nginx配置與檔案等都不會發生變化,不需要重新設定nginx配置等。直接重新開機就可以正常使用了。上面的備份檔案隻是一以備不時之需,在操作出錯時以友善恢複,正常新增子產品,測試使用正常後,備份檔案則可删除。

    有任何不明白或有問題的地方,歡迎留言指正,謝謝

繼續閱讀