I'm setting up a mongodb replica set across 3 different hosts. If you create the admin user on one host and turn on auth and keyfile in the /etc/mongodb.conf, do you have to create that same user on nodes 2/3? Or can I just add those nodes to the replica set and the admin database will be replicated with the admin user I added from node 1 to the other 2? I'm having some trouble doing that if I bring up the other nodes with auth/keyfile turned on.
Mongodb – Admin DB replicated in MongoDB replica set
mongodb
Related Question
- Mongodb – Mobile node in a mongodb replica set
- MongoDB 3.2 replica set with arbiter version 2.6
- MongoDB cluster setup
- Mongodb – Can’t auth admin db on the replica set
- Mongodb – different keyfiles for different replica sets
- Mongodb – How to configure mongodb replica set with redundant networks
- Mongodb users in replica
- MongoDB Replica Set Sync data by Copying Data Files from Another Member
Best Answer
There are a couple of separate questions/issues here:
If they are members of the same replica set, then no. The users will be written to the primary and then replicated to the secondaries - remember any secondary can become primary in a normal set, so you would have to have all the data necessary to do that, including users. If the nodes are in the set when they are added, the users will replicate normally. If you add them later, they will replicate the users as part of the initial sync process.
Note that for nodes that are members of different replica sets (say multiple shards) that is not the case.
Remember that the keyfile must be identical for all nodes in a set. The keyfile is what the nodes will use to authenticate with each other (for the purposes of initial sync and replication for a start, so it is an absolute must). If you are having issues when you add the nodes, there will be errors in the logs that will tell you why. The common reasons would be:
If you expand on the difficulties you have when you try to add (how you are adding, what error you get, and preferably the output of rs.status() and a sample config file) I can elaborate further.