postgresql - 如何在本地使用 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请点击链接
任何帮助,将不胜感激!
解决方案
正如您所提到的,您正在通过 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
推荐阅读
- powerbi - 为什么我可以创建这些关系?
- rust - ACCESS_VIOLATION 从 Rust 调用 Btrieve BTRCALL 函数
- reactjs - 检查用户是否在 azure AD B2C 用户流中注册或登录
- c# - 如何显示我创建的函数的结果?
- javascript - 循环认为是一个多维数组
- c# - C#获取当前登录用户在.net表单应用程序中的登录时间
- c - 将数字和字符串分成文本和数字
- java - GPU 上的 DL4J 示例不起作用(用于学校项目)
- node.js - 将 CVS 从 Web 保存到 Apify 数据集
- c# - 是否可以从给定类型创建 ICollection?