sharding mogodb using docker container :docker-compose MongoDB Error: network error while attempting to run command 'isMaster' on host
sharding mogodb using docker container :docker-compose MongoDB Error: network error while attempting to run command 'isMaster' on host
我正在尝试分片 mongodbs。在使用路由器连接时,我复制了配置服务器和 shards.But,我得到 "Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:60001'"。我试过 但仍然遇到同样的错误。我是 mongodb
的新手
我正在为每个 mongo 个实例使用 docker 个容器
这是 .yaml 文件
""""
version: '3'
services:
cfgsvr1:
container_name: cfgsvr1
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40001:27017
volumes:
- cfgsvr1:/data/db
cfgsvr2:
container_name: cfgsvr2
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40002:27017
volumes:
- cfgsvr2:/data/db
cfgsvr3:
container_name: cfgsvr3
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40003:27017
volumes:
- cfgsvr3:/data/db
volumes:
cfgsvr1: {}
cfgsvr2: {}
cfgsvr3: {}
version: '3'
services:
mongos:
container_name: mongos
image: mongo
command: mongos --bind_ip_all --port 27017 --configdb cfgrs/cfgsvr3:27017,cfgsvr2:27017,cfgsvr1:27017
ports:
- 60001:27017
version: '3'
services:
shard1svr1:
container_name: shard1svr1
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50001:27017
volumes:
- shard1svr1:/data/db
shard1svr2:
container_name: shard1svr2
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50002:27017
volumes:
- shard1svr2:/data/db
shard1svr3:
container_name: shard1svr3
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50003:27017
volumes:
- shard1svr3:/data/db
volumes:
shard1svr1: {}
shard1svr2: {}
shard1svr3: {}
version: '3'
services:
shard2svr1:
container_name: shard2svr1
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50004:27017
volumes:
- shard2svr1:/data/db
shard2svr2:
container_name: shard2svr2
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50005:27017
volumes:
- shard2svr2:/data/db
shard2svr3:
container_name: shard2svr3
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50006:27017
volumes:
- shard2svr3:/data/db
volumes:
shard2svr1: {}
shard2svr2: {}
shard2svr3: {}
""""
我的 ubuntu 版本是 18.04
我的数据库版本是 3.6.3
我的 shell 版本是 3.6.3
日志
mongos | 2019-12-19T09:14:24.527+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr3:27017
mongos | 2019-12-19T09:14:24.527+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr1:27017
mongos | 2019-12-19T09:14:24.536+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
mongos | 2019-12-19T09:14:25.027+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr2:27017
mongos | 2019-12-19T09:14:25.033+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
mongos | 2019-12-19T09:14:25.539+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
在没有“configsvr: true”的情况下复制 config server 时发现错误
和
sh.addShard("shard_replica/shard1,shard2,shard3")
sh.addShard("shard_replica2/shard4,shard5,shard6")
version: '2'
services:
shard1:
container_name: shard1
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 40001:27017
environment:
TERM: xterm
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data1:/data/db
shard2:
container_name: shard2
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 40002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data2:/data/db
shard3:
container_name: shard3
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 40003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data3:/data/db
cfg1:
container_name: cfg1
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 50001:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config1:/data/db
cfg2:
container_name: cfg2
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 50002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config2:/data/db
cfg3:
container_name: cfg3
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 50003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config3:/data/db
shard4:
container_name: shard4
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 30001:27017
environment:
TERM: xterm
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data4:/data/db
shard5:
container_name: shard5
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 30002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data5:/data/db
shard6:
container_name: shard6
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 30003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data6:/data/db
mongos:
container_name: mongos
image: mongo
depends_on:
- cfg1
- cfg2
- cfg3
- shard1
- shard2
- shard3
- shard4
- shard5
- shard6
command: mongos --configdb conf_replica/cfg1:27017,cfg2:27017,cfg3:27017 --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 27019:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
我正在尝试分片 mongodbs。在使用路由器连接时,我复制了配置服务器和 shards.But,我得到 "Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:60001'"。我试过
我正在为每个 mongo 个实例使用 docker 个容器 这是 .yaml 文件
""""
version: '3'
services:
cfgsvr1:
container_name: cfgsvr1
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40001:27017
volumes:
- cfgsvr1:/data/db
cfgsvr2:
container_name: cfgsvr2
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40002:27017
volumes:
- cfgsvr2:/data/db
cfgsvr3:
container_name: cfgsvr3
image: mongo
command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db
ports:
- 40003:27017
volumes:
- cfgsvr3:/data/db
volumes:
cfgsvr1: {}
cfgsvr2: {}
cfgsvr3: {}
version: '3'
services:
mongos:
container_name: mongos
image: mongo
command: mongos --bind_ip_all --port 27017 --configdb cfgrs/cfgsvr3:27017,cfgsvr2:27017,cfgsvr1:27017
ports:
- 60001:27017
version: '3'
services:
shard1svr1:
container_name: shard1svr1
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50001:27017
volumes:
- shard1svr1:/data/db
shard1svr2:
container_name: shard1svr2
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50002:27017
volumes:
- shard1svr2:/data/db
shard1svr3:
container_name: shard1svr3
image: mongo
command: mongod --shardsvr --replSet shard1rs --port 27017 --dbpath /data/db
ports:
- 50003:27017
volumes:
- shard1svr3:/data/db
volumes:
shard1svr1: {}
shard1svr2: {}
shard1svr3: {}
version: '3'
services:
shard2svr1:
container_name: shard2svr1
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50004:27017
volumes:
- shard2svr1:/data/db
shard2svr2:
container_name: shard2svr2
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50005:27017
volumes:
- shard2svr2:/data/db
shard2svr3:
container_name: shard2svr3
image: mongo
command: mongod --shardsvr --replSet shard2rs --port 27017 --dbpath /data/db
ports:
- 50006:27017
volumes:
- shard2svr3:/data/db
volumes:
shard2svr1: {}
shard2svr2: {}
shard2svr3: {}
"""" 我的 ubuntu 版本是 18.04 我的数据库版本是 3.6.3 我的 shell 版本是 3.6.3 日志
mongos | 2019-12-19T09:14:24.527+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr3:27017
mongos | 2019-12-19T09:14:24.527+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr1:27017
mongos | 2019-12-19T09:14:24.536+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
mongos | 2019-12-19T09:14:25.027+0000 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cfgsvr2:27017
mongos | 2019-12-19T09:14:25.033+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
mongos | 2019-12-19T09:14:25.539+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set cfgrs
在没有“configsvr: true”的情况下复制 config server 时发现错误 和
sh.addShard("shard_replica/shard1,shard2,shard3")
sh.addShard("shard_replica2/shard4,shard5,shard6")
version: '2'
services:
shard1:
container_name: shard1
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 40001:27017
environment:
TERM: xterm
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data1:/data/db
shard2:
container_name: shard2
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 40002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data2:/data/db
shard3:
container_name: shard3
image: mongo
command: mongod --shardsvr --replSet shard_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 40003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data3:/data/db
cfg1:
container_name: cfg1
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 50001:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config1:/data/db
cfg2:
container_name: cfg2
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 50002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config2:/data/db
cfg3:
container_name: cfg3
image: mongo
command: mongod --configsvr --replSet conf_replica --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 50003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/config3:/data/db
shard4:
container_name: shard4
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
ports:
- 30001:27017
environment:
TERM: xterm
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data4:/data/db
shard5:
container_name: shard5
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 30002:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data5:/data/db
shard6:
container_name: shard6
image: mongo
command: mongod --shardsvr --replSet shard_replica2 --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 30003:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/Chinmay/Documents/Chinmay/learn-mongodb/new/data6:/data/db
mongos:
container_name: mongos
image: mongo
depends_on:
- cfg1
- cfg2
- cfg3
- shard1
- shard2
- shard3
- shard4
- shard5
- shard6
command: mongos --configdb conf_replica/cfg1:27017,cfg2:27017,cfg3:27017 --port 27017 --bind_ip 0.0.0.0
environment:
TERM: xterm
ports:
- 27019:27017
expose:
- "27017"
volumes:
- /etc/localtime:/etc/localtime:ro