Mac为nginx安装nginx-sticky-module

夹谷浩宕
2023-12-01

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'   

结束

转载于:https://www.cnblogs.com/richaaaard/p/5041178.html

 类似资料: