使用本地kafka-connect集群连接远程数据库时连接超时

Connection timeout using local kafka-connect cluster to connect on a remote database

我正在尝试使用 docker-compose 运行 本地 kafka-connect 集群。 我需要连接到远程数据库,并且我还在使用远程 kafka 和模式注册表。 我已启用从我的机器访问这些远程资源。

要启动集群,在我 Ubuntu WSL2 终端的项目文件夹中,我 运行ning

docker build -t my-connect:1.0.0

docker-compose up

应用程序 运行 成功,但是当我尝试创建新连接器时,returns 错误 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

我做错了什么?我是否需要配置其他内容以允许连接到此远程数据库?

您需要正确设置 rest.advertised.host.name(或 CONNECT_REST_ADVERTISED_HOST_NAME,如果您使用的是 Docker)。 这就是 Connect worker 与集群中其他 worker 通信的方式。

有关详细信息,请参阅 Common mistakes made when configuring multiple Kafka Connect workers by Robin Moffatt

在你的情况下,尝试从撰写文件中删除 CONNECT_REST_ADVERTISED_HOST_NAME=localhost