MongoDB Replication Sets and ELB

I have one primary and two second words in aws using ELB. What is best for reading and writing?

1) Do I create one LB with all nodes in the ELB with primary and secondary, and let python (pymongo) handle the sorting to read and write?

2) Or make a place of all minor under ELB and assign primary for elastic IP? To do this, you need a script to track the type of node and reassign if a failure occurs.

I hope for option 1.

thanks

+6
source share
3 answers

It depends on your situation. With the mongodb drivers, you don’t need to keep track of which node the client is connecting to - you just need to tell it about the replica set and it will automatically connect to the primary and crash.

If you want to extend the load of reading, you can set the reading preference so that the application can read from secondary sources, but you can only write to the primary record. This means that you do not need to install ELB for all incoming connections, and it can even hurt you, because it can cause records to be sent to secondary servers (where they will fail). Using a reading preference will allow you to distribute readings, so in your case, I would recommend not using ELB.

In general, I would look at http://www.slideshare.net/jrosoff/mongodb-on-ec2-and-ebs . You may find this helpful.

+5
source

I am in the same boat, but I am running 3 instances of mongo in the same replica set, 2 by default and 1 arbiter. Setting up ElasticIP is a bad b / c idea, which means that your mongo server will have an open connection that you don't need.

I ended up creating an ELB that listens on 27017 and forwards both replicaset elements by default, but not for actual load balancing, but rather for fault tolerance. Therefore, if health check 27017 fails, standby mode can handle subsequent requests. In addition, using ELB you can create a DNS CNAME record and specify your application to use it, in my case I use "docstore". This way you do not need to specify actual mongo instances like docstore-1 and docstore-2 etc.

+1
source

I think the answer is that you are not using a load balancer. Your client provides detailed information about all members of the replica set (primary and secondary), and it connects to the current first, depending on what might be.

See How do you connect to replication from the MongoDB shell?

mongo --host replicaSetName/host1[:porthost1],host2[:porthost1],host3[:porthost3] databaseToConnect 

Here we use the command line client to connect to a replica set (rather than a single node), but it can be nodeJS, MongoChef (support for replica sets), or any other client you are connecting to.

0
source

All Articles