Mac為nginx安裝nginx-sticky-module

Richaaaard發表於2015-12-12

Mac為nginx安裝nginx-sticky-module


nginx版本: nginx-1.9.8

nginx-sticky-module版本:nginx-sticky-module-ng

*注意產品環境請慎用!

參考來源:

Nginx模組之SessionSticky

bitbucket.org

使用nginx sticky模組實現基於cookie的負載均衡

NGINX 3rd Party Modules

下載

很多網站介紹sticky_module的來源和版本都不太一樣,我嘗試了下面來自於github上從google搬過去的1.0版本,和bitbucket.org的ng版本

https://github.com/lusis/nginx-sticky-module

.

https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng

.
當然還有google版本

http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz

目前共有2個版本,一個是1.0,一個是1.1,1.0已經壽終正寢了。1.1增加了權重的引數。

安裝

先嚐試github上clone的版本

* make 的時候會出現錯誤,可能是由於和我自己當前的nginx版本太高相關:
/Users/Richard/Documents/Dev/github/nginx-sticky-module/ngx_http_sticky_module.c:335:21: error:
  incompatible integer to pointer conversion assigning to
  'ngx_http_upstream_rr_peer_t *' (aka 'struct ngx_http_upstream_rr_peer_s
  *') from 'int' [-Werror,-Wint-conversion]
            iphp->rrp.current = iphp->selected_peer;
                              ^ ~~~~~~~~~~~~~~~~~~~
/Users/Richard/Documents/Dev/github/nginx-sticky-module/ngx_http_sticky_module.c:342:19: error:
  variable 'n' may be uninitialized when used here
  [-Werror,-Wconditional-uninitialized]
            iphp->rrp.tried[n] |= m;
                            ^
/Users/Richard/Documents/Dev/github/nginx-sticky-module/ngx_http_sticky_module.c:267:33: note:
  initialize the variable 'n' to silence this warning
    ngx_uint_t                    n, i;
                                   ^
                                    = 0
/Users/Richard/Documents/Dev/github/nginx-sticky-module/ngx_http_sticky_module.c:342:25: error:
  variable 'm' may be uninitialized when used here
  [-Werror,-Wconditional-uninitialized]
            iphp->rrp.tried[n] |= m;
                                  ^
/Users/Richard/Documents/Dev/github/nginx-sticky-module/ngx_http_sticky_module.c:266:33: note:
  initialize the variable 'm' to silence this warning
    uintptr_t                     m;
                                   ^
                                    = 0
3 errors generated.
make[1]: *** [objs/addon/nginx-sticky-module/ngx_http_sticky_module.o] Error 1
make: *** [build] Error 2  

再嘗試nginx.com上推薦的bitbucket.org版本

先clone

$ git clone https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng.git

./configure將目標路徑指向當前的nginx例項

$ ./configure --prefix=/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a --add-module=/Users/Richard/Documents/Dev/github/nginx-sticky-module-ng    

然後make && sudo make install

一切正常

...

test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'        || mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'
test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs' ||         mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'
test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/html'        || cp -R html '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a'
test -d '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs' ||         mkdir -p '/Users/Richard/Documents/Dev/servers/cluster/nginx/node-a/logs'   

結束

相關文章