首页 > 解决方案 > 如何在本地使用 kafka 从 aws rds postgresql 中提取数据?

问题描述

我在 aws 上有 postgresql 数据库服务器。我在本地机器上设置了一个节点 kafka 集群,并想从 postgresql 数据库服务器中提取数据。我一直在使用 jdbc 源连接器这里是配置(更改了实际值)

name=test-source-postgresql-jdbc-01
connector.class=io.confluent.connect.jdbc.JdbcSourceConnector
tasks.max=1
key.converter=io.confluent.connect.avro.AvroConverter
key.converter.schema.registry.url=http://localhost:8081
connection.url=jdbc:postgresql://hostname:5432/dbname? 
user=abc&password=pwd
connection.user=abc
connection.password=pwd
table.whitelist=abc1
mode=timestamp
timestamp.column.name=timestamp
topic.prefix=test-postgresql-

并在运行时出现以下错误

ERROR Failed to create job for etc/kafka-connect-jdbc/quickstart-postgresql.properties (org.apache.kafka.connect.cli.ConnectStandalone:102)
ERROR Stopping after connector error (org.apache.kafka.connect.cli.ConnectStandalone:113)
java.util.concurrent.ExecutionException: org.apache.kafka.connect.runtime.rest.errors.BadRequestException: Connector 
configuration is invalid and contains the following 2 error(s):
Invalid value org.postgresql.util.PSQLException: Connection to hostname:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. for configuration Couldn't open connection to jdbc:postgresql://abc:5432/dbname?user=abc&password=pwd

curl localhost:8083/connector-plugins请点击链接

ls share/java/kafka-connect-jdbc -l请点击链接

任何帮助,将不胜感激!

标签: postgresqlamazon-rdsapache-kafka-connectconfluent-platform

解决方案


正如您所提到的,您正在通过 SSH 隧道连接到 RDS。我不认为您可以将 Kafka JDBC 连接器配置为自动通过 SSH 隧道,但您可以手动创建 SSH 隧道,然后配置 Kafka 连接器以通过此隧道连接到 RDS - 详细描述请点击此处

按照您的配置,您可以使用命令创建 SSH 隧道

ssh -N -L 5432:rds.hostname:5432 uername@ec2instnace.com -i ~/.ssh/your_key

您可以使用以下方法测试与数据库的连接:

psql -h localhost -p 5432

你的连接器配置将是

connection.url=jdbc:postgresql://localhost:5432/dbname?user=abc&password=pwd

推荐阅读