nginx-sticky-module-1.1 的 ip_hash 的替换方式

本文提供了一个详细的指南,涵盖了从编译安装gcc开始,直至完成Nginx的配置,实现负载均衡功能的过程。包括安装依赖包、编译与安装Nginx、安装特定模块、配置文件编写、以及如何使用Nginx进行负载均衡等步骤。
官方的原理图

官方的链接
https://code.google.com/p/nginx-sticky-module/

1.因为编译安装,所以需要安装gcc 

yum install gcc-c++
yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel

2.我的服务器上面
3.下一步安装 nginx,注意nginx的版本,我的版本是1.4.7, 最新版本1.6.0好像有问题,外国网站有解决方式,可能自己找啦

wget http://nginx.org/download/nginx-1.4.7.tar.gz

4.我的当前目录为/usr/local 
5.执行如下命令 

tar -zxvf nginx-1.4.7.tar.gz
rm -rf nginx-1.4.7.tar.gz
mv nginx-1.4.7 nginx

6.接下来下载 nginx-sticky-module-1.1.tar.gz 

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

对nginx-sticky-module模块不懂的话,可以去它的官网 

https://code.google.com/p/nginx-sticky-module/wiki/Documentation

7. 接下来到cd nginx目录里面,执行如下命令

./configure --with-http_stub_status_module  --conf-path=/usr/local/nginx/nginx.conf  --with-http_ssl_module --with-http_realip_module --add-module=../nginx-sticky-module-1.1

8.接下来执行   

make&&make install

9.nginx的 启动

/usr/local/nginx/sbin/nginx

10.nginx的重启 

/usr/local/nginx/sbin/nginx -s reload

11.nginx的关闭 

#查询nginx主进程号 
ps -ef | grep nginx
#停止进程 
kill -quit 主进程号 
#快速停止 
kill -term 主进程号 
#强制停止 
pkill -9 nginx
12.nginx的配置文件
upstream  tomcat_cluster{
              sticky;
              server   192.168.1.167:8080;
              server   192.168.1.167:8081;
    }
  server {
    listen 80;
    server_name 192.168.1.167;
    server_name_in_redirect off;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  
    location  / {
      proxy_pass http://tomcat_cluster; #转向tomcat处理
    }

    location ~ \.(jsp|do|action)$ { #所有jsp页面以及do/action请求均交由tomcat处理
      proxy_pass http://tomcat_cluster; #转向tomcat处理
    }

   location ~ \.(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf)$ {
            root  /home/leiwente/webapp/ROOT;
            expires      1h;
       }
   }

13.浏览器cookie查看,可以看到在集群环境下面都在同一台服务器上面




转载于:https://my.oschina.net/skyim/blog/267787

/opt/nginx-sticky-module/ngx_http_sticky_misc.c: 在函数‘ngx_http_sticky_misc_sha1’中: /opt/nginx-sticky-module/ngx_http_sticky_misc.c:176:15: 错误:‘SHA_DIGEST_LENGTH’未声明(在此函数内第一次使用) u_char hash[SHA_DIGEST_LENGTH]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c:176:15: 附注:每个未声明的标识符在其出现的函数内只报告一次 /opt/nginx-sticky-module/ngx_http_sticky_misc.c:176:10: 错误:未使用的变量‘hash’ [-Werror=unused-variable] u_char hash[SHA_DIGEST_LENGTH]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c: 在函数‘ngx_http_sticky_misc_hmac_sha1’中: /opt/nginx-sticky-module/ngx_http_sticky_misc.c:242:15: 错误:‘SHA_DIGEST_LENGTH’未声明(在此函数内第一次使用) u_char hash[SHA_DIGEST_LENGTH]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c:243:12: 错误:‘SHA_CBLOCK’未声明(在此函数内第一次使用) u_char k[SHA_CBLOCK]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c:243:10: 错误:未使用的变量‘k’ [-Werror=unused-variable] u_char k[SHA_CBLOCK]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c:242:10: 错误:未使用的变量‘hash’ [-Werror=unused-variable] u_char hash[SHA_DIGEST_LENGTH]; ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c: 在函数‘ngx_http_sticky_misc_text_raw’中: /opt/nginx-sticky-module/ngx_http_sticky_misc.c:324:5: 错误:传递‘ngx_sock_ntop’的第 1 个参数时将整数赋给指针,未作类型转换 [-Werror] digest->len = ngx_sock_ntop(1); ^ In file included from src/core/ngx_core.h:82:0, from /opt/nginx-sticky-module/ngx_http_sticky_misc.c:8: src/core/ngx_inet.h:114:8: 附注:需要类型‘struct sockaddr *’,但实参的类型为‘int’ size_t ngx_sock_ntop(struct sockaddr *sa, socklen_t socklen, u_char *text, ^ /opt/nginx-sticky-module/ngx_http_sticky_misc.c:324:5: 错误:提供给函数‘ngx_sock_ntop’的实参太少 digest->len = ngx_sock_ntop(1); ^
最新发布
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值