問(wèn)題描述
問(wèn)題:
如何使用 Kafka Connect 正確注冊(cè) SqlServer 連接器以連接到獨(dú)立的 SQL Server 實(shí)例?注意:我沒(méi)有在 Docker 中運(yùn)行 SQL Server.
How do I correctly register the SqlServer connector with Kafka Connect to connect to a standalone SQL Server Instance? Note: I am NOT running SQL Server in Docker.
錯(cuò)誤:
錯(cuò)誤:由:com.microsoft.sqlserver.jdbc.SQLServerException引起:TCP/IP 連接到主機(jī) 127.0.0.1,端口 1433 失敗.錯(cuò)誤:連接被拒絕(Connection denied).驗(yàn)證連接特性.確保 SQL Server 的實(shí)例正在運(yùn)行主機(jī)并在端口接受 TCP/IP 連接.確保 TCP與端口的連接未被防火墻阻止.".
Error: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: "Connection refused (Connection refused). Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
問(wèn)題排查:
- 在 dbo.Posts 表上啟用 CDC(見(jiàn)下文)
- 在 SQL Server 配置管理器的 SQL Server 網(wǎng)絡(luò)配置中驗(yàn)證 TCP/IP 已啟用并將所有地址設(shè)置為已啟用并在端口 1433 上處于活動(dòng)狀態(tài)
- 禁用 Windows 防火墻
- 在 SQL Server 配置管理器中啟用 SQL Server 瀏覽器
- 驗(yàn)證我可以遠(yuǎn)程登錄以下內(nèi)容:(127.0.0.1 1433; localhost 1433; lt-ls231 1433)
上下文:
我正在嘗試使用 Docker 在 Windows 10 上設(shè)置 Debezium.我可以毫無(wú)問(wèn)題地在 Powershell 中成功運(yùn)行以下命令:
I am attempting to setup Debezium on Windows 10 using Docker. I can successfully run the following commands in Powershell without problem:
docker run -it --rm --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 debezium/zookeeper:1.1
docker run -it --rm --name kafka -p 9092:9092 --link zookeeper:zookeeper debezium/kafka:1.1
docker run -it --rm --name connect -p 8083:8083 -e GROUP_ID=1 -e CONFIG_STORAGE_TOPIC=my_connect_configs -e OFFSET_STORAGE_TOPIC=my_connect_offsets -e STATUS_STORAGE_TOPIC=my_connect_statuses --link zookeeper:zookeeper --link kafka:kafka debezium/connect:1.1
當(dāng)我嘗試使用 Kafka-Connect connect
注冊(cè) SQL Server 連接時(shí)出現(xiàn)錯(cuò)誤(見(jiàn)上文),我運(yùn)行以下命令:
I get an error (see above) when I attempt to register the SQL Server connection with Kafka-Connect connect
, I run the following command:
Invoke-RestMethod -Method Post -Uri 'http://localhost:8083/connectors/' -Headers @{'Accept' = 'application/json'; 'Content-Type' = 'application/json'} -Body '{"name": "mssqlserver-localhost-testDb-connector", "config": {"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector", "database.hostname": "127.0.0.1", "database.port": "1433", "database.user": "svc_kafka", "database.password": "password", "database.dbname": "Posts", "database.server.name": "LT-LS231", "table.whitelist": "dbo.Posts", "database.history.kafka.bootstrap.servers": "kafka:9092", "database.history.kafka.topic": "dbhistory.LT-LS231" }}'
格式化后的JSON如下:
The formatted JSON is as follows:
Invoke-RestMethod -Method Post -Uri 'http://localhost:8083/connectors/' -Headers @{'Accept' = 'application/json'; 'Content-Type' = 'application/json'} -Body '
{
"name": "mssqlserver-localhost-testDb-connector",
"config": {
"connector.class": "io.debezium.connector.sqlserver.SqlServerConnector",
"database.hostname": "127.0.0.1",
"database.port": "1433",
"database.user": "svc_kafka",
"database.password": "password",
"database.dbname": "Posts",
"database.server.name": "LT-LS231",
"table.whitelist": "dbo.Posts",
"database.history.kafka.bootstrap.servers": "kafka:9092",
"database.history.kafka.topic": "dbhistory.LT-LS231"
}
}'
這是根據(jù) Debezium 網(wǎng)站上提供的 JSON 建模的:https://debezium.io/documentation/reference/1.1/connectors/sqlserver.html#sqlserver-deploying-a-connector
This is modeled after the JSON provided on Debezium's site: https://debezium.io/documentation/reference/1.1/connectors/sqlserver.html#sqlserver-deploying-a-connector
推薦答案
問(wèn)題在于對(duì) localhost
的引用.如果您在 Docker 容器中運(yùn)行 Connect,則 localhost
是容器的本地主機(jī),而不是機(jī)器的本地主機(jī).嘗試在 docker0
接口或所有接口上公開(kāi) SQL Server,然后在注冊(cè)請(qǐng)求中使用 docker0
IP.
The problem is in the reference to the localhost
. If you run the Connect in Docker container then the localhost
is the localhost of the container not of the machine. Try exposing the SQL Server on docker0
interface or all intefaces and then use docker0
IP in the registration request.
這篇關(guān)于Debezium 如何使用 Kafka Connect 正確注冊(cè) SqlServer 連接器 - 連接被拒絕的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!