In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
How to analyze and use the source code of tengine session_sticky_module module, in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Preface
In the past, nginx did not maintain good support for session, mainly using ip_hash to fix customers from the same source (IP in the same C segment) to the same machine at the back end. Ip_hash has a disadvantage that it cannot achieve good load balancing until the emergence of nginx-sticky-module, the extension module of nginx, solves the problem of session sticky.
Personally, I felt that tengine's session sticky module was better, so I migrated tengine's sticky to nginx.
Temgine session_sticky_module module is a load balancing module, which realizes the session persistence between the client and the back-end server through cookie. Under certain conditions, it can ensure that the same client accesses the same back-end server.
Basic parameters:
Cookie sets the cookie name used to record the session
Domain sets the domain name of cookie. It is not set by default.
Path sets the URL path for cookie. It is not set by default.
Maxage sets the lifetime of cookie. If it is not set by default, it will be session cookie. If the browser is closed, it will become invalid.
Mode sets the mode of cookie:
Insert: in the reply, this module directly inserts the cookie with the corresponding name through the Set-Cookie header
Rewrite: the cookie for session sticky set by the backend is overridden with the server identity. If the cookie is not set by the back-end service in the response header, it is considered that the request does not require session sticky. Using this mode, the back-end service can control which requests require sesstion sticky and which do not.
Option sets the option for cookie for session sticky, which can be set to indirect or direct. Indirect does not transmit the cookie of the session sticky to the backend service, which is completely transparent to the backend application. Direct is the opposite of indirect.
Maxidle sets the maximum idle timeout for session cookie
Maxlife sets the maximum lifetime of session cookie
Fallback sets whether to retry other machines, and whether it is necessary to try other machines when the back-end machines of sticky hang up.
Hash sets whether to use clear text or MD5 value for server identification in cookie. Default is md5.
Currently, the console only supports two modes, insert and rewrite.
In both modes, the other configurations are the same.
In insert mode, the value of cookie is completely managed by lb without going through the backend. Each backend rs generates a unique id value, plus the values of maxidle and maxlife. it is separated by a separator and used as the value of cookie for session persistence. This condition requires the cooperation of option=indirect and session_sticky_hide_cookie.
In rewrite mode, nothing changes except mode, and the value of cookie is determined by whether the backend rs is set or not.
Supplement to session_sticky format
On the first request, because the request does not have a rs value, or because the cookie value itself is incorrect, it triggers the first selection of cookie and returns the cookie value through response
Curl-v 127.0.0.3
* About to connect () to 127.0.0.3 port 978
* Trying 127.0.0.3. Connected
Connected to 127.0.0.3 (127.0.0.3) port 978 (# 0)
> GET / HTTP/1.1
> User-Agent: kcurl/1.0 (curl 7.19.7) (x86_64-unknown-linux-gnu) libcurl/7.19.7 OpenSSL/1.0.1e zlib/1.2.3
> Host: 127.0.0.3
> Accept: * / *
>
< HTTP/1.1 200 OK < Server: Tengine/2.3.0 < Date: Sun, 28 Apr 2019 10:24:01 GMT < Content-Type: text/plain < Content-Length: 3 < Connection: keep-alive < Set-Cookie: LBSID=d349ca31adc862f4d7e6faa19e516d6d|1556447041|1556447041; Path=/ GET / HTTP/1.1 >User-Agent: kcurl/1.0 (curl 7.19.7) (x86_64-unknown-linux-gnu) libcurl/7.19.7 OpenSSL/1.0.1e zlib/1.2.3
> Host: 127.0.0.3
> Accept: * / *
> Cookie: LBSID=d349ca31adc862f4d7e6faa19e516d6d | 1556447041 | 1556447041; Path=/
>
< HTTP/1.1 200 OK < Server: Tengine/2.3.0 < Date: Sun, 28 Apr 2019 10:30:13 GMT < Content-Type: text/plain < Content-Length: 3 < Connection: keep-alive < Set-Cookie: LBSID=d349ca31adc862f4d7e6faa19e516d6d|1556447413|1556447041; Path=/ GET /ok HTTP/1.1 >User-Agent: curl/7.29.0
> Host: 10.10.117.238
> Accept: * / *
>
< HTTP/1.1 200 OK < Server: LB 1.0.0 < Date: Thu, 17 Oct 2019 07:26:09 GMT < Content-Type: application/octet-stream < Content-Length: 2 < Connection: keep-alive < Set-Cookie: LBSID=10.0.23.20:80|1571367|1572197167; Path=/ GET /ok HTTP/1.1 >User-Agent: curl/7.29.0
> Host: 10.10.117.238
> Accept: * / *
> Cookie: LBSID=10.0.23.20:80 | 15734169 | 1571297217; Path=/
>
< HTTP/1.1 200 OK < Server: LB 1.0.0 < Date: Thu, 17 Oct 2019 07:26:38 GMT < Content-Type: application/octet-stream < Content-Length: 2 < Connection: keep-alive < Set-Cookie: LBSID=10.0.23.20:80|15734169|1571297217; Path=/ GET /ok HTTP/1.1 >User-Agent: curl/7.29.0
> Host: 10.10.117.238
> Accept: * / *
> Cookie: LBSID=10.0.23.20:80 | 1571297198 | 1571297217; Path=/
>
< HTTP/1.1 200 OK
< Server: LB 1.0.0
< Date: Thu, 17 Oct 2019 07:27:47 GMT
< Content-Type: application/octet-stream
< Content-Length: 2
< Connection: keep-alive
< Set-Cookie: LBSID=10.0.23.6:80 | 1571297198 | 1571297217; Path=/
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.