简体   繁体   English

Keycloak + postgresql配置

[英]Keycloak + postgresql configuration

I tried to configure keycloak server with my postgresql db.我试图用我的 postgresql 数据库配置 keycloak 服务器。 After many tries with a lot of configs I decided to ask the question.经过多次尝试大量配置后,我决定问这个问题。 I have the next configurations: module.xml which is located in keycloak/modules/org/postgresql/main Also in that directory I put jdbc-driver with name 'postgresql-42.2.16.jar'我有下一个配置: module.xml 位于 keycloak/modules/org/postgresql/main 也在那个目录中我把 jdbc-driver 命名为 'postgresql-42.2.16.jar'

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">

<resources>
    <resource-root path="postgresql-42.2.16.jar"/>
</resources>

<dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
</dependencies>
</module>

standalone.xml which is located in keycloak/standalone/configuration In that xml I configured standalone.xml 位于 keycloak/standalone/configuration 在那个 xml 我配置

drivers:司机:

<drivers>
    <driver name="postgresql" module="org.postgresql">
        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
    </driver>
    <driver name="h2" module="com.h2database.h2">
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
    </driver>
</drivers>

datasources:数据源:

<datasources>
    <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:postgres://192.168.99.100:5432/keycloak</connection-url>
        <driver>postgresql</driver>
        <pool>
            <max-pool-size>20</max-pool-size>
        </pool>
        <security>
            <user-name>keycloak</user-name>
            <password>password</password>
        </security>
    </datasource>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
         <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
         <driver>h2</driver>
         <security>
             <user-name>sa</user-name>
             <password>sa</password>
         </security>
    </datasource>
 
...
</datasources>

keycloak server config:密钥斗篷服务器配置:

<subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
    <spi name="connectionsJpa">
        <provider name="default" enabled="true">
            <properties>
                <property name="dataSource" value="java:jboss/datasources/KeycloakDS"/>
                <property name="initializeEmpty" value="false"/>
                <property name="migrationStrategy" value="manual"/>
                <property name="migrationExport" value="${jboss.home.dir}/keycloak-database-update.sql"/>
            </properties>
        </provider>
    </spi>
</subsystem>

And when I'm trying to start my keycloak server I got the exception:当我尝试启动我的 keycloak 服务器时,出现了异常:

17:56:19,859 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) 
WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc- 
driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]"
]
}
17:56:19,860 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) 
WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
    "jboss.jdbc-driver.postgresql",
    "jboss.jdbc-driver.postgresql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc- 
driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]"
]
}

  

It's looks like I configured my datasource in wrong way, but I can't find the error.看起来我以错误的方式配置了我的数据源,但我找不到错误。 I checked this check list and it doesn't resolve my issue.我检查了这个核对清单,它没有解决我的问题。

Could you please retry with the following connection string:您能否使用以下连接字符串重试:

jdbc:postgresql://192.168.99.100:5432/keycloak

instead of代替

jdbc:postgres://192.168.99.100:5432/keycloak

Also, consider letting the SPI/connectionsJpa block at defaults (I believe in particular that initializeEmpty should be true) and I don't remember that I had to add/modify this block, so please double-check.另外,考虑让 SPI/connectionsJpa 块默认(我特别相信initializeEmpty应该是真的),我不记得我必须添加/修改这个块,所以请仔细检查。

You may also disable or comment the ExampleDS (h2) dataSource.您还可以禁用或注释ExampleDS (h2) 数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM