1.配置站点
每个web节点都配
[root@web01 ~]# vim /soft/tomcat/conf/server.xml
...
<!--站点session.yang.com-->
<Host name="session.yang.com" appBase="/session"
unpackWARs="true" autoDeploy="true">
</Host>
...
2.接入负载
[root@lb01 conf.d]# cat /etc/nginx/conf.d/proxy_session.yang.com.conf
upstream session {
server 172.16.1.7:8080;
server 172.16.1.8:8080;
}
server {
listen 80;
server_name session.yang.com;
location / {
proxy_pass http://session;
include proxy_params;
}
}
3.测试(每个web节点都配一下)
[root@web01 ~]# mkdir -p /session/ROOT
[root@web01 ~]# vi /session/ROOT/index.jsp
<body>
<%
//HttpSession session = request.getSession(true);
System.out.println(session.getCreationTime());
out.println("<br> web01 SESSION ID:" + session.getId() + "<br>");
out.println("Session created time is :" + session.getCreationTime()
+ "<br>");
%>
</body>
4.支持Redis、session共享
1.拷贝所有的jar包
[root@web01 ~]# cp tomcat-cluster-redis-session-manager/lib/* /soft/tomcat/lib/
2.拷贝redis配置文件,并且更新redis配置文件
[root@web01 ~]# cp tomcat-cluster-redis-session-manager/conf/redis-data-cache.properties /soft/tomcat/conf/
3.更新修改
[root@web01 ~]# vim /soft/tomcat/conf/redis-data-cache.properties
4.Add the below two lines in your tomcat/conf/context.xml file.
<Valve className="tomcat.request.session.redis.SessionHandlerValve" />
<Manager className="tomcat.request.session.redis.SessionManager" />