Skip to content

docker 搭建 replicaset 无法使用主机ip问题 #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xujiang1 opened this issue Jun 15, 2020 · 1 comment
Closed

docker 搭建 replicaset 无法使用主机ip问题 #410

xujiang1 opened this issue Jun 15, 2020 · 1 comment
Labels
question Usability question, not directly related to an error with the image

Comments

@xujiang1
Copy link

xujiang1 commented Jun 15, 2020

我有一个主机 192.168.31.206 在上面使用docker搭建了3个节点 ip分别为:

/2_mongo_shard2 - 172.17.0.4

/1_mongo_shard2 - 172.17.0.3

/0_mongo_shard2 - 172.17.0.2

mongodb 配置文件为:

[root@vipsc-159 config]# cat mongod.conf

systemLog:
  destination: file
  logAppend: true
  path: /data/log/mongod.log
storage:
  dbPath: /data/db
  journal:
    enabled: true
  directoryPerDB: true
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 10
      journalCompressor: snappy
      directoryForIndexes: true
    collectionConfig:
      blockCompressor: snappy
    indexConfig:
      prefixCompression: true
net:
  bindIp: 0.0.0.0
  port: 27018
replication:
  oplogSizeMB: 10240
  replSetName: rs2
sharding:
  clusterRole: shardsvr

processManagement:
  fork: false
  pidFilePath: /data/pid/shard2.pid

使用docker-compose启动:

[root@vipsc-159 docker_compose_yaml]# cat mongo_shard2.yml
shard2:
  image: mongo:4.2.7
  container_name: 0_mongo_shard2
  volumes:
    - /usr/local/vipcloud/data/data1/dockervolumes/shard2/config:/etc/mongod
    - /usr/local/vipcloud/data/data1/dockervolumes/shard2/data:/data
  ports:
    - 32018:27018
  command: mongod -f /etc/mongod/mongod.conf

我将3个docker的端口分别映射到32018,32118,32218
但是当我初始化 replicaset时无法通过主机ip进行初始化:

rs.initiate(
    {
        _id: "rs2",
        members: [
            { _id: 0, host: "192.168.31.206:32018", priority: 10 },
            { _id: 1, host: "192.168.31.206:32118", arbiterOnly: true },
            { _id: 2, host: "192.168.31.206:32218", priority: 1 }
        ]
    }
)

会报错

{ 
    "operationTime" : Timestamp(0, 0), 
    "ok" : 0.0, 
    "errmsg" : "No host described in new configuration 1 for replica set rs2 maps to this node", 
    "code" : 93.0, 
    "codeName" : "InvalidReplicaSetConfig", 
    "$clusterTime" : {
        "clusterTime" : Timestamp(0, 0), 
        "signature" : {
            "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="), 
            "keyId" : 0
        }
    }
}

但是 可以通过docker的ip进行初始化

rs.initiate(
    {
        _id: "rs2",
        members: [
            { _id: 0, host: "172.17.0.4:32018", priority: 10 },
            { _id: 1, host: "172.17.0.3:32118", arbiterOnly: true },
            { _id: 2, host: "172.17.0.2:32218", priority: 1 }
        ]
    }
)

为什么

如果我希望通过192.168.31.206初始化成功 我应该怎么做

希望得到大家的帮助

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Jun 15, 2020
@wglambert
Copy link

I would try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow. Since these repos aren't really a user-help forum

#246 (comment)

Adding automation for setting up a replica set is not something we want to add to the image since it requires an external service like consul in order to reliably coordinate which is the first and where to join.

Other issue about replicasets #339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

2 participants