Keycloak v20.0.3 -我无法通过IP:端口连接到Postgresql 12

rbl8hiat  于 2023-02-12  发布在  PostgreSQL
关注(0)|答案(1)|浏览(206)

如标题所示,我无法连接到VM上的Postgresql 12,但对于部署在K8S上的Postgresql,它连接正常。
下面是我的信息:

  • Docker桌面4.16.3(96739)
  • Keycloak v20.0.3(v20.0.1也出现相同错误)
  • 虚拟机:Postgresql 12-Ubuntu 18.04

我的环境:

  • 密钥锁管理员=管理员
  • 密钥锁管理员密码=管理员
  • KC_DB =后灰色
  • KC_数据库_URL_数据库=网络-oidc-v20
  • KC数据库网址主机= 192.168.201.23
  • KC数据库URL端口= 5432
  • KC_DB_用户名= Web-oidc
  • KC_数据库_密码= 1234时的Abcd
  • KC主机名管理员URL = http://本地主机:8080
  • KC主机名URL = http://本地主机:8080

(我也尝试使用KC_DB_URL=jdbc:postgresql://192.168.201.23:5432/web-oidc-v20作为KC_DB_URL_DATABASE, KC_DB_URL_HOST, KC_DB_URL_PORT的替代品,但也不起作用)
下面是docker运行命令:

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB=postgres -e KC_DB_URL_DATABASE=web-oidc-v20 -e KC_DB_URL_HOST=192.168.201.23 -e KC_DB_URL_PORT=5432 -e KC_DB_USERNAME=web-oidc -e KC_DB_PASSWORD=Abcd@1234 -e KC_HOSTNAME_ADMIN_URL=http://localhost:8080 -e KC_HOSTNAME_URL=http://localhost:8080 web-oidc-v20

容器日志:

Changes detected in configuration. Updating the server image.
Updating the configuration and installing your custom providers, if any. Please wait.
2023-02-08 08:55:41,942 WARN  [org.keycloak.services] (build-26) KC-SERVICES0047: load-digo-user (vn.vnpt.digo.iscs.keycloak.spi.authenticator.LoadDigoUserAuthenticatorFactory) is implementing the internal SPI authenticator. This SPI is internal and may change without notice
2023-02-08 08:55:46,242 WARN  [io.quarkus.deployment.steps.ReflectiveHierarchyStep] (build-104) Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
        - javax.servlet.http.Cookie (source: JacksonProcessor > org.springframework.security.web.savedrequest.DefaultSavedRequest$Builder)
Consider adding them to the index either by creating a Jandex index for your dependency via the Maven plugin, an empty META-INF/beans.xml or quarkus.index-dependency properties.
2023-02-08 08:55:53,256 INFO  [io.quarkus.deployment.QuarkusAugmentor] (main) Quarkus augmentation completed in 14734ms
Server configuration updated and persisted. Run the following command to review the configuration:

        kc.sh show-config

Next time you run the server, just run:

        kc.sh start --optimized

2023-02-08 08:55:55,649 INFO  [vn.vnpt.digo.iscs.keycloak.spi.authenticator.LoadDigoUserAuthenticatorFactory] (main) init
2023-02-08 08:55:55,751 INFO  [vn.vnpt.digo.iscs.keycloak.spi.user.storage.DigoUserStorageProviderFactory] (main) init
2023-02-08 08:55:55,753 INFO  [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: Base URL: http://localhost:8080, Hostname: localhost, Strict HTTPS: false, Path: /, Strict BackChannel: false, Admin URL: http://localhost:8080, Admin: localhost, Port: 8080, Proxied: false
2023-02-08 08:55:58,207 WARN  [io.quarkus.agroal.runtime.DataSources] (main) Datasource <default> enables XA but transaction recovery is not enabled. Please enable transaction recovery by setting quarkus.transaction-manager.enable-recovery=true, otherwise data may be lost if the application is terminated abruptly
2023-02-08 08:55:59,484 WARN  [org.infinispan.PERSISTENCE] (keycloak-cache-init) ISPN000554: jboss-marshalling is deprecated and planned for removal
2023-02-08 08:55:59,546 WARN  [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
2023-02-08 08:55:59,608 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000556: Starting user marshaller 'org.infinispan.jboss.marshalling.core.JBossUserMarshaller'
2023-02-08 08:56:00,138 INFO  [org.keycloak.broker.provider.AbstractIdentityProviderMapper] (main) Registering class org.keycloak.broker.provider.mappersync.ConfigSyncEventListener
2023-02-08 08:56:00,135 INFO  [org.infinispan.CONTAINER] (keycloak-cache-init) ISPN000128: Infinispan version: Infinispan 'Triskaidekaphobia' 13.0.10.Final
2023-02-08 08:56:00,195 WARN  [org.keycloak.quarkus.runtime.storage.legacy.database.LegacyJpaConnectionProviderFactory] (main) Unable to prepare operational info due database exception: Connection has been closed.
2023-02-08 08:56:00,428 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000078: Starting JGroups channel `ISPN`
2023-02-08 08:56:00,429 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!
2023-02-08 08:56:00,585 WARN  [io.agroal.pool] (main) Datasource '<default>': Connection has been closed.
2023-02-08 08:56:00,613 WARN  [org.jgroups.protocols.UDP] (keycloak-cache-init) JGRP000015: the send buffer of socket MulticastSocket was set to 1.00MB, but the OS only allocated 212.99KB
2023-02-08 08:56:00,618 WARN  [org.jgroups.protocols.UDP] (keycloak-cache-init) JGRP000015: the receive buffer of socket MulticastSocket was set to 20.00MB, but the OS only allocated 212.99KB
2023-02-08 08:56:00,620 WARN  [org.jgroups.protocols.UDP] (keycloak-cache-init) JGRP000015: the send buffer of socket MulticastSocket was set to 1.00MB, but the OS only allocated 212.99KB
2023-02-08 08:56:00,622 WARN  [org.jgroups.protocols.UDP] (keycloak-cache-init) JGRP000015: the receive buffer of socket MulticastSocket was set to 25.00MB, but the OS only allocated 212.99KB
2023-02-08 08:56:02,644 INFO  [org.jgroups.protocols.pbcast.GMS] (keycloak-cache-init) 87e253982a2b-10337: no members discovered after 2001 ms: creating cluster as coordinator
2023-02-08 08:56:02,662 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000094: Received new cluster view for channel ISPN: [87e253982a2b-10337|0] (1) [87e253982a2b-10337]
2023-02-08 08:56:02,668 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000079: Channel `ISPN` local address is `87e253982a2b-10337`, physical addresses are `[192.168.0.2:33278]`
2023-02-08 08:56:03,341 INFO  [org.infinispan.CLUSTER] (main) ISPN000080: Disconnecting JGroups channel `ISPN`
2023-02-08 08:56:03,507 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (production) mode
2023-02-08 08:56:03,508 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to validate database
2023-02-08 08:56:03,508 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: org.postgresql.util.PSQLException: Connection has been closed.
2023-02-08 08:56:03,508 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Connection has been closed.
2023-02-08 08:56:03,509 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.

Postgresql日志:

2023-02-08 14:59:19.553 +07 [2652184] web-oidc@web-oidc-v20 LOG:  connection authorized: user=web-oidc database=web-oidc-v20 SSL enabled (protocol=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384, bits=256, compression=off)
2023-02-08 14:59:20.758 +07 [2652184] web-oidc@web-oidc-v20 FATAL:  relation "migration_model" does not exist at character 25
2023-02-08 14:59:20.758 +07 [2652184] web-oidc@web-oidc-v20 STATEMENT:  SELECT ID, VERSION FROM MIGRATION_MODEL ORDER BY UPDATE_TIME DESC
2023-02-08 14:59:20.758 +07 [2652184] web-oidc@web-oidc-v20 LOG:  disconnection: session time: 0:00:01.577 user=web-oidc database=web-oidc-v20 host=192.168.200.25 port=62448

请让我知道我错在哪里,真诚地感谢大家!🙏

nx7onnlm

nx7onnlm1#

尝试将docker命令中的localhost替换为host. docker. internal。
Docker无法解析localhost。因此,您需要运行

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB=postgres -e KC_DB_URL_DATABASE=web-oidc-v20 -e KC_DB_URL_HOST=192.168.201.23 -e KC_DB_URL_PORT=5432 -e KC_DB_USERNAME=web-oidc -e KC_DB_PASSWORD=Abcd@1234 -e KC_HOSTNAME_ADMIN_URL=http://host.docker.internal:8080 -e KC_HOSTNAME_URL=http://host.docker.internal:8080 web-oidc-v20

另外,不确定这一点

-e KC_DB_URL_HOST=192.168.201.23

另外,我看到你正在尝试在生产模式下启动它。这是预期的吗?如果不是,那么在最后添加start-dev。

相关问题