簡體   English   中英

Kafka 使用 TLS 連接 mongoDB 接收器

[英]Kafka connect mongoDB sink with TLS

我使用 TLS 身份驗證設置了我的 mongoDB 集群。

我可以使用以下方法成功連接 mongos 實例:

/opt/cluster/stacks/mongoDB/bin/mongosh --tls --host $(hostname).domain.name -tlsCAFile /opt/cluster/security/ssl/cert.pem --port 27017

我有一個具有以下配置的 Kafka 連接 mongoDB 接收器:

{
  "name": "client-order-request-mongodb-sink",
  "config": {
    "connector.class": "com.mongodb.kafka.connect.MongoSinkConnector",
    "database":"Trading",
    "collection":"ClientOrderRequest",
    "topics":"ClientOrderRequest",
    "connection.uri":"mongodb://hostname1.domain.name:27017,pre-hostname2.domain.name:27017",
    "mongo.errors.tolerance": "all",
    "mongo.errors.log.enable": "true",
    "errors.log.include.messages": "true",
    "writemodel.strategy":"com.mongodb.kafka.connect.sink.writemodel.strategy.ReplaceOneBusinessKeyStrategy",
    "document.id.strategy": "com.mongodb.kafka.connect.sink.processor.id.strategy.PartialValueStrategy",
    "document.id.strategy.overwrite.existing": "true",
    "document.id.strategy.partial.value.projection.type": "allowlist",
    "document.id.strategy.partial.value.projection.list": "localReceiveTime,clientId,orderId"
  }
}

如果我在沒有身份驗證的情況下重新部署 mongoDB,它工作正常,但是現在當我嘗試使用以下 curl 命令實例化它時:

curl -X POST -H "Content-Type: application/json" --data '@connect-task-sink-mongodb-client-order-request.json' $KAFKA_CONNECT_LEADER_NODE/connectors/

我有以下錯誤:

{"error_code":400,"message":"連接器配置無效並包含以下 1 個錯誤:\n無法連接到服務器。\n您還可以在端點/connector-plugins/{connectorType}/config/validate找到上述錯誤列表/connector-plugins/{connectorType}/config/validate "}

mongoDB kafka 連接接收器文檔中,我發現我需要設置 KAFKA_OPTS 的全局變量,因此在啟動分布式連接服務器之前,我要做:

export KAFKA_OPTS="\
-Djavax.net.ssl.trustStore=/opt/cluster/security/ssl/keystore.jks \
-Djavax.net.ssl.trustStorePassword=\"\" \
-Djavax.net.ssl.keyStore=/opt/cluster/security/ssl/keystore.jks \
-Djavax.net.ssl.keyStorePassword=\"\""

請注意,我輸入了一個空密碼,因為當我列出我的密鑰庫的條目時:

keytool -v -list -keystore key.jks

然后我在提示密碼時按回車鍵。

所以問題是客戶端沒有啟用 ssl 連接。

如果您想使用 mongoDB kafka 連接插件執行此操作,您需要在 connection.uri 配置參數中聲明它,例如:

"connection.uri":"mongodb://hostname1.domain.name:27017,pre-hostname2.domain.name:27017/?ssl=true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM