Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

Connecting to MongoDB Replica Set behind a Load Balancer

$
0
0

I am a little confused on how MongoDB handles replica sets. I have the following setup:

  • 2 Replica set members to store data
  • 1 Arbiter
  • Everything is in a Virtual Network

There are two scenarios:

Scenario 1

  • No Load balancer.
  • DataVM0 is accessible at public IP 123.123.12.1
  • DataVM1 is accessible at public IP 123.123.12.2
  • ArbiterVM is accessible public at IP 123.123.12.3

Here, my connection string would look something like:

mongodb://123.123.12.1:27017,123.123.12.2:27017,123.123.12.3:27017/?replicaSet=samplereplicaset

Scenario 2

  • Load balancer accessible at public IP 123.123.12.1.
  • DataVM0 is not publicly accessible.
  • DataVM1 is not publicly accessible.
  • ArbiterVM is not publicly accessible.
  • LoadBalancer port 27017 is forwarded to DataVM0 port 27017
  • LoadBalancer port 27018 is forwarded to DataVM1 port 27017
  • LoadBalancer port 27019 is forwarded to ArbiterVM port 27017

Here, my connection string would look something like this:

mongodb://123.123.12.1:27017,123.123.12.1:27018,123.123.12.1:27019/?replicaSet=samplereplicaset

Are both these ways to connect equivalent in terms of replica sets? I ask this since in the connection string, I'm not directly connecting to any of the VMs.

All VMs are accessible from every other VM in the virtual network. DNS and everything works properly.


Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>