jboss如何配置redis的session共享
时间: 2023-10-27 08:06:14 浏览: 161
您可以按照以下步骤来配置 Redis 以用于 JBoss 的 Session 共享:
1. 下载 Jedis jar 包并将其添加到 JBoss 的 classpath 中。
2. 在 JBoss 的配置文件 `standalone.xml` 中添加以下配置:
```
<cache-container name="web" default-cache="passivation">
<transport lock-timeout="60000"/>
<distributed-cache name="session-cache" mode="SYNC" statistics-enabled="true">
<persistence passivation="false"/>
<partition-handling when-split="DENY_ACCESS" merge-policy="REMOVE_ALL"/>
<file-store/> <!-- 如果您想使用持久化存储 -->
<remote-store/> <!-- 如果您想使用远程存储 -->
<locking isolation="REPEATABLE_READ"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="1800000"/>
<state-transfer timeout="600000" await-initial-transfer="true" mode="ASYNC" />
</distributed-cache>
</cache-container>
```
3. 配置 JBoss 的 web subsystem,添加以下设置:
```
<subsystem xmlns="urn:jboss:domain:web:3.0" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
<!-- 添加以下设置 -->
<distributable/>
<session-management jvmRoute="jvmRoute" session-cookie="false" session-store="infinispan">
<infinispan>
<cache-container>web</cache-container>
</infinispan>
</session-management>
<!-- 结束 -->
</virtual-server>
</subsystem>
```
4. 修改 `jboss-web.xml` 文件,添加以下配置:
```
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_7_1.xsd">
<context-root>your-context-root</context-root>
<session-config>
<session-store>distributed-cache</session-store>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
</session-config>
</jboss-web>
```
5. 配置 Redis 主机和端口。您可以在 `standalone.xml` 文件中添加以下配置:
```
<subsystem xmlns="urn:jboss:domain:infinispan:12.0" default-cache-container="clustered">
<cache-container name="clustered" default-cache="default">
<transport lock-timeout="60000"/>
<distributed-cache name="default" mode="SYNC" statistics-enabled="true">
<persistence passivation="false"/>
<partition-handling when-split="DENY_ACCESS" merge-policy="REMOVE_ALL"/>
<remote-store>
<connection-pool max-connections-per-node="2"/>
<shared>
<redis-server host="your-redis-host" port="your-redis-port"/> <!-- Redis 主机和端口 -->
<serialization> <!-- 数据序列化 -->
<marshaller class="org.infinispan.commons.marshall.JavaSerializationMarshaller"/>
</serialization>
</shared>
</remote-store>
<locking isolation="REPEATABLE_READ"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="1800000"/>
<state-transfer timeout="600000" await-initial-transfer="true" mode="ASYNC" />
</distributed-cache>
</cache-container>
</subsystem>
```
完成以上所有步骤后,您的 Redis 就可以用于 JBoss 的 Session 共享了。希望能对您有所帮助!
阅读全文