I am trying to set up a 3 node MongoDB cluster.
1) Started mongodb in all 3 nodes with the below config file.
net:
bindIp: 0.0.0.0
port: 10901
setParameter:
enableLocalhostAuthBypass: false
systemLog:
destination: file
path: "<LOG_PATH>"
logAppend: true
processManagement:
fork: true
storage:
dbPath: "<DB_PATH>/data"
journal:
enabled: true
security:
keyFile : "<KEY_FILE_PATH>"
sharding:
clusterRole: "configsvr"
replication:
replSetName: "configReplSet"
2) Created Admin user in one of the config node; confirmed I am able to log in with the admin user:
mongo --port 10901 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
now the console says user:PRIMARY>
3) Initiated the replica set using the below command.
rs.initiate(
{
_id: "configReplSet",
configsvr: true,
members: [
{ _id : 0, host : "<IP1>:10901" },
{ _id : 1, host : "<IP2>:10901" },
{ _id : 2, host : "<IP3>:10901" }
]
}
)
4) Executed rs.status() and got the proper output.
5) Started the mongod shard nodes with the below config in all 3 instances.
net:
bindIp: 0.0.0.0
port: 10903
setParameter:
enableLocalhostAuthBypass: false
systemLog:
destination: file
path: "<LOG_PATH>"
logAppend: true
processManagement:
fork: true
storage:
dbPath: "<DB_PATH>/shard_data/"
journal:
enabled: true
security:
keyFile : "<KEY_FILE>"
sharding:
clusterRole: "shardsvr"
replication:
replSetName: "shardReplSet"
6) Created Admin user in one of the shard nodes also, and confirmed I am able to login with the admin user:
mongo --port 10903 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
7) Initiated the shard replica set using the below command:
rs.initiate(
{
_id: "shardReplSet",
members: [
{ _id : 0, host : "<IP1>:10903" },
{ _id : 1, host : "<IP2>:10903" },
{ _id : 2, host : "<IP3>:10903" }
]
}
)
8) Started the mongos router with the below config:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: <LOG_PATH_FOR_MONGOS>
# network interfaces
net:
port: 10902
security:
keyFile: <KEY_FILE>
processManagement:
fork: true
sharding:
configDB: configReplSet/<IP1>:10901,<IP2>:10901,<IP3>:10901
9) Connected to mongos using the mongo client:
mongo --port 10902 -u "admin" -p "adminpwd" --authenticationDatabase "admin" --host <IP>
Now, I see the below in my terminal.
MongoDB server version: 3.4.2
mongos>
10) Added the shard in the mongos interface:
sh.addShard("shardReplSet/<IP1>:10903, <IP2>:10903, <IP3>:10903")
Issues :-
1) I am unable to connect to mongos from a remote machine
I am able to connect to mongos on each of the three nodes:
From Node1:
mongo --port 10902 -u "user" -p "password" --authenticationDatabase "admin" --host <Node1>
mongo --port 10902 -u "user" -p "password" --authenticationDatabase "admin" --host <Node2>
mongo --port 10902 -u "user" -p "password" --authenticationDatabase "admin" --host <Node3>
All the above 3 connections are working from Node1, from Node2, and from Node3.
But if I try from my localhost to connect to these instances, I get timeout errors; even though I am able to ssh to these servers.
2) I am running the config nodes on port 10901, shard nodes on port 10903, and the mongos router on port 10902. Each host is running a config mongod node, a shard mongod node and a mongos router. Is this OK?
3) On each host, the DB path for the config node and the shard node are different. I have to create the admin user on each service (config, shard, router). Is this correct?
4) I have created a replica set for config and a replica set for the shard, but not for the mongos router - is this OK?
5) I am unable to connect to these instances from a remote MongoChef tool. This connection was on the router port - is this correct? If so, do I need to run the mongos router on each node?
6) Do we need to connect to the port 10903 or 10902 or 10901 to create new databases, and to create new users for databases?
7) Is there anything else important to be added here?