• 八方資訊網(wǎng)歡迎您!
    八方資訊網(wǎng)>游戲>正文

    nginx-2:部署生產(chǎn)級openresty

    2020-03-23 09:22:29 來源: 閱讀:

    目錄

    (1).下載源碼

    (2).openrestry低版本編譯命令

    (3).openrestry高版本編譯命令

    1.編譯命令

    2.注意事項(xiàng)

    3.編譯錯(cuò)誤與解決

    (4).openrestry安裝第三方庫lua_resty_http

    1.安裝第三方庫lua_resty_http

    2.安裝第三方庫nginx-lua-prometheus

    (5).使用lua所必須的模塊(openresty自帶)

    (6).configure參數(shù)詳解

    (7).相關(guān)閱讀

    (8).相關(guān)閱讀


    (1).下載源碼


    https://openresty.org/cn/download.html

    我下載的是最新版本:openresty-1.15.8.1.tar.gz


    tar -xzvf openresty-VERSION.tar.gz

    cd openresty-VERSION/

    #需要安裝各種組件以適用于生產(chǎn)環(huán)境

    下載第三方插件:

    git clone https://github.com/replay/ngx_http_consistent_hash.git

    后邊安裝openresty時(shí)有參數(shù)指向上述工程的本地地址。


    (2).openrestry低版本編譯命令


    低版本編譯時(shí)需要手動(dòng)指定很多組件(使用高版本不用指定下述這么多):

    ./configure --prefix=/app/3rd/nginx/openresty --with-cc-opt=-O2 --add-module=build/ngx_devel_kit-0.3.1rc1 --add-module=build/ngx_stream_lua-0.0.7 --add-module=build/iconv-nginx-module-0.14 --add-module=build/echo-nginx-module-0.61 --add-module=build/xss-nginx-module-0.06 --add-module=build/ngx_coolkit-0.2 --add-module=build/set-misc-nginx-module-0.32 --add-module=build/form-input-nginx-module-0.12 --add-module=build/encrypted-session-nginx-module-0.08 --add-module=build/srcache-nginx-module-0.31 --add-module=build/ngx_lua-0.10.15 --add-module=build/ngx_lua_upstream-0.07 --add-module=build/headers-more-nginx-module-0.33 --add-module=build/array-var-nginx-module-0.05 --add-module=build/memc-nginx-module-0.19 --add-module=build/redis-nginx-module-0.3.7 --add-module=build/rds-json-nginx-module-0.15 --add-module=build/rds-csv-nginx-module-0.09 --with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib --add-module=/app/3rd/src-install/ngx_http_consistent_hash --with-http_stub_status_module --with-pcre-jit --with-stream_ssl_preread_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-openssl=/opt/openresty/openssl-1.1.0i --with-dtrace-probes --with-stream --with-stream_ssl_module --with-pcre=/opt/openresty/pcre-8.40


    (3).openrestry高版本編譯命令


    1.15.8.1+,很多module不需要手工指定,默認(rèn)安裝:


    1.編譯命令


    ./configure --prefix=/app/3rd/nginx/openresty --with-cc-opt=-O2 --add-module=build/iconv-nginx-module-0.14 --with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib --add-module=/app/3rd/src-install/ngx_http_consistent_hash --with-http_stub_status_module --with-pcre-jit --with-stream_ssl_preread_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-openssl=/opt/openresty/openssl-1.1.0i --with-dtrace-probes --with-stream --with-stream_ssl_module --with-pcre=/opt/openresty/pcre-8.40

    gmake

    gmake install


    2.注意事項(xiàng)


    --add-module=build/ngx_stream_lua-0.0.7不需要加,因?yàn)椋?/p>

    ngx_stream_lua_module is already enabled in OpenResty by default. Your linker errors clearly indicate that. You should remove the option --add-module=build/ngx_stream_lua-0.0.7.

    官方git issue回復(fù):

    https://github.com/openresty/openresty/issues/507

    multiple definition of `ngx_http_rds_csv_output_more_field_data':表示add-module中的已經(jīng)自動(dòng)包含,不需要add-module主動(dòng)指定。


    3.編譯錯(cuò)誤與解決


    3.1.編譯錯(cuò)誤1


    configure階段報(bào)錯(cuò):the HTTP rewrite module requires the PCRE library


    ./configure: error: the HTTP rewrite module requires the PCRE library.

    安裝pcre-devel與openssl-devel解決問題

    yum -y install pcre-devel openssl openssl-devel


    3.2.編譯錯(cuò)誤2


    gmake階段報(bào)錯(cuò):dtrace command not foud錯(cuò)誤:

    安裝dtrace

    git clone https://github.com/dtrace4linux/linux.git

    有可能提示libgcc需要upgrade,執(zhí)行yum upgrade libgcc即可。

    centos執(zhí)行:tools/get-deps-fedora.sh安裝依賴。

    make all

    make install

    make load


    3.3.編譯錯(cuò)誤3

    gmake階段報(bào)錯(cuò):/opt/openresty/openssl-1.1.0i: No such file or directory

    https://github.com/openssl/openssl/releases?after=OpenSSL_1_1_1-pre9

    下載:

    wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0i.tar.gz

    正常安裝openssl的步驟:

    ./config --prefix=/opt/openresty/openssl-1.1.0i

    make

    make install

    但是openrestry依賴的openssl不能這樣安裝,需要把openssl的源碼copy到目錄:

    /opt/openresty/openssl-1.1.0i

    然后執(zhí)行openrestry階段時(shí),會自動(dòng)到上邊目錄部署openssl.

    錯(cuò)誤提示(gmake階段):collect2: error: ld returned 1 exit status

    網(wǎng)上相同問題的解決方式:

    https://blog.csdn.net/iaiot/article/details/78273921

    openrestry執(zhí)行configure時(shí)指定pcre目錄。也可以參考官方文檔:https://openresty.org/en/installation.html

    ./configure --with-pcre=../pcre-8.40 -j4

    pcre8.40下載地址:

    https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz

    all version:

    https://ftp.pcre.org/pub/pcre/

    但是又遇到了另一個(gè)問題:

    configure: error: You need a C++ compiler for C++ support.

    解決方法:

    yum install -y gcc gcc-c++

    /opt/openresty/pcre-8.40/missing: line 81: automake-1.15: command not found:

    wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz

    ./bootstrap.sh

    ./configure

    make

    make install


    (4).openrestry安裝lua第三方庫


    1.安裝第三方庫lua_resty_http


    參考:

    https://git.102no.com/2018/12/21/lua-resty-http/

    第一步

    首先找到項(xiàng)目地址:https://github.com/pintsized/lua-resty-http

    第二步

    然后將 lua-resty-http/lib/resty/ 目錄下的 http.lua 和 http_headers.lua 兩個(gè)文件拷貝到openresty/lualib/resty 目錄下即可,

    OpenResty 安裝目錄為 openresty)。不需要重啟。(少數(shù)需要清空 Openresty shared_dict 數(shù)據(jù)的情況需要重啟 )。


    2.安裝第三方庫nginx-lua-prometheus


    openrestry添加prometheus監(jiān)控的Lua擴(kuò)展:

    參考:

    https://www.jianshu.com/p/3341db428978

    git clone https://github.com/knyar/nginx-lua-prometheus

    prometheus.lua拷貝到lualib下。


    (5).使用lua所必須的模塊(openresty自帶)


    lua-nginx-module:是 Lua 的最基本模塊。


    luajit:官網(wǎng),luajit 是采用 C 語言編寫的 Lua 語言解釋器。當(dāng)然如果你不想用 luajit 的話,也可以 yum 安裝 lua 并提供給 Nginx,不推薦那樣而已。


    ngx_devel_kit:一般簡稱 NDK,是一個(gè)供其它模塊使用的拓展 Nginx 核心功能的模塊,第三方模塊開發(fā)可以基于它快速實(shí)現(xiàn)。強(qiáng)烈建議編譯 Lua 時(shí)把它也帶上,雖然不是必須的,缺少該依賴項(xiàng)時(shí)例如 set_by_lua* 和 ndk.set_var.* API 都將被自動(dòng)禁用。


    (6).configure參數(shù)詳解


    ./configure

    #指定安裝的位置

    --prefix=/app/3rd/nginx/openresty/nginx

    #設(shè)置C編譯器參數(shù):

    # -O1 提供基礎(chǔ)級別的優(yōu)化

    # -O2提供更加高級的代碼優(yōu)化,會占用更長的編譯時(shí)間

    # -O3提供最高級的代碼優(yōu)化

    --with-cc-opt=-O2

    #一般簡稱 NDK,是一個(gè)供其它模塊使用的拓展 Nginx 核心功能的模塊;

    # 第三方模塊開發(fā)可以基于它快速實(shí)現(xiàn)。

    # 強(qiáng)烈建議編譯 Lua 時(shí)把它也帶上,雖然不是必須的,缺少該依賴項(xiàng)時(shí)例如 set_by_lua* 和 ndk.set_var.* API 都將被自動(dòng)禁用

    --add-module=build/ngx_devel_kit-0.3.1rc1

    #編碼轉(zhuǎn)換模塊

    --add-module=build/iconv-nginx-module-0.14

    #nginx echo模塊是在nginx程序上擴(kuò)展了echo輸出字符的功能, 對于調(diào)試很方便。

    --add-module=build/echo-nginx-module-0.61

    #Nginx 中的原生跨站點(diǎn)腳本支持

    --add-module=build/xss-nginx-module-0.06

    #操作cookie的模塊

    --add-module=build/ngx_coolkit-0.2

    #模塊是標(biāo)準(zhǔn)的HttpRewriteModule指令的擴(kuò)展,提供更多的功能,如URI轉(zhuǎn)義與非轉(zhuǎn)義、JSON引述、Hexadecimal/MD5/SHA1/Base32/Base64編碼與解碼、隨機(jī)數(shù)等等。

    --add-module=build/set-misc-nginx-module-0.32

    #作用是解析post請求中的參數(shù)。

    --add-module=build/form-input-nginx-module-0.12

    #encrypt and decrypt nginx variable values。

    --add-module=build/encrypted-session-nginx-module-0.08

    #針對代理層緩存,我們可以將靜態(tài)資源放入cdn或者本地頁面緩存加快用戶訪問速度,緩解服務(wù)器壓力。比如結(jié)合pika實(shí)現(xiàn)。

    --add-module=build/srcache-nginx-module-0.31

    #Lua 的最基本模塊。

    --add-module=build/ngx_lua-0.10.15

    #Lua&upstream模塊。

    --add-module=build/ngx_lua_upstream-0.07

    #Set and clear input and output headers...more than "add"!

    #提供操作header的各種方法。

    --add-module=build/headers-more-nginx-module-0.33

    #Add support for array variables to NGINX config files

    #增加數(shù)組變量的支持。

    --add-module=build/array-var-nginx-module-0.05

    #提供memcached的各種操作。

    --add-module=build/memc-nginx-module-0.19

    #提供redis的各種操作。

    --add-module=build/redis-nginx-module-0.3.7

    #提供db的操作支持,json格式。

    --add-module=build/rds-json-nginx-module-0.15

    #提供db的操作支持,csv格式。

    --add-module=build/rds-csv-nginx-module-0.09

    #lua相關(guān)模塊。

    --add-module=build/ngx_stream_lua-0.0.7

    #設(shè)置將會在鏈接(linking)過程中使用的額外參數(shù)。

    --with-ld-opt=-Wl,-rpath,/app/3rd/nginx/openresty/luajit/lib

    #通過一致性哈希算法來選擇合適的后端節(jié)點(diǎn)。

    --add-module=/tmp/open_install/openresty-1.13.6.2/../ngx_http_consistent_hash-master

    #模塊主要用于查看Nginx的一些狀態(tài)信息。

    --with-http_stub_status_module

    # 打開pcre JIT支持,比不使用快好幾倍。

    --with-pcre-jit

    #手頭沒證書,給https做代理時(shí)要用到這個(gè)功能。

    --with-stream_ssl_preread_module

    #在啟用Mail模塊后,單獨(dú)地禁用pop3模塊

    --without-mail_pop3_module

    #在啟用mail模塊后,單獨(dú)地禁用IMAP模塊

    --without-mail_imap_module

    #在啟用mail模塊后,單獨(dú)地禁用smtp模塊

    --without-mail_smtp_module

    #讓nginx支持http/2。

    --with-http_v2_module

    #讓nginx支持https。

    --with-http_ssl_module

    #獲取真實(shí)IP模塊。

    --with-http_realip_module

    #在響應(yīng)之前或者之后追加文本內(nèi)容,比如想在站點(diǎn)底部追加一個(gè)js或者css,可以使用這個(gè)模塊來實(shí)現(xiàn),這個(gè)模塊和淘寶開發(fā)的nginx footer模塊有點(diǎn)類似,但是還是有不同. 這個(gè)模塊需要依賴子請求,nginx footer依賴nginx寫死的配置.

    --with-http_addition_module

    #ngx_http_auth_request_module 第三方認(rèn)證

    # 編譯 Nginx 時(shí)需要添加該模塊 --with-http_auth_request_module

    # 該模塊可以將客戶端輸入的用戶名、密碼 username:password 通過 Base64 編碼后寫入 Request Headers 中

    # 例如:wang:wang -> Authorization:Basic d2FuZzp3YW5n=

    # 然后通過第三方程序解碼后跟數(shù)據(jù)庫中用戶名、密碼進(jìn)行比較,Nginx 服務(wù)器通過 header 的返回狀態(tài)判斷是否認(rèn)證通過。

    --with-http_auth_request_module

    #安全連接,用于防盜鏈。

    #https://juejin.im/post/5bce737551882576e3102733

    --with-http_secure_link_module

    #如果你想提供從一個(gè)目錄中隨機(jī)選擇文件的索引文件,那么這個(gè)模塊需要被激活

    --with-http_random_index_module

    #nginx默認(rèn)安裝ngx_http_gzip_module,采用的是chunked方式的動(dòng)態(tài)壓縮,靜態(tài)壓縮需要使用http_gzip_static_module這個(gè)模塊,進(jìn)行pre-compress。

    #模塊 ngx_http_gzip_static_module 允許發(fā)送以".gz"作為文件擴(kuò)展名的預(yù)壓縮文件,以替代發(fā)送普通文件。需要指定 --with-http_gzip_static_module編譯選項(xiàng):

    --with-http_gzip_static_module

    #該模塊實(shí)現(xiàn)了替代過濾,在響應(yīng)中用一個(gè)字符串替代另一個(gè)字符串

    --with-http_sub_module

    #啟用這個(gè)模塊將激活使用WebDAV的配置指令。注意:這個(gè)模塊也只在有需要使用的基礎(chǔ)上啟用,如果配置不正確,它將帶來安全問題。

    --with-http_dav_module

    #如果需要提供Flash流媒體視頻文件,那么該模塊將會提供偽流媒體

    --with-http_flv_module

    #這個(gè)模塊支持H.264/AAC文件偽流媒體

    --with-http_mp4_module

    #在服務(wù)端發(fā)送數(shù)據(jù)之前進(jìn)行壓縮也很重要。GZip 壓縮就是其中的一種壓縮方式。

    #Nginx 默認(rèn)就能提供上述功能,提供兩個(gè) GZip 壓縮的增強(qiáng)插件:http_gzip_static_module,http_gunzip_module

    --with-http_gunzip_module

    #使用aio threads,需要添加--with-threads配置

    #nginx這樣配置:

    server {              location /one {            aio threads=one;        }        location /two {            aio threads=two;        }    }

    --with-threads

    #指定nginx ssl模塊依賴的ssl庫

    --with-openssl=/opt/openresty/openssl-1.1.0i

    #openresty使用火焰圖排查性能問題時(shí)要用到dtrace。

    #參考文章:https://juejin.im/post/59ce27fef265da065b66d54b

    --with-dtrace-probes

    #把內(nèi)網(wǎng)ip端口映射到外網(wǎng)地址。比如如果你想把云數(shù)據(jù)庫(mysql等)開放外網(wǎng)地址。需要增加編譯參數(shù):--with-stream 與 --with-stream_ssl_module。

    --with-stream

    --with-stream_ssl_module


    (7).相關(guān)閱讀


    nginx-1:生產(chǎn)級別nginx高性能配置

    kubernetes-9:nginx-ingress容器化


    本文為企業(yè)推廣,本網(wǎng)站不做任何建議,僅提供參考,作為信息展示!

    推薦閱讀:葉紫網(wǎng)

    網(wǎng)友評論
    請登錄后進(jìn)行評論| 0條評論

    請文明發(fā)言,還可以輸入140

    您的評論已經(jīng)發(fā)表成功,請等候?qū)徍?/p>

    小提示:您要為您發(fā)表的言論后果負(fù)責(zé),請各位遵守法紀(jì)注意語言文明

    回到首頁 回到頂部
    八方資訊網(wǎng) 關(guān)于我們| 聯(lián)系我們| 招聘信息| 老版地圖| 網(wǎng)站地圖
    免責(zé)聲明:八方資訊網(wǎng)所有文字、圖片、視頻、音頻等資料均來自互聯(lián)網(wǎng),不代表本站贊同其觀點(diǎn),本站亦不為其版權(quán)負(fù)責(zé)。相關(guān)作品的原創(chuàng)性、文中陳述文字以及內(nèi)容數(shù)據(jù)龐雜本站無法一一核實(shí),如果您發(fā)現(xiàn)本網(wǎng)站上有侵犯您的合法權(quán)益的內(nèi)容,請聯(lián)系我們,本網(wǎng)站將立即予以刪除!
    Copyright © 2012-2019 http://m.quan28.cn, All rights reserved.
    主站蜘蛛池模板: 无码欧精品亚洲日韩一区夜夜嗨| 51久久夜色精品国产| 国产精品91视频| 日韩蜜芽精品视频在线观看| 精品国产91久久久久久久 | 狠狠精品干练久久久无码中文字幕| 久久丫精品国产亚洲av不卡| 日本精品一区二区三区四区| 91精品啪在线观看国产电影| 国产精品一级片| 国自产精品手机在线观看视| 精品无码一区二区三区亚洲桃色| 欧美精品黑人粗大视频| 精品国产污污免费网站| 99视频在线观看精品| 亚洲国产精品无码久久98| 精品无人区无码乱码大片国产| 久久线看观看精品香蕉国产| 国产乱人伦偷精品视频AAA| 曰韩精品无码一区二区三区| 久久久久久无码国产精品中文字幕| 99热热久久这里只有精品68| 精品久久一区二区| 8x福利精品第一导航| 国产精品毛片一区二区三区| 久久精品人人做人人爽电影蜜月 | mm1313亚洲国产精品无码试看| 国产韩国精品一区二区三区久久| 久久99精品久久久久久久久久| 亚洲精品V欧洲精品V日韩精品| 亚洲精品tv久久久久久久久久| 欧美日韩成人精品久久久免费看 | 精品久久综合1区2区3区激情| 国产精品爱搞视频网站| 99久久国产综合精品五月天喷水 | 全球AV集中精品导航福利| 亚洲精品无码国产| 久久精品亚洲日本波多野结衣| 精品无码日韩一区二区三区不卡 | 亚洲欧洲国产精品你懂的| 中文字幕亚洲精品|