在域 Keycloak 服务器上创建 realms/clients 不会立即对从属 Keycloak 节点可见

Creating realms/clients on a domain Keycloak server is not immediately visible to a slave Keycloak node

我们有 2 台机器 运行ning Keycloak 4.8.3.Final (WildFly Core 6.0.2.Final) 处于域模式。首先,host1 将成为 运行 域控制器,并将成为我们的主人。 Host2 是我们的奴隶,并向主人注册自己。根据我们的理解,域模式通过提供一个中心位置来存储和发布配置来解决这个问题。

第一个通过执行命令启动:

/opt/keycloak/bin/domain.sh --host-config host-master.xml -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djava.security.egd=file:/dev/urandom -Dkeycloak.profile.feature.token_exchange=enabled -Djboss.node.name=host1

第二个通过执行命令:

/opt/keycloak/bin/domain.sh --host-config host-slave.xml -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.domain.master.username=slave -Djboss.domain.master.address={host1_ip} -Dkeycloak.profile.feature.token_exchange=enabled -Djava.security.egd=file:/dev/urandom -Djboss.node.name=host2

两者都启动成功,slave成功连接到master。我们正在使用 MySQL 机器,服务器都指向该机器以实现数据持久性。

首先,我们使用了 keycloak 分发附带的默认值 domain.xml,我们最初的期望是通过在 host1 上创建一些东西,更改将传播到 host2。不幸的是,这并没有发生。当我们创建用户时,用户会在一段时间后出现在 host2 上。当我们从 host1 创建领域或领域中的客户端时,在我们重新启动两台服务器并强制同步信息之前,无法从 host2 看到更改。

下一步是更改 infinispan 指令中的 domain.xml 配置,并在所有机器上复制缓存。

<subsystem xmlns="urn:jboss:domain:infinispan:7.0">
    <cache-container name="keycloak">
        <transport lock-timeout="60000" />
        <replicated-cache name="authenticationSessions" />
        <replicated-cache name="clientSessions" />
        <replicated-cache name="offlineClientSessions" />
        <replicated-cache name="authorization" />
        <replicated-cache name="work" />
        <replicated-cache name="keys" />
        <replicated-cache name="actionTokens"></replicated-cache>
        <replicated-cache name="realms" />
        <replicated-cache name="users" />
        <replicated-cache name="sessions" />
        <replicated-cache name="offlineSessions" />
        <replicated-cache name="loginFailures" />
        <replicated-cache name="work" />
        <replicated-cache name="realmVersions" />
    </cache-container>
    <cache-container name="server" aliases="singleton cluster" default-cache="default" module="org.wildfly.clustering.server">
        <transport lock-timeout="60000" />
        <replicated-cache name="default">
            <transaction mode="BATCH" />
        </replicated-cache>
    </cache-container>
    <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
        <transport lock-timeout="60000" />
        <distributed-cache name="dist">
            <locking isolation="REPEATABLE_READ" />
            <transaction mode="BATCH" />
            <file-store />
        </distributed-cache>
    </cache-container>
    <cache-container name="ejb" aliases="sfsb" default-cache="dist" module="org.wildfly.clustering.ejb.infinispan">
        <transport lock-timeout="60000" />
        <distributed-cache name="dist">
            <locking isolation="REPEATABLE_READ" />
            <transaction mode="BATCH" />
            <file-store />
        </distributed-cache>
    </cache-container>
    <cache-container name="hibernate" module="org.infinispan.hibernate-cache">
        <transport lock-timeout="60000" />
        <local-cache name="local-query">
            <object-memory size="10000" />
            <expiration max-idle="100000" />
        </local-cache>
        <invalidation-cache name="entity">
            <transaction mode="NON_XA" />
            <object-memory size="10000" />
            <expiration max-idle="100000" />
        </invalidation-cache>
        <replicated-cache name="timestamps" />
    </cache-container>
</subsystem>

但是,我们有同样的问题,尤其是如果您为客户端重新生成秘密,则该秘密不会传播到从属主机,反之亦然。

是否有其他人遇到过该问题?您如何解决该问题?任何帮助将不胜感激!

问题是我们的云提供商不支持多播,两台服务器无法找到并相互通信!我更改了配置并开始使用 TCPPING 而不是仅使用 UDP 的 PING。 我花了很多时间试图解决这个问题,所以请确保您的提供商支持多播,以便开箱即用地使用 Keycloak。此外,我发现以下文章提供了有关如何设置 Keycloak https://www.keycloak.org/2019/04/keycloak-cluster-setup.html 的信息。如果只有这篇文章是在我试图处理这个问题时创建的...