admin管理员组文章数量:1532204
2024年7月19日发(作者:)
基于Nginx的Session-sticky技术的软件负载均衡方案原理和实施步骤
[一]、综述
(1)实现原理:用户请求到nginx,基于nginx的nginx-sticky-module模块的session sticky(会话
粘滞)实现后端应用服务器的路由选择,再将用户请求提交到后端的tomcat/weblogic/websphere
应用处理并逆向反馈响应。
(2)技术选型:
Nginx+ nginx-sticky-module+J2EE中间件(容器)。
(3)应用场景:
本解决方案是基于浏览器的Cookie机制,通过nginx的反向代理机制,将浏览器与后端应用服务器的
访问映射关系,作为前端请求转发到实现某个会话内所有用户的请求都访问当相同的后端服务器。
[二]、安装步骤
创建www用户和组,以及主机需要的目录,日志目录
groupadd www
useradd -g www www
一、依赖的程序
1. gzip module requires zlib library
2. rewrite module requires pcre library
3. ssl support requires openssl library
二、依赖的程序的安装的方法
1、zlib 现在最新的版本是zlib-1.2.5
官网下载地址:/
$tar -xvzf
2、 pcre现在的最新版本是
官网下载地址:ftp:///pub/software/programming/pcre/pcre-
$tar -xvzf
$cd pcre-8.02
$./configure --prefix=/usr/local/pcre --enable-utf8 --enable-unicode-properties
$ make && make install
3、openssl现在最新版本是
官网下载地址:/source/
$tar zvxf
$cd openssl-1.0.0
$./config --prefix=/usr/local/ssl-1.0.0 shared zlib-dynamic enable-camellia
$make && make install
4、安装Nginx 1.0.0,这种方法./configure 要带很多参数,大家要注意。
官网下载地址:/
$tar zvxf Nginx
$cd Nginx 1.0.0
$./configure --prefix=/usr/local/nginx --with-http_gzip_static_module
--with-http_stub_status_module --with-http_realip_module
--with-zlib=/usr/local/src/zlib
--with-pcre=/usr/
local
/src/pcre
--add-module
=/usr/local/src/nginx-sticky-module
特别注意:pcre和zlib不需要安装,nginx会直接采用源代码的方式进行configure配置。
$ make
$ make install
编译和安装成功。
四、会话保持配置
(1)实现原理:
官方下载:
/p/nginx-sticky-module/
建议版本:nginx-sticky-module-1.1
安装方式:
安装nginx时, ./configure附加--add-module=/usr/local/src/nginx-sticky-module
(2)关键配置参数:
sticky [name=cookieName] [domain=.] [path=/] [expires=1h]
[hash=index|md5|sha1];
- name: the name of the cookies used to track the persistant upstream srv
default: route
- domain: the domain in which the cookie will be valid
default: nothing. Let the browser handle this.
- path: the path in which the cookie will be valid
default: nothing. Let the browser handle this.
- expires: the validity duration of the cookie
refault: nothing. It's a session cookie.
restriction: must be a duration greater than one second
- hash: the hash mechanism to encode upstream server. It can't be used
with hmac.
md5|sha1: well known hash
index: it's not hashed, an in-memory index is used instead
it's quicker and the overhead is shorter
版权声明:本文标题:基于Nginx的Session-sticky技术的软件负载均衡方案原理和实施步骤v1.0 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1721362030a873822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论