使用本地 kafka-connect 集群连接远程数据库的连接超时
Posted
技术标签:
【中文标题】使用本地 kafka-connect 集群连接远程数据库的连接超时【英文标题】:Connection timeout using local kafka-connect cluster to connect on a remote database 【发布时间】:2021-09-13 22:28:12 【问题描述】:我正在尝试使用 docker-compose 运行本地 kafka-connect 集群。 我需要连接远程数据库,并且我还使用远程 kafka 和模式注册表。 我已启用从我的机器访问这些远程资源的权限。
要启动集群,在我的 Ubuntu WSL2 终端的项目文件夹中,我正在运行
docker build -t my-connect:1.0.0
docker-compose up
应用程序运行成功,但当我尝试创建新连接器时,返回错误 500 并超时。
我的 Dockerfile
FROM confluentinc/cp-kafka-connect-base:5.5.0
RUN cat /etc/confluent/docker/log4j.properties.template
ENV CONNECT_PLUGIN_PATH="/usr/share/java,/usr/share/confluent-hub-components"
ARG JDBC_DRIVER_DIR=/usr/share/java/kafka/
RUN confluent-hub install --no-prompt confluentinc/kafka-connect-jdbc:5.5.0 \
&& confluent-hub install --no-prompt confluentinc/connect-transforms:1.3.2
ADD java/kafka-connect-jdbc /usr/share/confluent-hub-components/confluentinc-kafka-connect-jdbc/lib/
COPY java/kafka-connect-jdbc/ojdbc8.jar /usr/share/confluent-hub-components/confluentinc-kafka-connect-jdbc/lib/
ENTRYPOINT ["sh","-c","export CONNECT_REST_ADVERTISED_HOST_NAME=$(hostname -I);/etc/confluent/docker/run"]
我的 docker-compose.yaml
services:
connect:
image: my-connect:1.0.0
ports:
- 8083:8083
environment:
- CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL=http=//schema-registry:8081
- CONNECT_KEY_CONVERTER=io.confluent.connect.avro.AvroConverter
- CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL=http=//schema-registry:8081
- CONNECT_BOOTSTRAP_SERVERS=broker1.intranet:9092
- CONNECT_GROUP_ID=kafka-connect
- CONNECT_INTERNAL_KEY_CONVERTER=org.apache.kafka.connect.json.JsonConverter
- CONNECT_VALUE_CONVERTER=io.confluent.connect.avro.AvroConverter
- CONNECT_INTERNAL_VALUE_CONVERTER=org.apache.kafka.connect.json.JsonConverter
- CONNECT_OFFSET_STORAGE_TOPIC=kafka-connect.offset
- CONNECT_CONFIG_STORAGE_TOPIC=kafka-connect.config
- CONNECT_STATUS_STORAGE_TOPIC=kafka-connect.status
- CONNECT_CONNECTOR_CLIENT_CONFIG_OVERRIDE_POLICY=All
- CONNECT_LOG4J_ROOT_LOGLEVEL=INFO
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- CONNECT_REST_ADVERTISED_HOST_NAME=localhost
我的集群已启动
~$ curl -X GET http://localhost:8083/
"version":"5.5.0-ccs","commit":"606822a624024828","kafka_cluster_id":"OcXKHO7eT4m9NBHln6ACKg"
连接器调用
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" localhost:8083/connectors/ -d
"name": "my-connector",
"config":
"connector.class" : "io.debezium.connector.oracle.OracleConnector",
"tasks.max": "1",
"database.user": "user",
"database.password": "pass",
"database.dbname":"SID",
"database.schema":"schema",
"database.server.name": "dbname",
"schema.include.list": "schema",
"database.connection.adapter":"logminer",
"database.hostname":"databasehost",
"database.port":"1521"
错误
"error_code": 500,"message": "IO Error trying to forward REST request: java.net.SocketTimeoutException: Connect Timeout"
## LOG
connect_1 | [2021-07-01 19:08:50,481] INFO Database Version: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
connect_1 | Version 19.4.0.0.0 (io.debezium.connector.oracle.OracleConnection)
connect_1 | [2021-07-01 19:08:50,628] INFO Connection gracefully closed (io.debezium.jdbc.JdbcConnection)
connect_1 | [2021-07-01 19:08:50,643] INFO AbstractConfig values:
connect_1 | (org.apache.kafka.common.config.AbstractConfig)
connect_1 | [2021-07-01 19:09:05,722] ERROR IO error forwarding REST request: (org.apache.kafka.connect.runtime.rest.RestClient)
connect_1 | java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Connect Timeout
测试与数据库的连接
$ telnet databasehostname 1521
Trying <ip>... Connected to databasehostname
测试与 kafka 代理的连接
$ telnet broker1.intranet 9092
Trying <ip>... Connected to broker1.intranet
测试与远程架构注册表的连接
$ telnet schema-registry.intranet 8081
Trying <ip>... Connected to schema-registry.intranet
我做错了什么?我是否需要配置其他东西以允许连接到这个远程数据库?
【问题讨论】:
【参考方案1】:您需要正确设置rest.advertised.host.name
(或CONNECT_REST_ADVERTISED_HOST_NAME
,如果您使用的是Docker)。
这就是 Connect 工作人员与集群中其他工作人员进行通信的方式。
更多详情请参阅Common mistakes made when configuring multiple Kafka Connect workers
Robin Moffatt。
在您的情况下,请尝试从撰写文件中删除 CONNECT_REST_ADVERTISED_HOST_NAME=localhost
。
【讨论】:
我已经尝试过了,但是当我尝试使用 "network_mode" = host 上传 compose 时,我收到错误 "connect_1 | sh: 1: export: 172.17.0.1: bad variable name" 我明白了。这很愚蠢。 - CONNECT_GROUP_ID 与在相同环境中运行并使用相同配置主题的另一个实例同名。改变这个,它工作!还是谢谢。 @Malkath,不客气!如果我的回答有帮助。请投票以上是关于使用本地 kafka-connect 集群连接远程数据库的连接超时的主要内容,如果未能解决你的问题,请参考以下文章
Kafka-Connect:启动 S3 Sink 连接器时出现无法识别的错误
使用 Docker Compose 创建 Kafka-Connect 集群以供 ksqlDB 使用
本地Spark连接远程集群Hive(Scala/Python)
Kafka-connect,Bootstrap 代理断开连接