Mac为nginx安装nginx-sticky-module

本文介绍了在Mac环境下为nginx安装nginx-sticky-module的过程。针对不同的版本进行了尝试,并详细记录了遇到的问题及解决方法,最终成功安装并配置了基于cookie的负载均衡。

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'   

结束

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值