nginx编译安装_Nginx编译安装nginx-upsync-module模块以实现动态负载
安裝依賴包
OpenSSL
在官網下載頁下到最新穩定版1.0.2q。
PCRE
在 PCRE 官網可以找到下載地址,這里選擇8.x的最高版本 pcre-8.42.tar.gz。
zlib
zlib 直接選擇官網首頁最新的zlib-1.2.11.tar.gz。
下載nginx 源碼包及nginx-upsync-module模塊源碼
這里下載的是nginx穩定版nginx-1.14.2.tar.gz,nginx-upsync-module模塊源碼使用git clone https://github.com/weibocom/nginx-upsync-module.git下載。解壓之后進入源碼目錄執行
./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可以看到全部的參數,下面是一些常用配置參數的含義:
--prefix #nginx安裝目錄,默認在/usr/local/nginx--pid-path #pid問件位置,默認在logs目錄--lock-path #lock問件位置,默認在logs目錄--with-http_ssl_module #開啟HTTP SSL模塊,以支持HTTPS請求。--with-http_dav_module #開啟WebDAV擴展動作模塊,可為文件和目錄指定權限--with-http_flv_module #支持對FLV文件的拖動播放--with-http_realip_module #支持顯示真實來源IP地址--with-http_gzip_static_module #預壓縮文件傳前檢查,防止文件被重復壓縮--with-http_stub_status_module #取得一些nginx的運行狀態--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 #允許調試日志--http-client-body-temp-path #客戶端請求臨時文件路徑--http-proxy-temp-path #設置http proxy臨時文件路徑--http-fastcgi-temp-path #設置http fastcgi臨時文件路徑--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #設置uwsgi 臨時文件路徑--http-scgi-temp-path=/var/tmp/nginx/scgi #設置scgi 臨時文件路徑:在make的時候報錯
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這個是因為我先前裝了別的版本的openssl導致的,查看Nginx源碼目錄文件auto/lib/openssl/conf,可以發現代碼:
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"實際的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"執行make clean 之后重新執行上面的./configure ....,這時報錯
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=,改完之后千萬不要執行./configure ....,否則會重新生成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再次執行
makemake install如果還報上面的錯誤,可以嘗試手動執行下面的命令之后再執行上面的命令
./Configure darwin64-x86_64-cc --prefix=/work/tools/openssl-1.0.2q/.openssl no-shared no-threads sudo makesudo make install有時候報類似symbol(s) not found 有可能是權限不夠導致的,可以嘗試加sudo執行命令。這時啟動nginx已經可以啟動了。
配置
本文以Consul作為注冊中心,關于Consul的知識將不再介紹。進入配置文件目錄創建一個目錄servers以放將來添加的配置文件,修改配置文件nginx.conf添加include servers/*.conf; ,進入servers創建一個空文件upsync-test-tmp.conf作為upsync的緩存文件,再創建配置文件 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 ;是為了占位,防止啟動nginx報錯。接下來向注冊中心注冊服務
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接下來啟動nginx,再請求服務發現已經起作用了。
再下掉這個服務看看是否生效
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再上線這個服務
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測試已經沒有問題。
總結
以上是生活随笔為你收集整理的nginx编译安装_Nginx编译安装nginx-upsync-module模块以实现动态负载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中cmd是什么_python
- 下一篇: 微信小程序装修解决方案ppt_装修公司微