Mongos is not starting

When I did the first lab I could normally initiate mongos.
In the second lab, with the exact Config file for mongos, it is refusing to initiate:

mongos -f mongos.conf

I get the message:

2019-07-08T17:37:58.658+0000 W SHARDING [main] Running a sharded cluster with fewer than 3 config servers should only be done for testing purposes and is not recommended for production.
about to fork child process, waiting until server is ready for connections.
forked process: 2630

And nothing happens. Then I start a new terminal, initiate “vagrant ssh” and I try:

mongo --port 26000 --username m103-admin --password m103-pass --authenticationDatabase admin

This is what I get:

MongoDB shell version v3.6.12
connecting to: mongodb://127.0.0.1:26000/?authSource=admin&gssapiServiceName=mongodb
2019-07-08T17:48:17.868+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:26000, in(checking socket for error after poll), reason: Connection refused
2019-07-08T17:48:17.869+0000 E QUERY [thread1] Error: couldn’t connect to server 127.0.0.1:26000, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

What is wrong ? and why the IP address is 127.0.0.1?
Here is monogs configuration file:

sharding:
configDB: m103-csrs/192.168.103.100:26001
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

@Ridah_97796 127.0.0.1 is the IP address of your local machine (the Vagrant VM in this case), I don’t think there’s anything wrong with that.

The message about running a sharded cluster with fewer than 3 config servers means that there’s something wrong with your config server replica set. Try connecting mongo to that replica set and run rs.status().members. That’ll return an array of the nodes in the config server replica set.

If the array has fewer than 3 elements or any of the elements has a “stateStr” property other than “PRIMARY” or “SECONDARY” then that’s your problem, you need to check that the mongod processes for each of the nodes in the config server replica set are configured correctly and running.

I found initially that some of my mongod processes were stopping at some point after I started them. I never did work out why, but shutting down the vagrant VM with vagrant halt and then restarting it seemed to solve the problem.

Hope this helps :slight_smile:

1 Like

It turned out that I have to initiate CSRS files for mongos to work :no_mouth:

Thanks though. :slightly_smiling_face:

No worries, getting 9 mongods correctly configured into 3 replica sets and playing nicely with each other and a mongos isn’t a trivial task. I certainly didn’t find it easy.

Glad you worked it out :slight_smile:

1 Like