我们正在两个Docker容器中运行Keycloak (v4.4,独立模式)。我们希望这些容器是无状态的,因此我们必须将所有缓存的数据保存到备份存储中(数据库或其他缓存解决方案,如Redis)。我们不能允许缓存的数据只存在于内存中,因为任何一个容器都可能在任何时候被销毁。
理想情况下,我们希望将缓存的数据持久化到自己的Redis实例。由于Keycloak使用Infinispan,这似乎是将Infinispan配置为使用Redis:http://infinispan.org/docs/cachestores/redis/的方法。
天真地,我试图通过更新我的standalone-4.4.0.xml文件使其看起来如下(请注意第5行中的redis-store元素),从而在Redis中使用Keycloak存储会话信息:
<subsystem xmlns="urn:jboss:domain:infinispan:6.0">
<cache-container name="keycloak">
<local-cache name="sessions">
<persistence passivation="false">
<redis-store xmlns="urn:infinispan:config:store:redis:8.0"
topology="server" socket-timeout="10000" connection-timeout="10000">
<redis-server host="server1" />
<connection-pool min-idle="6" max-idle="10" max-total="20" min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
</redis-store>
</persistence>
</local-cache>
<local-cache name="realms">
<object-memory size="10000"/>
</local-cache>
<local-cache name="users">
<object-memory size="10000"/>
</local-cache>
<local-cache name="authenticationSessions"/>
<local-cache name="offlineSessions"/>
<local-cache name="clientSessions"/>
<local-cache name="offlineClientSessions"/>
<local-cache name="loginFailures"/>
<local-cache name="work"/>
<local-cache name="authorization">
<object-memory size="10000"/>
</local-cache>
<local-cache name="keys">
<object-memory size="1000"/>
<expiration max-idle="3600000"/>
</local-cache>
<local-cache name="actionTokens">
<object-memory size="-1"/>
<expiration max-idle="-1" interval="300000"/>
</local-cache>
</cache-container>
<cache-container name="server" default-cache="default" module="org.wildfly.clustering.server">
<local-cache name="default">
<transaction mode="BATCH"/>
</local-cache>
</cache-container>
<cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
<local-cache name="passivation">
<redis-store xmlns="urn:infinispan:config:store:redis:8.0"
topology="server" socket-timeout="10000" connection-timeout="10000">
<redis-server host="server1" />
<connection-pool min-idle="6" max-idle="10" max-total="20" min-evictable-idle-time="30000" time-between-eviction-runs="30000" />
</redis-store>
</persistence>
</local-cache>
</cache-container>
<cache-container name="ejb" aliases="sfsb" default-cache="passivation" module="org.wildfly.clustering.ejb.infinispan">
<local-cache name="passivation">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
<file-store passivation="true" purge="false"/>
</local-cache>
</cache-container>
<cache-container name="hibernate" module="org.infinispan.hibernate-cache">
<local-cache name="entity">
<transaction mode="NON_XA"/>
<object-memory size="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="local-query">
<object-memory size="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="timestamps"/>
</cache-container>
</subsystem>但是,当我启动Keycloak时,我会得到以下错误:
'persistence' isn't an allowed element here。
问题:是否有一种简单的方法来配置密钥披风以将缓存的数据保存在Redis或其他持久数据存储中?
发布于 2019-08-05 16:08:20
子系统版本urn:jboss:domain:infinispan:6.0不知道xml的这个模式,所以您必须更新这个子系统,或者如果您使用了最新的Keycloak映像(6.0.1),也许只需要实现一个新的InfinispanConnectionProviderFactory就更容易了,这主要涉及使用Wildfly:
/subsystem=keycloak-server/spi=connectionsInfinispan/:remove()
/subsystem=keycloak-server/spi=connectionsInfinispan/:add(default-provider=custom)
/subsystem=keycloak-server/spi=connectionsInfinispan/provider=custom/:add(properties={},enabled=true)当然,要做到这一点,您必须实现一个扩展并部署它。但是在代码级别上,您可以使用最新Infinispan的全部功能。
我看到您想使用Redis,这是另一个大问题,请阅读这个答案https://stackoverflow.com/a/57362238/571689,在这里我告诉您以下问题,您将遇到。
https://stackoverflow.com/questions/52506538
复制相似问题