Linux成长库

nginx+tomcat+redis实现负载均衡以及sessio

2018-06-07  本文已影响0人  泡菜爱上WaSabi
vim nginx.conf
http {

upstream test {  
    server 192.168.1.157:8080 max_fails=1 fail_timeout=5s;  
    server 192.168.1.156:8080 max_fails=1 fail_timeout=5s;  
}  

}

修改nginx.conf的location上下文

server {
   location / {
     root   html;  
     index  index.html index.htm;  
     proxy_pass http://test;  
  }
}
<Context>  
    <!-- Default set of monitored resources -->  
    <WatchedResource>WEB-INF/web.xml</WatchedResource>  
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->  
    <!-- 
    <Manager pathname="" /> 
    -->  
    <!-- Uncomment this to enable Comet connection tacking (provides events  
         on session expiration as well as webapp lifecycle) -->  
    <!-- 
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> 
    -->  
  <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />  
  <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"  
   host="192.168.1.100"  
   port="6379"  
   database="0"  
   maxInactiveInterval="60" />  
</Context>  
[root@localhost text]# vim index.jsp 

<%@ page language="java" %>
<html>
  <head><title>TomcatA</title></head>
  <body>
  <h1 style="color: red;">TomcatA</h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body>
</html>
sessionID:<%=session.getId()%>
<br>
SessionIP:<%=request.getServerName()%>
<br>
SessionPort:<%=request.getServerPort()%>
<%
//为了区分,第二个可以是B  
out.println("This is Tomcat Server A");
%>
上一篇 下一篇

猜你喜欢

热点阅读