Mongodb 主节点未在 Debezium Kafka Connect 中解析 — Docker Compose

Mongodb 主节点未在 Debezium Kafka Connect 中解析 — Docker Compose

我有这个docker compose文件,其中包含bitnami/mongodb用于创建副本集的容器。并且我已经使用zookeeperkafkadebezium-connector来监控我的mongodb副本集。

version: '2.2'
services:
    mongodb-primary:
        hostname: mongodb-primary
        image: 'bitnami/mongodb:latest'
        ports:
            - 27017:27017
        environment:
            - MONGODB_REPLICA_SET_NAME=rs0
            - MONGODB_REPLICA_SET_MODE=primary
            - MONGODB_ROOT_PASSWORD=another_root
            - MONGODB_DATABASE=genomics
            - MONGODB_REPLICA_SET_KEY=replicasetkey123
            - MONGODB_USERNAME=genomics_user
            - MONGODB_PASSWORD=another
            - MONGODB_ADVERTISED_HOSTNAME=mongodb-primary
        volumes:
            - 'mongodb_master_data:/bitnami'
    mongodb-secondary:
        hostname: mongodb-secondary
        image: 'bitnami/mongodb:latest'
        depends_on:
            - mongodb-primary
        environment:
            - MONGODB_REPLICA_SET_NAME=rs0
            - MONGODB_REPLICA_SET_MODE=secondary
            - MONGODB_PRIMARY_HOST=mongodb-primary
            - MONGODB_PRIMARY_PORT_NUMBER=27017
            - MONGODB_PRIMARY_ROOT_PASSWORD=another_root
            - MONGODB_REPLICA_SET_KEY=replicasetkey123
            - MONGODB_USERNAME=genomics_user
            - MONGODB_PASSWORD=another
            - MONGODB_DATABASE=genomics
            - MONGODB_ADVERTISED_HOSTNAME=mongodb-secondary
    mongodb-arbiter:
        hostname: mongodb-arbiter
        image: 'bitnami/mongodb:latest'
        depends_on:
            - mongodb-primary
        environment:
            - MONGODB_REPLICA_SET_NAME=rs0
            - MONGODB_REPLICA_SET_MODE=arbiter
            - MONGODB_PRIMARY_HOST=mongodb-primary
            - MONGODB_PRIMARY_PORT_NUMBER=27017
            - MONGODB_PRIMARY_ROOT_PASSWORD=another_root
            - MONGODB_REPLICA_SET_KEY=replicasetkey123
            - MONGODB_USERNAME=genomics_user
            - MONGODB_PASSWORD=another
            - MONGODB_DATABASE=genomics
            - MONGODB_ADVERTISED_HOSTNAME=mongodb-arbiter
    debezium_connect:
        image: debezium/connect:0.7
        ports:
            - 8083:8083
        environment:
            - BOOTSTRAP_SERVERS=kafka:9092
            - GROUP_ID=1
            - CONFIG_STORAGE_TOPIC=my_connect_configs
            - OFFSET_STORAGE_TOPIC=my_connect_offsets
        links:
            - kafka
            - mongodb-primary
    kafka:
        image: debezium/kafka:0.7
        environment:
            KAFKA_ADVERTISED_HOST_NAME: kafka
            KAFKA_ADVERTISED_PORT: 9092
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
            ZOOKEEPER_CONNECT: zookeeper:2181
            KAFKA_CREATE_TOPICS: "topic-jhipster:1:1"
        ports:
            - 9092:9092
        links:
            - zookeeper
    zookeeper:
        image: debezium/zookeeper:0.7
        ports:
            - 2181:2181
            - 2888:2888
            - 3888:3888
    consul:
        image: consul:0.9.3
        command: consul agent -dev -ui -client 0.0.0.0
        ports:
            - 8300:8300
            - 8500:8500
            - 8600:8600
    consul-config-loader:
        image: jhipster/consul-config-loader:v0.2.2
        volumes:
            - ./central-server-config:/config
        environment:
            - INIT_SLEEP_SECONDS=5
            - CONSUL_URL=consul
            - CONSUL_PORT=8500
        # Uncomment to load configuration into Consul from a Git repository
        # as configured in central-server-config/git2consul.json
        # Also set SPRING_CLOUD_CONSUL_CONFIG_FORMAT=files on your apps
        #    - CONFIG_MODE=git

volumes:
    mongodb_master_data:
        driver: local

# networks:
#     app-tier:
#         driver: bridge

所以我通过以下方式启动了这个文件

docker-compose -f app.yaml up

