jboss7.2如何配置redis的session共享
时间: 2023-10-27 18:06:12 浏览: 164
您可以按照以下步骤进行配置:
1. 下载Redis客户端 jar 包,并将其添加到 JBoss 7.2 的lib目录下。
2. 在文件 $JBOSS_HOME/standalone/configuration/standalone.xml 中添加以下代码:
```xml
<subsystem xmlns="urn:jboss:domain:web:1.1" 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">
<session-cookie http-only="true"/>
<session-config>
<session-manager>
<persistent-sessions>
<redis-store name="redis-session-store" database="0" host="localhost" port="6379"/>
</persistent-sessions>
</session-manager>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</virtual-server>
</subsystem>
```
3. 在 ${JBOSS_HOME}/modules/system/layers/base/org/jboss/as/clustering/web/infinispan/web module 中,创建 module.xml 文件,并在其中添加以下代码:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.jboss.as.clustering.web.infinispan.redisstore">
<dependencies>
<module name="org.jboss.as.clustering.web.infinispan"/>
<module name="org.infinispan"/>
<module name="redis.clients"/>
</dependencies>
<resources>
<resource-root path="redis-store-1.0.0-SNAPSHOT.jar"/>
</resources>
</module>
```
4. 在 ${JBOSS_HOME}/standalone/deployments/jboss-web.deployer/server.xml 文件中,添加以下代码:
```xml
<Engine name="jboss.web" defaultHost="localhost">
<Host name="localhost" autoDeploy="false" deployOnStartup="false">
<Cluster className="org.jboss.ha.framework.server.HAPartition"
partitionName="web"
multicastAddr="228.1.2.3"
multicastPort="45566"
bindAddr="127.0.0.1"
logFactoryClassName="org.jboss.logging.Log4jLoggerFactory"
ucastAddr="127.0.0.1"
ucastPort="45567"
ignoreTTL="true"
channel="clustered-web">
<Receiver className="org.jboss.ha.framework.internal.ReceiveThread"/>
<Interceptor className="org.jboss.ha.framework.server.ClusterFileTransfer"/>
<Interceptor className="org.jboss.ha.framework.server.DistributedReplicantManager"/>
<Interceptor className="org.jboss.ha.framework.interfaces.HAPartition.ShunInterceptor"/>
<Interceptor className="org.jboss.ha.jmx.HATarget"/>
<Interceptor className="org.jboss.ha.framework.server.ClusterPartition"/>
</Cluster>
<Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
cacheConnection="true"
cacheMaxSize="100"
cacheMinSize="5"
cacheStrategy="LRU"
lazyInit="true"
flushOnClose="true"/>
<Manager
distributable="true"
expireSessionsOnShutdown="false"
name="redis-session-store"
sessionIdLength="20"
sessionIdGeneratorClassName="org.jboss.web.tomcat.service.session.JvmRouteSessionIDGenerator"
redisUri="redis://localhost:6379"
storeMode="REDIS_STORE"
concurrentAccessTimeout="10000"
useJK="false"/>
</Host>
</Engine>
```
5. 启动 JBoss 服务器,并测试配置是否成功。
阅读全文