> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://close.gitbook.io/yun-wei-bi-ji/centos/tomcat/tomcat-8.x-ji-yu-redis-session-hui-hua-bao-chi.md).

# Tomcat 8.x基于Redis Session会话保持

### Tomcat 8.x基于Redis Session会话保持

**tomcat配置共享session几种方式**

1、利用tomcat自身集群特性进行配置； 2、利用Memcache第三方缓存进行配置； 3、利用Redis第三方缓存进行配置；

```bash
wget -c https://mirrors.yangxingzhen.com/tomcat_redis_seession/tomcat8-redis-seseion.tar.gz
tar zxf tomcat8-redis-seseion.tar.gz
mv tomcat8-redis-session/*.jar /usr/local/tomcat/lib

# 修改tomcat下的context.xml文件
<!-- Redis session共享配置 -->
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
host="192.168.31.66"
port="6379"
database="1"
maxInactiveInterval="60"
/>

注意：将host改成 线上redis地址，port是对应的端口，database 尽量选一个目前没有的redis库（方便测试）
```

**在tomcat发布目录下创建index.jsp文件,重启Tomcat服务**

```bash
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>获取session id</title>
</head>
<body>
Session Id : <%= request.getSession().getId() %>
</body>
</html>
```
