无法访问set mongo config server的任何节点

时间:2018-03-14 21:53:19

标签: mongodb sharding

我想通过docker-compose部署包含1个mongo shard(副本集),1个configserver(副本集)和1个路由器的mongo集群。我有一个问题,它是“无法达到设置mongoconfigserver的主要”。 我发现了一个问题: Unable to launch mongos,但在这种情况下,config-server没有副本集,而我在命令中需要“--replSet mongoconfigserver”选项。

这是我的docker-compose.yml:

version: '3'
services:
  # Config servers for metadata
  mongoconfigserver-01:
    container_name: mongoconfigserver-01
    image: mongo
    command: mongod --configsvr --replSet mongoconfigserver --dbpath /data/db --port 27017
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/config1:/data/db
  mongoconfigserver-02:
    container_name: mongoconfigserver-02
    image: mongo
    command: mongod --configsvr --replSet mongoconfigserver --dbpath /data/db --port 27017
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/config2:/data/db
  mongoconfigserver-03:
    container_name: mongoconfigserver-03
    image: mongo
    command: mongod --configsvr --replSet mongoconfigserver --dbpath /data/db --port 27017
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/config3:/data/db    
  # First shard 
  mongo-shard-01a:
    image: mongo

    command: mongod --port 27018 --replSet mongo-shard-01 --dbpath /data/db
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/data1:/data/db
    ports:
        - 27017:27017
  mongo-shard-01b:
    image: mongo
    command: mongod --port 27018 --replSet mongo-shard-01 --dbpath /data/db
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/data2:/data/db
    ports:
        - 27027:27017
  mongo-shard-01c:
    image: mongo
    command: mongod --port 27018 --replSet mongo-shard-01 --dbpath /data/db
    volumes:
        - /etc/localtime:/etc/localtime:ro
        - /mongo_cluster/data3:/data/db
    ports:
        - 27037:27017
  # Mongo router
  mongo-router-01:
    container_name: mongo-router-01
    image: mongo
    depends_on:
        - mongoconfigserver-01
        - mongoconfigserver-02
        - mongoconfigserver-03
        - mongo-shard-01a
        - mongo-shard-01b
        - mongo-shard-01c
    command: mongos --configdb mongoconfigserver/mongoconfigserver-01:27017,mongoconfigserver-02:27017,mongoconfigserver-03:27017
    volumes:
        - /etc/localtime:/etc/localtime:ro

和日志:

mongo-router-01         | 2018-03-14T22:46:40.857+0100 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to mongoconfigserver-02:27017 (1 connections now open to mongoconfigserver-02:27017 with a 5 second timeout)
mongo-router-01         | 2018-03-14T22:46:40.857+0100 I NETWORK  [shard registry reload] Successfully connected to mongoconfigserver-03:27017 (1 connections now open to mongoconfigserver-03:27017 with a 5 second timeout)
mongo-router-01         | 2018-03-14T22:46:40.857+0100 I NETWORK  [monitoring keys for HMAC] Successfully connected to mongoconfigserver-01:27017 (1 connections now open to mongoconfigserver-01:27017 with a 5 second timeout)
mongo-router-01         | 2018-03-14T22:46:40.858+0100 W NETWORK  [monitoring keys for HMAC] Unable to reach primary for set mongoconfigserver
mongo-router-01         | 2018-03-14T22:46:41.359+0100 W NETWORK  [mongosMain] Unable to reach primary for set mongoconfigserver
mongo-router-01         | 2018-03-14T22:46:41.359+0100 I NETWORK  [mongosMain] Cannot reach any nodes for set mongoconfigserver. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
mongo-router-01         | 2018-03-14T22:46:41.860+0100 W NETWORK  [mongosMain] Unable to reach primary for set mongoconfigserver

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

在配置服务器中设置以下参数。

use admin
config = {
    _id : "configs",
    members : [
    {_id : 0, host : "ip:21000" },
    {_id : 1, host : "ip:21000" },
    {_id : 2, host : "ip:21000" }
    ]
}
rs.initiate(config);