Dave
Dave

Reputation: 3393

MongoDB replica set hostnames - client vs. server

I'm setting up a MongoDB replica set. The hostnames are all specified in the /etc/hosts file on all of the replica set members ("mongo1", "mongo2" and "mongo3"). These DNS names are only defined on the replica set members.

Clients connect to the replica set via other hostnames (the Amazon EC2 hostname) that point to the same machines.

Question: Is there any need for clients to be able to resolve the replica set hostnames, since they don't use these to establish a connection?

Upvotes: 1

Views: 963

Answers (1)

Joe
Joe

Reputation: 28316

Yes, the clients need to be able to resolve the hostnames used to add the nodes to the replica set.

When connecting to a replia set, the hostnames provided in the connection string are used as a seed list.

The client attempts to connect to each node in the seedlist in turn until one succeeds. It then runs the isMaster database command to get the list of hosts in the replica set, and the current primary.

The client drops the initial connection to the seed host and connects to the replica set members using the hostname and port returned in the isMaster command.

Upvotes: 3

Related Questions