0

1) I have mongo instances A, B and C, each having a different set of users with different roles. I have used mongo shell to connect with A through an Admin user. Now, to create a replica and add B and C, do I need to pass through auth on B and C. Can you please help me with the commands?

2) I have mongo instances A, B and C, each having a different set of users with different roles. After I create a replica with A, B and C, what happens to the users of individual nodes. Are all the users from each node available in the replica?

1
  • Welcome to the site, what is the MongoDB version(x,y,z)? Apr 11, 2019 at 4:48

2 Answers 2

0

So in your case, currently all the nodes(A, B and C) are running as standalone nodes with a different set of data.

Now you are trying to establish a replica with the existing nodes.

As per your question, first, you are trying to convert node A to a replica set member and then adding B and C to the replica set. So mostly, in this case, node A will become primary and B and C will be added as secondary. Since B and C are added as secondary for one time it will replicate all data from A. This one time process is called Initial Sync.

When Initial Sync is happening, mongod removes the contents of the dbPath directory of B and C node.

Please follow the steps in Deploy a Replica Set to set up the replica set.

Answering your second question, this procedure will delete all users and data from Node B and C.

5
  • ,this procedure will delete all users and data from Node B and C. I don't think so it will delete the rest of the users from that which node is participating the secondary replica node in the cluster. Apr 11, 2019 at 11:23
  • @MdHaidarAliKhan , please check mongodb initial sync process
    – Mani
    Apr 11, 2019 at 12:43
  • @MdHaidarAliKhan Please check the WARNING given in the following link docs.mongodb.com/manual/tutorial/resync-replica-set-member/…
    – Mani
    Apr 11, 2019 at 15:12
  • From one mongod, can I initiate a replica and add other mongod instances into the replica set without passing through the auth of that other mongod instances? Apr 16, 2019 at 10:25
  • You can authenticate members of replica sets and sharded clusters. For the internal authentication of the members, MongoDB can use either keyfiles or x.509 certificates. Please refer docs.mongodb.com/manual/tutorial/… to enable keyfile authentication between replica set members.
    – Mani
    Apr 16, 2019 at 15:09
0

I have mongo instances A, B and C, each having a different set of users with different roles. I have used mongo shell to connect with A through an Admin user. Now, to create a replica and add B and C, do I need to pass through auth on B and C. Can you please help me with the commands?

As @AdamC has been already stated that 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.

Suppose that you have 3 node replica set like as A,B,C

The Node A there is configuration file as (A.conf)

For example I am mentioning the node A configuration file

storage:
  dbPath: /var/mongodb/db/A
net:
  bindIp: 192.168.xxx.xxx,localhost
  port: 27011                --- node A port no
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/Example-keyfile
systemLog:
  destination: file
  path: /var/mongodb/db/A/mongod.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: StackExachange-example

Node B.conf file

storage:
  dbPath: /var/mongodb/db/B
net:
  bindIp: 192.168.xxx.xxx,localhost
  port: 27012                --- node B port no
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/Example-keyfile
systemLog:
  destination: file
  path: /var/mongodb/db/B/mongod.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: StackExachange-example

Node C.conf file

storage:
  dbPath: /var/mongodb/db/C
net:
  bindIp: 192.168.xxx.xxx,localhost
  port: 27013                --- node C port no
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/Example-keyfile
systemLog:
  destination: file
  path: /var/mongodb/db/C/mongod.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: StackExachange-example

Note: Here the dbpath of every node (i.e., A,B,C will be different)

After making the configuration file of A,B,C with thier different path start the mongod server process.

Starting mongod processes with A.conf, B.conf and C.conf:

mongod -f A.conf
mongod -f B.conf
mongod -f C.conf

after starting the mongod process of all node, suppose that I will connect to node A with mongo shell

mongo --port 27011  --- here port no 27011 is port no of A

Initiating the replica set:

rs.initiate()

Creating a user:

use admin db.createUser({ user: "StackExchange-admin", pwd: "StackExchange-pass", roles: [ {role: "root", db: "admin"} ] })

Note : Here I am creating the user and password of admin database of node A.

Exiting out of the Mongo shell and connecting to the entire replica set:

exit
mongo --host "StackExchange-example/192.168.xxx.xxx:27011" -u "StackExchange-admin"
-p "StackExchange-pass" --authenticationDatabase "admin"

Getting replica set status:

rs.status()

Adding other members to replica set:

rs.add("B:27012")
rs.add("C:27013")

Getting an overview of the replica set topology:

rs.isMaster()

Stepping down the current primary:

rs.stepDown()

Checking replica set overview after election:

rs.isMaster()

I have mongo instances A, B and C, each having a different set of users with different roles. After I create a replica with A, B and C, what happens to the users of individual nodes. Are all the users from each node available in the replica?

Here as I understood the mongo instances (A,B,C) means that three mongod. Suppose that among three of node A,B,C they have some different users with different roles . Suppose that when replication has been made with the node A as primary replica set with their admin database & their roles authentication.

As whatever before the replication you have the Users & roles of the the node B,C it will be remain there but after the replication if you shall create new users or roles to members of replica then need to Resync a Member of a Replica Set

For further your ref here , here and here

2
  • From one mongod, can I initiate a replica and add other mongod instances into the replica set without passing through the auth of that other mongod instances? Apr 16, 2019 at 10:24
  • @Raman, Yes, you can. But the three node replica folder will be different to each other. Apr 16, 2019 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.