WildFly Postgres DataSource远程连接URL被忽略 [英] WildFly Postgres DataSource remote connection-url ignored
问题描述
在以独立群集模式设置Keycloak服务器时遇到一些配置问题.尽管将数据源配置为使用{REMOTE_IP}
上的postgres数据库,但它仍无法启动服务器,抱怨它无法连接到localhost:5432
.
I am running into some configuration troubles in setting up a Keycloak server in standalone clustered mode. Despite configuring the datasource to use a postgres database on {REMOTE_IP}
, it is failing to start the server complaining that it cannot connect to localhost:5432
.
我一直在搜索,但是我很困惑为什么当将连接URL设置为远程主机时,数据源会尝试连接到本地主机.
I've been searching all over but I'm befuddled why the DataSource would try to connect to localhost when the connection-url is set to a remote host.
我的配置是否有任何错误?我如何找出PG为什么尝试连接到localhost而不是{REMOTE_IP}
Is there any mistake in my configuration? How can I figure out why PG is trying to connect to localhost instead of {REMOTE_IP}
我的设置是1个Postgres数据库服务器和2个Keycloak服务器
My setup is 1 Postgres database server and 2 Keycloak servers
我遵循了使用关系数据库的安装说明,并添加了用于Postgres的JDBC驱动程序v9.4.1212.
I followed the installation instructions for using a relational database and have added the JDBC drivers v9.4.1212 for Postgres.
我的数据源配置如下:
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://{REMOTE_IP}: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>
日志中的错误消息显示为:
The error message from the logs reads:
...
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:52)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:216)
at org.postgresql.Driver.makeConnection(Driver.java:404)
at org.postgresql.Driver.connect(Driver.java:272)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:86)
at org.postgresql.ds.PGPoolingDataSource.getConnection(PGPoolingDataSource.java:309)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:312)
... 43 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.postgresql.core.PGStream.<init>(PGStream.java:61)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
... 52 more
我已经确认可以使用psql连接到Postgres
I've verified that I can connect to postgres using psql
# psql -h {REMOTE_IP} keycloak keycloak
psql (9.5.7)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384,
bits: 256, compression: off)
Type "help" for help.
keycloak=>
推荐答案
我设法弄清楚了这一点.用于postgres的JDBC驱动程序已配置为使用PGPoolingDataSource
并已定义datasource-class
.
I managed to figure this out for my case. The JDBC driver for postgres was configured to use a PGPoolingDataSource
and had a datasource-class
defined.
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<datasource-class>org.postgresql.ds.PGPoolingDataSource</datasource-class>
</driver>
定义datasource-class
后,必须通过connection-property
而不是connection-url
传递连接URL.我更新了配置,服务器启动正常.
When the datasource-class
is defined, the connection url must be passed through a connection-property
instead of connection-url
. I updated my configuration and the server booted up fine.
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://{REMOTE_IP}:5432/keycloak</connection-url>
<connection-property name="url">jdbc:postgresql://{REMOTE_IP}:5432/keycloak</connection-property>
<driver>postgresql</driver>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
<driver-class>org.postgresql.Driver</driver-class>
<security>
<user-name>keycloak</user-name>
<password>{PASSWORD}</password>
</security>
</datasource>
wildfly问题跟踪器中记录了此问题 https://issues.jboss.org/browse/WFLY-6157
This issue is noted in the wildfly issue tracker https://issues.jboss.org/browse/WFLY-6157
这篇关于WildFly Postgres DataSource远程连接URL被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!