我正在尝试连接到Docker容器之外的Oracle数据库。我是Docker的新手,不确定如何实现这一点。在我的本地计算机上,我可以通过提供主机,服务名称和端口或仅通过引用tnsnames.ora文件中提到的条目来连接到特定的数据库。我已经在Windows 10计算机上安装了Docker。我的最终目标是使用ksqlDB在kafka主题上流式处理我的表。但是,第一步是连接到我的oracle数据库。我不确定要从Docker连接到任何外部数据库源需要进行哪些修改或设置。我尝试了以下连接器配置,但这不起作用。
连接器配置:
CREATE SOURCE CONNECTOR jdbc_source WITH(
'connector.class' = 'io.confluent.connect.jdbc.JdbcSourceConnector',
'connection.url' = 'jdbc:oracle:thin://dv11-db.com:1521/dv11.db.com',
'connection.user' = 'user',
'connection.password' = 'password',
'topic.prefix' = 'jdbc_',
'mode' = 'bulk',
'table.whitelist' = 'batch_driver'
);
错误:
{
"error_code" : 400,
"message" : "Connector configuration is invalid and contains the following 2 error(s):\nInvalid value java.sql.SQLException: No suitable driver
found for jdbc:oracle:thin://dv11-db.com:1521/dv11.db.com for configuration Couldn't open connection to jdbc:oracle:thin://dv11-db.com:1521/dv11.db.com\nInvalid value java.sql.SQLException: No suitable driver found for jdbc:oracle:thin://dv11-db.com:1521/dv11.db.com for configuration Couldn't open connection to jdbc:oracle:thin://dv11-db.com:1521/dv11.db.com\nYou can also find the above list of errors at the endpoint `/{connectorType}/config/validate`"
}
Oracle配置:
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dv11-db.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = dv11.db.com)))
Docker-compose.yml
---
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-enterprise-kafka:latest
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "29092:29092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
ksqldb-server:
image: confluentinc/ksqldb-server:0.7.0
hostname: ksqldb-server
container_name: ksqldb-server
depends_on:
- broker
ports:
- "8088:8088"
environment:
KSQL_LISTENERS: http://0.0.0.0:8088
KSQL_BOOTSTRAP_SERVERS: broker:9092
KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: "true"
KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: "true"
KSQL_KSQL_CONNECT_WORKER_CONFIG: "/connect/connect.properties"
KSQL_CONNECT_GROUP_ID: "ksql-connect-cluster"
KSQL_CONNECT_BOOTSTRAP_SERVERS: "broker:9092"
KSQL_CONNECT_KEY_CONVERTER: "org.apache.kafka.connect.storage.StringConverter"
KSQL_CONNECT_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
KSQL_CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
KSQL_CONNECT_CONFIG_STORAGE_TOPIC: "ksql-connect-configs"
KSQL_CONNECT_OFFSET_STORAGE_TOPIC: "ksql-connect-offsets"
KSQL_CONNECT_STATUS_STORAGE_TOPIC: "ksql-connect-statuses"
KSQL_CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
KSQL_CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
KSQL_CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
KSQL_CONNECT_PLUGIN_PATH: "/usr/share/kafka/plugins"
volumes:
- ./confluentinc-kafka-connect-jdbc-5.4.0:/usr/share/kafka/plugins/jdbc
ksqldb-cli:
image: confluentinc/ksqldb-cli:0.7.0
container_name: ksqldb-cli
depends_on:
- broker
- ksqldb-server
entrypoint: /bin/sh
tty: true
答案 0 :(得分:1)
java.sql.SQLException:没有合适的驱动程序
不是docker问题。您没有将数据库驱动程序放置在正确的位置
它不应该进入/usr/share/kafka/plugins/jdbc
。
它应该放在/usr/share/kafka-connect-jdbc
引用https://www.confluent.io/blog/kafka-connect-deep-dive-jdbc-source-connector/
在本地计算机上,我可以通过提供主机,服务名称和端口或仅引用tnsnames.ora文件中提到的条目来连接到特定数据库
不清楚您的连接方式...来自代码?使用某些Oracle工具?
如果您的数据库位于另一台服务器上,则Docker的网络连接应以完全相同的方式工作。您仍然需要设置驱动程序