0

I'm trying to create an replicated sharded cluster in mongodb. Initially I've created two shards and there are a replica set with three members in each shard. And all the shards and replicasets run in a single machine. I followed

http://docs.mongodb.org/manual/tutorial/convert-replica-set-to-replicated-shard-cluster/

to deploy this structure and that worked perfectly.

But as I'm running my mongodb in an AWS instance for a business application and I'm connecting my node.js server with the database, I want to load balance the database within multiple aws instance so that the database works fine even in huge traffic load and even if one instance becomes unhealthy or unavailable, I'll be able to access the database from the replicaset running in other instances.

Depending on the suggestions of different users in my previous question

http://stackoverflow.com/questions/24671205/mongodb-load-balancing-in-multiple-aws-instances

I'm trying to divide the database in shards and each shard will have a replicaSet with 3 or more members running in separate aws instances. To create this structure, I tried to deploy it locally at first.

I've two replicasets firstset & secondset

The firstset has three members 192.168.1.10:27018(Primary), 192.168.1.11.27018(Secondary) & 192.168.1.9:27018(arbiter)

And the secondset has three members 192.168.1.6:27019(Primary), 192.168.1.9:27019(Secondary) & 192.169.1.11:27019(arbiter)

To create the firstset replica I've written

mongod --dbpath /replica-data --port 27018 --replSet firstset --oplogSize 10

in 192.168.1.10, 192.168.1.11 & 192.168.1.9

Then to initiate the replica set I've written

mongo --port 27018

in 192.168.1.10 and then,

use admin

db.runCommand({
 "replSetInitiate": {
    "_id": "firstset",
    "members": [{
         "_id": 1,
         "host": "192.168.1.10:27018",
         "priority": 10
         }, {
         "_id": 2,
         "host": "192.168.1.11:27018",
         "priority": 2
         }, {
         "_id": 3,
         "host": "192.168.1.9:27018",
         "priority": 1,
         "arbiterOnly": true
         }]
         }
    });

I've created the secondset replica is similar way and it worked.

Then I tried to create three configsvrs in three separate machine so that even if one machine shuts down the other configsvrs will be running. The configsvs will run in 192.168.1.10:27020, 192.168.1.11:27020 & 192.168.1.6:27020

So I've written

mongod --configsvr --dbpath /shard-data -port 27020

in 192.168.1.10, 192.168.1.11 & 192.168.1.6.

Then I tried to run the mongos in 192.168.1.10 in 27017 port with the three running configdb. So, I've written

mongos --configdb 192.168.1.10:27020,192.168.1.11:27020,192.168.1.6:27020 --port 27017 --chunkSize 1

Then as I've to add the shard in the mongos, and the mongos in running in 27017 port, I've written:-

mongo --port 27017

But it's showing

errno:111 conncetion refused.

But previously it working perfectly when I was testing it in a single machine.

Please help me why I'm getting this error and how to solve it.

I also have another confusion. I'm running the mongos in 192.168.1.10 and then I'll connect my node.js server with that mongos, but if that machine shuts down I'll have problem. So should I need to run mongos in other machines also, so that atleast one mongos will be running to route the connections with the database at any time ? If I've to create multiple mongos running is separate machines at same time, then how I'll connect any one of the mongos from the node.js server to access the database?

Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40
  • If it was working perfectly on a single machine it sounds like a firewall, also what do you mean by adding the shard to the mongos, you should only need to provide the configsrvs? – Sammaye Jul 11 '14 at 07:18
  • No, according to the link I've mentioned, I need to add two replicasets to the mongos, so I need to run db.runCommand( { addShard : ....And another thing is if there is any firewall issue then even replicasets should not run, but that worked. I think the issue is in somewhere else. – Indranil Mondal Jul 11 '14 at 07:36
  • Ah of course sorry I thought you have done that. Ok I know where you are now, you are actually setting up the set to be saved to the configsrv – Sammaye Jul 11 '14 at 07:37
  • And you are running the mongo shell on the same machine as the mnogos? – Sammaye Jul 11 '14 at 07:39
  • "so that atleast one mongos will be running to route the connections with the database at any time" Yes, you can actually load balance mongos', since the load balancer can provide one IP thats also the connectivity problem solved, however, most drivers accept a seed list of IPs, whether it be replica set members or mongos instances. It will instantly detect and react – Sammaye Jul 11 '14 at 07:40
  • Yeah, to set up the replicasets to be saved to the configsrv, I need to connect the mongos and then add shard. But I'm not being able to connect mongos even if I'm running the mongos in 192.168.1.10 and then trying to connect to the port in same machine. Only the configsrvs are in separate machine. – Indranil Mondal Jul 11 '14 at 07:41
  • Are you sure the mongos is running? – Sammaye Jul 11 '14 at 07:45
  • I've written the code mongos --configdb localhost:20001 .... in the same machine and that has not given me any error. – Indranil Mondal Jul 11 '14 at 07:47
  • Can you edit the question with the output form the mongos? It is just that on loopback there should be no firewall issue and this error is either firewall or nothing on that port – Sammaye Jul 11 '14 at 07:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57137/discussion-between-indra-and-sammaye). – Indranil Mondal Jul 11 '14 at 07:52

0 Answers0