现在debezium_connect图像已准备好接受 mongodb 连接器属性:

{
    "name": "run-connector",
    "config": {
        "connector.class" : "io.debezium.connector.mongodb.MongoDbConnector",
        "tasks.max" : "1",
        "mongodb.hosts" : "rs0/mongodb-primary:27017",
        "mongodb.name" : "genomics",
        "mongodb.user" : "genomics_user",
        "mongodb.password" : "another",
        "database.whitelist" : "inventory",
        "database.history.kafka.bootstrap.servers" : "kafka:9092"
    }
}

通过使用以下命令完成:

curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-mongodb.json

其中的register-mongodb.json内容显示在上方。但是在 curl 之后,debezium_connect 出现此错误:

2018-06-05 15:49:35,080 INFO   MongoDB|genomics|disc  No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=mongodb-primary:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='genomics_user', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server mongodb-primary:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed", "operationTime" : { "$timestamp" : { "t" : 1528213769, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1528213769, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "vSvTuw+hQCycX/rSliCcxWEh1BM=", "$type" : "00" }, "keyId" : { "$numberLong" : "6563606422322413569" } } } }}}]}. Waiting for 30000 ms before timing out   [org.mongodb.driver.cluster]
2018-06-05 15:50:05,081 ERROR  MongoDB|genomics|disc  Error while reading the 'shards' collection in the 'config' database: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb-primary:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='genomics_user', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server mongodb-primary:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed", "operationTime" : { "$timestamp" : { "t" : 1528213799, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1528213799, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "tk+Fd4ytnt/O8TMDyG43h79fnkk=", "$type" : "00" }, "keyId" : { "$numberLong" : "6563606422322413569" } } } }}}]   [io.debezium.connector.mongodb.ReplicaSetDiscovery]
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb-primary:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='genomics_user', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server mongodb-primary:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed", "operationTime" : { "$timestamp" : { "t" : 1528213799, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1528213799, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "tk+Fd4ytnt/O8TMDyG43h79fnkk=", "$type" : "00" }, "keyId" : { "$numberLong" : "6563606422322413569" } } } }}}]
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377)
    at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
    at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:402)
    at com.mongodb.operation.ListDatabasesOperation.execute(ListDatabasesOperation.java:102)
    at com.mongodb.operation.ListDatabasesOperation.execute(ListDatabasesOperation.java:54)
    at com.mongodb.Mongo.execute(Mongo.java:836)
    at com.mongodb.Mongo$2.execute(Mongo.java:823)
    at com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
    at com.mongodb.ListDatabasesIterableImpl.iterator(ListDatabasesIterableImpl.java:57)
    at com.mongodb.MappingIterable.iterator(MappingIterable.java:36)
    at io.debezium.connector.mongodb.MongoUtil.contains(MongoUtil.java:181)
    at io.debezium.connector.mongodb.MongoUtil.contains(MongoUtil.java:170)
    at io.debezium.connector.mongodb.MongoUtil.onDatabase(MongoUtil.java:114)
    at io.debezium.connector.mongodb.MongoUtil.onCollection(MongoUtil.java:129)
    at io.debezium.connector.mongodb.MongoUtil.onCollectionDocuments(MongoUtil.java:148)
    at io.debezium.connector.mongodb.ReplicaSetDiscovery.getReplicaSets(ReplicaSetDiscovery.java:67)
    at io.debezium.connector.mongodb.ReplicaSetMonitorThread.run(ReplicaSetMonitorThread.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
2018-06-05 15:50:05,082 INFO   MongoDB|genomics|disc  Cluster description not yet available. Waiting for 30000 ms before timing out   [org.mongodb.driver.cluster]

我的网络有问题吗?我认为 debezium_connect 看不到 mongodb-primary,因此无法进行身份验证。

您可以通过以下命令删除现有的“run-connector”:

curl -X DELETE localhost:8083/connectors/run-connector/

我可以通过其他第三方工具(例如robo3t我自己编写的其他应用程序)对 mongo-replica-set 进行身份验证。但无法 debezium_connect在 docker 网络中执行此操作。还应注意,我自己编写的应用程序在 docker 网络中连接到 mongodb 没有任何问题。

答案1

这是由于身份验证错误导致的。抛出了以下异常:

命令失败,错误 18:“身份验证失败。”在服务器 mongodb-primary:27017 上

请再次检查您的用户名和密码。

答案2

您确定已启动 MongoDB 并为您的用户提供必要的权限吗?请使用http://debezium.io/docs/connectors/mongodb/#setting-up-mongodb

相关内容