I am following a Youtube tutorial on how to shard a MongoDB database on my local machine. The tutorial is for Mongo 2.2, and I'm on Mongo 3.4. So I'm using the following bash script to start up the shards, and the config servers and shards start fine, but my mongos processes aren't able to connect, no printed error. I know one thing that changed since Mongo 3.2 is that you have to include the replica set connection string, which I thought I did, but obviously it's not working.
#!/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
It stops running after the first mongos command. In log.mongo0 I have the following error repeated a bunch
.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
Any help is appreciated. Thank you
So, it turns out that it had to do with the error No primary detected for set configReplSet
. I added the following lines after creating the config servers:
mongo --port 26050 --eval "printjson(rs.initiate())"
mongo --port 26050 --eval "printjson(rs.status())"
From there I was able to begin creating the shards