日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

nginx编译安装_Nginx编译安装nginx-upsync-module模块以实现动态负载

發(fā)布時(shí)間:2024/7/5 Nginx 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx编译安装_Nginx编译安装nginx-upsync-module模块以实现动态负载 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

安裝依賴包

OpenSSL

在官網(wǎng)下載頁下到最新穩(wěn)定版1.0.2q。

PCRE

在 PCRE 官網(wǎng)可以找到下載地址,這里選擇8.x的最高版本 pcre-8.42.tar.gz。

zlib

zlib 直接選擇官網(wǎng)首頁最新的zlib-1.2.11.tar.gz。

下載nginx 源碼包及nginx-upsync-module模塊源碼

這里下載的是nginx穩(wěn)定版nginx-1.14.2.tar.gz,nginx-upsync-module模塊源碼使用git clone https://github.com/weibocom/nginx-upsync-module.git下載。解壓之后進(jìn)入源碼目錄執(zhí)行

./configure --sbin-path=/usr/local/opt/nginx --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/opt/nginx/nginx.pid --prefix=/usr/local/opt/nginx --with-http_ssl_module --add-module=/work/tools/nginx-modules/nginx-upsync-module --with-openssl=/work/tools/openssl-1.0.2q --with-pcre=/work/tools/pcre-8.42 --with-zlib=/work/tools/zlib-1.2.11makemake install

查看文件auto/options可以看到全部的參數(shù),下面是一些常用配置參數(shù)的含義:

--prefix #nginx安裝目錄,默認(rèn)在/usr/local/nginx--pid-path #pid問件位置,默認(rèn)在logs目錄--lock-path #lock問件位置,默認(rèn)在logs目錄--with-http_ssl_module #開啟HTTP SSL模塊,以支持HTTPS請(qǐng)求。--with-http_dav_module #開啟WebDAV擴(kuò)展動(dòng)作模塊,可為文件和目錄指定權(quán)限--with-http_flv_module #支持對(duì)FLV文件的拖動(dòng)播放--with-http_realip_module #支持顯示真實(shí)來源IP地址--with-http_gzip_static_module #預(yù)壓縮文件傳前檢查,防止文件被重復(fù)壓縮--with-http_stub_status_module #取得一些nginx的運(yùn)行狀態(tài)--with-mail #允許POP3/IMAP4/SMTP代理模塊--with-mail_ssl_module #允許POP3/IMAP/SMTP可以使用SSL/TLS--with-pcre=../pcre-8.11 #注意是未安裝的pcre路徑--with-zlib=../zlib-1.2.5 #注意是未安裝的zlib路徑--with-debug #允許調(diào)試日志--http-client-body-temp-path #客戶端請(qǐng)求臨時(shí)文件路徑--http-proxy-temp-path #設(shè)置http proxy臨時(shí)文件路徑--http-fastcgi-temp-path #設(shè)置http fastcgi臨時(shí)文件路徑--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #設(shè)置uwsgi 臨時(shí)文件路徑--http-scgi-temp-path=/var/tmp/nginx/scgi #設(shè)置scgi 臨時(shí)文件路徑:

在make的時(shí)候報(bào)錯(cuò)

ld: symbol(s) not found for architecture i386clang: error: linker command failed with exit code 1 (use -v to see invocation)make[4]: *** [link_app.] Error 1make[3]: *** [openssl] Error 2make[2]: *** [build_apps] Error 1make[1]: *** [/user/local/openssl-1.0.2q/.openssl/include/openssl/ssl.h] Error 2make: *** [build] Error 2

這個(gè)是因?yàn)槲蚁惹把b了別的版本的openssl導(dǎo)致的,查看Nginx源碼目錄文件auto/lib/openssl/conf,可以發(fā)現(xiàn)代碼:

CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"

實(shí)際的openssl源碼目錄是沒有.openssl目錄的,ssl.h文件是在openssl源碼目錄的include/openssl/目錄下的,libssl.a 和libcrypto.a是在openssl源碼根目錄下的。將此文件修改為:

CORE_INCS="$CORE_INCS $OPENSSL/include"CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"CORE_LIBS="$CORE_LIBS $OPENSSL/libssl.a"CORE_LIBS="$CORE_LIBS $OPENSSL/libcrypto.a"

執(zhí)行make clean 之后重新執(zhí)行上面的./configure ....,這時(shí)報(bào)錯(cuò)

ld: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)make[1]: *** [objs/nginx] Error 1make: *** [build] Error 2

查了一下,看到好多人的解決方式都是修改objs/Makefile文件,找到編譯openssl的地方,將./config --prefix= 改成./Configure darwin64-x86_64-cc --prefix=,改完之后千萬不要執(zhí)行./configure ....,否則會(huì)重新生成objs/Makefile文件,最終如下

/work/tools/openssl-1.0.2q/.openssl/include/openssl/ssl.h: objs/Makefile cd /work/tools/openssl-1.0.2q && if [ -f Makefile ]; then $(MAKE) clean; fi && ./Configure darwin64-x86_64-cc --prefix=/work/tools/openssl-1.0.2q/.openssl no-shared no-threads && $(MAKE) && $(MAKE) install_sw LIBDIR=lib

再次執(zhí)行

makemake install

如果還報(bào)上面的錯(cuò)誤,可以嘗試手動(dòng)執(zhí)行下面的命令之后再執(zhí)行上面的命令

./Configure darwin64-x86_64-cc --prefix=/work/tools/openssl-1.0.2q/.openssl no-shared no-threads sudo makesudo make install

有時(shí)候報(bào)類似symbol(s) not found 有可能是權(quán)限不夠?qū)е碌?#xff0c;可以嘗試加sudo執(zhí)行命令。這時(shí)啟動(dòng)nginx已經(jīng)可以啟動(dòng)了。

配置

本文以Consul作為注冊(cè)中心,關(guān)于Consul的知識(shí)將不再介紹。進(jìn)入配置文件目錄創(chuàng)建一個(gè)目錄servers以放將來添加的配置文件,修改配置文件nginx.conf添加include servers/*.conf; ,進(jìn)入servers創(chuàng)建一個(gè)空文件upsync-test-tmp.conf作為upsync的緩存文件,再創(chuàng)建配置文件 test-upsync.conf

upstream testupsync { upsync 127.0.0.1:8500/v1/kv/upstreams/testupsync/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/etc/nginx2/servers/upsync-test-tmp.conf; include /usr/local/etc/nginx2/servers/upsync-test-tmp.conf; server 127.0.0.1:11111 down ;}server { listen 8000; server_name localhost; location / { proxy_pass http://testupsync; } location = /upstream_show { upstream_show; }}

server 127.0.0.1:11111 down ;是為了占位,防止啟動(dòng)nginx報(bào)錯(cuò)。接下來向注冊(cè)中心注冊(cè)服務(wù)

curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10 }' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002curl -s http://127.0.0.1:8500/v1/kv/upstreams/testupsync?recurse

接下來啟動(dòng)nginx,再請(qǐng)求服務(wù)發(fā)現(xiàn)已經(jīng)起作用了。

再下掉這個(gè)服務(wù)看看是否生效

curl -X?PUT?-d '{"weight":2,?"max_fails":2,?"fail_timeout":10,"down":1}' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002

再上線這個(gè)服務(wù)

curl -X?PUT?-d '{"weight":2,?"max_fails":2,?"fail_timeout":10,"down":0}' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002

測(cè)試已經(jīng)沒有問題。

總結(jié)

以上是生活随笔為你收集整理的nginx编译安装_Nginx编译安装nginx-upsync-module模块以实现动态负载的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。