Lab-Configure a sharded cluster

vagrant@m103:~$ ps -ef|grep mongo

vagrant 3921 1 1 15:43 ? 00:00:10 mongod -f csrs_1.conf
vagrant 4005 1 1 15:43 ? 00:00:08 mongod -f csrs_2.conf
vagrant 4104 1 1 15:44 ? 00:00:09 mongod -f csrs_3.conf
vagrant 4224 1 0 15:45 ? 00:00:01 mongos -f mongos.conf
vagrant 4546 3897 0 15:57 pts/0 00:00:00 grep --color=auto mongo

vagrant@m103:~$ mongo --port 27002 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

when iam typing above command ,iam getting error like this

MongoDB shell version v3.6.16
connecting to: mongodb://127.0.0.1:27002/?authSource=admin&gssapiServiceName=mongodb
2020-01-08T15:59:43.073+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27002, in(checking socket for error after poll), reason: Connection refused
2020-01-08T15:59:43.074+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:27002, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

Hi @SUJANA_42894,

If you are following the lab instructions then csrs_1.conf, csrs_2.conf and csrs_3.conf should be running on ports 26001, 26002 and 26003 respectively. The mongos should be running on port 26000.

In the output of ps -ef|grep mongo command, I don’t see any other process running.

Can you please make sure that a mongod instance is running on port 27002 before you try to connect to it ?

Thanks,
Shubham Ranjan
Curriculum Services Engineer

1)Bring up the config server replica set (CSRS)

csrs_1.conf
vi csrs_1.conf

sharding:
clusterRole: configsvr
replication:
replSetName: m103-csrs
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: localhost,192.168.103.100
port: 26001
systemLog:
destination: file
path: /var/mongodb/db/csrs1/mongod.log
logAppend: true
processManagement:
fork: true
storage:
dbPath: /var/mongodb/db/csrs1

cp csrs_1.conf csrs_2.conf
cp csrs_1.conf csrs_3.conf
vi csrs_2.conf
vi csrs_3.conf
mkdir /var/mongodb/db/{csrs1,csrs2,csrs3}

mongod -f csrs_1.conf
mongod -f csrs_2.conf
mongod -f csrs_3.conf

mongo --port 26001
rs.initiate()
use admin
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

db.auth(“m103-admin”,“m103-pass”)

exit

mongo --host “m103-csrs/192.168.103.100:26001” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

rs.status()

rs.add(“m103:26002”)
rs.add(“m103:26003”)

  1. Bring up the mongos

mongos.conf
vi mongos.conf

sharding:
configDB: m103-csrs/192.168.103.100:26001,192.168.103.100:26002,192.168.103.100:26003
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: localhost,192.168.103.100
port: 26000
systemLog:
destination: file
path: /var/mongodb/db/mongos.log
logAppend: true
processManagement:
fork: true

mongos -f mongos.conf

  1. Reconfigure m103-repl

storage:
dbPath: /var/mongodb/db/1
net:
bindIp: 192.168.103.100,localhost
port: 27001
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod1.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
sharding:
clusterRole: shardsvr
storage:
wiredTiger:
engineConfig:
cacheSizeGB: .1

vi mongod-repl-1.conf
vi mongod-repl-2.conf
vi mongod-repl-3.conf

vagrant@m103:~$ mongod -f mongod-repl-1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3984
child process started successfully, parent exiting

vagrant@m103:~$ mongod -f mongod-repl-2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4081
ERROR: child process failed, exited with error number 51
To see additional information in this output, start without the “–fork” option.

when iam typing above command for lab

Here iam getting error

vagrant@m103:~$ ps -ef|grep mongo
vagrant 3631 1 1 16:12 ? 00:00:07 mongod -f csrs_1.conf
vagrant 3667 1 1 16:12 ? 00:00:07 mongod -f csrs_2.conf
vagrant 3808 1 1 16:12 ? 00:00:05 mongod -f csrs_3.conf
vagrant 3940 1 0 16:14 ? 00:00:00 mongos -f mongos.conf
vagrant 3984 1 1 16:15 ? 00:00:05 mongod -f mongod-repl-1.conf
vagrant 4228 2462 0 16:21 pts/0 00:00:00 grep --color=auto mongo

vagrant@m103:~$ cat /var/mongodb/db/mongod2.log

when iam typing above command

2020-01-09T16:54:59.273+0000 I CONTROL [initandlisten] options: { config: “mongod-repl-2.conf”, net: { bindIp: “192.168.103.100,localhost”, port: 27002 }, processManagement: { fork: true }, replication: { replSetName: “m103-repl” }, security: { authorization: “enabled”, keyFile: “/var/mongodb/pki/m103-keyfile” }, sharding: { clusterRole: “shardsvr” }, storage: { dbPath: “/var/mongodb/db/1”, wiredTiger: { engineConfig: { cacheSizeGB: 0.1 } } }, systemLog: { destination: “file”, logAppend: true, path: “/var/mongodb/db/mongod2.log” } }
2020-01-09T16:54:59.273+0000 I STORAGE [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /var/mongodb/db/1/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /var/mongodb/db/1 directory, terminating
2020-01-09T16:54:59.273+0000 F - [initandlisten] Invariant failure globalStorageEngine src/mongo/db/service_context_d.cpp 272
2020-01-09T16:54:59.273+0000 F - [initandlisten]

From your log
“Another mongod instance is already running on the /var/mongodb/db/1 directory, terminating”

Please make sure no other instance is running on the same port
If you have any previous mongods running on same port kill it and restart

Hi @SUJANA_42894,

Based on what you have shared above,

dbPath for mongod-repl-1.conf :

dbPath for mongod-repl-2.conf :

As you can see, both are using the same dbPath. I think by mistake you forgot to change it. In addition to this, please make sure that you have also changed the dbPath in mongod-repl-3.conf accordingly.

Hope it helps!

Please feel free to get back to us if you have any other query.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

Thank you very much.

I resolved it.

You are correct.I wrote this storage: { dbPath: “/var/mongodb/db/1”, wrong in mongod-repl-2.conf file.