第 9 章 服务器缓存配置
Red Hat Single Sign-On 有两种类型的缓存。一种缓存位于数据库前面,以降低 DB 的负载,并通过在内存中保留数据来提高总体响应时间。realm、client、role 和 user 元数据保存在这种类型的缓存中。这个缓存是本地缓存。即使位于具有更多 Red Hat Single Sign-On 服务器的集群中,本地缓存也不会使用复制。相反,它们只会在本地保留副本,如果条目更新了一个 invalidation 消息,则消息会发送到集群的其余部分,该条目将被驱除。有单独的复制缓存 工作,该任务是将失效消息发送到整个集群,其中哪些条目应从本地缓存驱除。这可大大减少网络流量,使效率更高,并避免通过线路传输敏感元数据。
第二类型的缓存处理管理用户会话、离线令牌,并跟踪登录失败,以便服务器可以检测密码临时和其他攻击。这些缓存中保存的数据只是临时的,但可能在集群中复制。
本章讨论了这两个集群非集群部署用于这些缓存的一些配置选项。
有关这些缓存的更多高级配置,请参阅 JBoss EAP 配置指南中的 Infinispan 部分。
9.1. 驱除和过期 复制链接链接已复制到粘贴板!
为红帽单点登录配置了多个不同的缓存。有一个域缓存,其中包含有关安全应用程序、通用安全数据和配置选项的信息。另外,还有一个包含用户元数据的用户缓存。两者都会默认缓存到最多 10000 个条目,并使用最早使用的驱除策略。它们也与控制集群设置中驱除的对象修订缓存相关联。这个缓存是隐式创建的,且配置的大小已两倍。用户会话、离线令牌和登录失败也存在单独的缓存。这些缓存也没有绑定大小。
这些缓存的驱除策略和最大条目可以在 standalone. xml、standalone -ha.xml 或 domain.xml 中配置,具体取决于您的 操作模式。
非集群
<subsystem xmlns="urn:jboss:domain:infinispan:4.0">
<cache-container name="keycloak" jndi-name="infinispan/Keycloak">
<local-cache name="realms">
<eviction max-entries="10000" strategy="LRU"/>
</local-cache>
<local-cache name="users">
<eviction max-entries="10000" strategy="LRU"/>
</local-cache>
<local-cache name="sessions"/>
<local-cache name="offlineSessions"/>
<local-cache name="loginFailures"/>
<local-cache name="work"/>
<local-cache name="authorization">
<eviction strategy="LRU" max-entries="100"/>
</local-cache>
<local-cache name="keys">
<eviction strategy="LRU" max-entries="1000"/>
<expiration max-idle="3600000"/>
</local-cache>
</cache-container>
集群的
<subsystem xmlns="urn:jboss:domain:infinispan:4.0">
<cache-container name="keycloak" jndi-name="infinispan/Keycloak">
<transport lock-timeout="60000"/>
<local-cache name="realms">
<eviction max-entries="10000" strategy="LRU"/>
</local-cache>
<local-cache name="users">
<eviction max-entries="10000" strategy="LRU"/>
</local-cache>
<distributed-cache name="sessions" mode="SYNC" owners="1"/>
<distributed-cache name="offlineSessions" mode="SYNC" owners="1"/>
<distributed-cache name="loginFailures" mode="SYNC" owners="1"/>
<distributed-cache name="authorization" mode="SYNC" owners="1"/>
<replicated-cache name="work" mode="SYNC"/>
<local-cache name="keys">
<eviction max-entries="1000" strategy="LRU"/>
<expiration max-idle="3600000"/>
</local-cache>
</cache-container>
要限制或扩展允许的条目数量,只需添加或编辑特定缓存配置的 expiration 元素。