我正在跟踪一个
Youtube tutorial
关于如何在本地机器上共享MongoDB数据库。本教程针对的是Mongo 2.2,我使用的是Mongo3.4。因此,我使用以下bash脚本启动碎片,配置服务器和碎片启动良好,但我的mongos进程无法连接,没有打印错误。我知道,自从Mongo 3.2以来,有一件事发生了变化,那就是必须包含副本集连接字符串,我以为我已经包含了,但显然它不起作用。
#!/bin/bash
# Create the directories that the shards will run in
# We will have 4 shards, with a replication factor of 3
mkdir a0 a1 a2
mkdir b0 b1 b2
mkdir c0 c1 c2
mkdir d0 d1 d2
# Create the three configuration server folders
mkdir cfg0 cfg1 cfg2
# Common variables
replSet="configReplSet"
hostname="127.0.0.1"
# Configure the config servers
mongod --configsvr --replSet ${replSet} --dbpath cfg0 --port 26050 --fork --logpath log.cfg0 --logappend
mongod --configsvr --replSet ${replSet} --dbpath cfg1 --port 26051 --fork --logpath log.cfg1 --logappend
mongod --configsvr --replSet ${replSet} --dbpath cfg2 --port 26052 --fork --logpath log.cfg2 --logappend
# Set up shard servers
mongod --shardsvr --replSet a --dbpath a0 --logpath log.a0 --port 27000 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet a --dbpath a1 --logpath log.a1 --port 27001 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet a --dbpath a2 --logpath log.a2 --port 27002 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet b --dbpath b0 --logpath log.b0 --port 27100 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet b --dbpath b1 --logpath log.b1 --port 27101 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet b --dbpath b2 --logpath log.b2 --port 27102 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet c --dbpath c0 --logpath log.c0 --port 27200 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet c --dbpath c1 --logpath log.c1 --port 27201 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet c --dbpath c2 --logpath log.c2 --port 27202 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet d --dbpath d0 --logpath log.d0 --port 27300 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet d --dbpath d1 --logpath log.d1 --port 27301 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet d --dbpath d2 --logpath log.d2 --port 27302 --fork --logappend --oplogSize 50
mongos --configdb ${replSet}/${hostname}:26050,${hostname}:26051,${hostname}:26052 --fork --logappend --logpath log.mongos0 --port 27017
mongos --configdb ${replSet}/${hostname}:26050,${hostname}:26051,${hostname}:26052 --fork --logappend --logpath log.mongos1 --port 26061
mongos --configdb ${replSet}/${hostname}:26050,${hostname}:26051,${hostname}:26052 --fork --logappend --logpath log.mongos2 --port 26062
mongos --configdb ${replSet}/${hostname}:26050,${hostname}:26051,${hostname}:26052 --fork --logappend --logpath log.mongos3 --port 26063
它在第一个mongos命令后停止运行。在日志中。mongo0我重复了一系列以下错误
.841-0400 W NETWORK [mongosMain] Failed to connect to 127.0.0.1:26050, in(checking socket for error after poll), reason: Connection refused
2017-06-28T15:38:01.841-0400 W NETWORK [mongosMain] Failed to connect to 127.0.0.1:26051, in(checking socket for error after poll), reason: Connection refused
2017-06-28T15:38:01.841-0400 W NETWORK [mongosMain] No primary detected for set configReplSet