1.經過數據庫實現Session同步
2.經過Cookie實現Session同步
3.經過MEMCACHED等緩存服務器實現Session同步
4.經過Apache的相關組件實現Session同步,好比Tomcat:mod_jk-apache.so,Weblogic:mod_wl_22.so2.會話保持:最爲簡單的方式,一旦請求被分發到A服務器,那麼以後這個會話全部的請求都會保持分發獲得A服務器。
LoadModule headers_module modules/mod_headers.so
<VirtualHost 127.0.0.1:80> Header add Set-Cookie "routeId=.%{BALANCER_WORKER_ROUTE}e;path=/" env=BALANCER_ROUTE_CHANGED ServerAdmin webmaster@dummy-host.example.com ServerName 127.0.0.1 ProxyPreserveHost On ProxyRequests Off <Proxy balancer://democluster> Require all granted BalancerMember http://127.0.0.1:8080/demo route=server1 BalancerMember http://127.0.0.1:8081/demo route=server2 </Proxy> ProxyPass /framework http://127.0.0.1:8080/framework ProxyPassReverse /framework http://127.0.0.1:8080/framework ProxyPass /demo balancer://democluster stickysession=routeId ProxyPassReverse /demo balancer://democluster ErrorLog "logs/test.localhost-error_log" CustomLog "logs/test.localhost-access_log" common </VirtualHost>
Header add Set-Cookie "routeId=.%{BALANCER_WORKER_ROUTE}e;path=/" env=BALANCER_ROUTE_CHANGED在用戶的瀏覽器中設置Cookie,Cookie值KEY是routeId,VALUE是取 %{BALANCER_WORKER_ROUTE} ,對應吉羣配置中的route字段,以下配置:
BalancerMember http://127.0.0.1:8080/demo route=server1而後在設置負載的均衡的規則:
ProxyPass /demo balancer://democluster stickysession=routeId配置完成。打開瀏覽器通過分發以後,瀏覽器的Cookies就會有對應的鍵值