Keycloak 高可用性 : Standalone-HA vs Domain Clustered mode

标签 keycloak

基于documentation :

Domain Clustered Mode:

Domain mode is a way to centrally manage and publish the configuration for your servers.

Running a cluster in standard mode can quickly become aggravating as the cluster grows in size. Every time you need to make a configuration change, you have to perform it on each node in the cluster. Domain mode solves this problem by providing a central place to store and publish configurations. It can be quite complex to set up, but it is worth it in the end. This capability is built into the WildFly Application Server which Keycloak derives from.

我尝试了用户手册中的示例设置,它确实维护了多个配置。

但是,就高可用性而言,这并不是很有弹性。当主节点宕机时,Auth Server 将停止运行,因为所有从节点都监听域 Controller 。

我的理解对吗?还是我遗漏了什么?

如果是这种情况,要确保高可用性,Standalone-HA 是可行的方法,对吧?

最佳答案

Wildfly 节点管理和集群是正交特征。

keycloak 中的集群实际上只是缓存复制(各种 session 、登录失败等...)。因此,如果你想为你的 session 启用容错,你只需要正确配置缓存复制(通常还有节点发现),为此你可以简单地让 owners 参数大于 1:

<distributed-cache name="sessions" owners="2"/>
<distributed-cache name="authenticationSessions" owners="2"/>
<distributed-cache name="offlineSessions" owners="2"/>
<distributed-cache name="clientSessions" owners="2"/>
<distributed-cache name="offlineClientSessions" owners="2"/>
<distributed-cache name="loginFailures" owners="1"/>
<distributed-cache name="actionTokens" owners="2">

现在所有在第一个节点上启动的新 session 都将被复制到另一个节点,因此如果第一个节点出现故障,最终用户可以由另一个节点提供服务。例如,您总共可以有 3 个节点,并且至少需要 2 个 session 副本分布在这 3 个节点中。

现在,如果我们查看域模式与 ha 模式,我们可以说这只是关于如何将这些 jboss/wildfly 服务器配置传送到目标节点。在 HA 模式下,服务器运行时提供所有配置,在域模式下,这些配置将从域 Controller 中获取。

我建议您使用 HA 模式实现复制,然后在需要时转到域模式。此外,如果我们考虑将所有内容容器化的现代方法,HA 模式更适合容器化。可以在容器构建期间注入(inject)参数化集群设置,并能够在运行时通过环境更改它们(例如,所有者参数可以从容器环境变量中删除)

Keycloak 博客中有一些关于集群的文章,例如: this

我还建议查看 Keycloak docker 容器镜像存储库: here

关于Keycloak 高可用性 : Standalone-HA vs Domain Clustered mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64575238/

相关文章:

java - 具有自定义用户联合docker部署的Keycloak

mysql - Keycloak/Wildfly 由于组复制 mysql 数据库而失败,没有太多提示为什么 : "RuntimeException: Failed to update database"

java - 在 Keycloak 中进行身份验证之前在服务器中设置请求 header

docker - docker如何拉旧版本的Keycloak?

Mysql,在触发器中插入不应该插入NULL值

sendgrid - 当通过 sendgrid 从 keycloak 发送验证电子邮件请求时,生成的 url 编码错误

keycloak - 如何使用 Spring Cloud Gateway 和 Keycloak 验证 curl(或 Postman 或 Ajax)调用

spring-boot - 如何在通过keycloak生成的访问 token (JWT)中添加自定义字段?

java - 如何为 keycloak 客户端添加多个用户

java - Keycloak Quickstarts 在部署 Wildfly 中不起作用