问题
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?
来源:https://stackoverflow.com/questions/24684940/error-to-connect-mongos-when-trying-to-create-replicated-sharded-cluster