N
N
Nodar2015-09-24 10:42:40
MongoDB
Nodar, 2015-09-24 10:42:40

How to setup MongoDB Replica Set authorization properly?

I read the Mongolian docks, but I can’t understand the moment with access to the replica by login / password.
How to organize it correctly? Do I need to set logins and passwords separately for all replicas (different or the same?) or do it on the master, and this data is replicated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2015-09-28
@Nodar

A small manual on authorization in a replica:
1) Run the first node, authorization must be disabled!
2) Create admin and superuser:

use admin
db.createUser( {
    user: "siteUserAdmin",
    pwd: "<password>",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  });
db.createUser( {
    user: "siteRootAdmin",
    pwd: "<password>",
    roles: [ { role: "root", db: "admin" } ]
  });

3) Stop the node
4) Next, you need to create a key file:
you can simply enter some line like:
or generate it using openssl:
well, specify the rights:
After the file has been created, it should be copied to all nodes.
Important! so that the contents of this file on ALL nodes are the same!
5) Next, add to the config of each node:
auth=true
keyFile=/путь-до-файла-mongodb-keyfile
replSet=Название-реплики

it is also desirable to configure bind_ip
6) Well, try to start all the nodes))
ps: I don’t know how to write manuals) so excuse me ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question