mongodb3.6 Cluster Construction: Shard cluster authentication

Source: Internet
Author: User

The previous cluster has been created and now joins the certification.

1. Generate a key file
Create a path on each server:
Mkdir-p/var/lib/mongo/auth

Generate a 64-byte key file
OpenSSL rand-base64 >/var/lib/mongo/auth/keyfile.key

Copy the key file to each node in the cluster (routing node, meta-Configuration node, and the key file on the Shard node).
Scp/var/lib/mongo/auth/keyfile.key [Email Protected]:/var/lib/mongo/auth
Scp/var/lib/mongo/auth/keyfile.key [Email Protected]:/var/lib/mongo/auth

Set the permissions for the key file to 600,owner to Mongod (the user who started the MONGO instance)
Chown-r Mongod:mongod/var/lib/mongo/auth
chmod 600/var/lib/mongo/auth/keyfile.key
2. Create a clustered user
The Admin user who creates the Admin library is created on each node (each shard node, each routing node)
MONGO 127.0.0.1:20000/admin

Db.createuser (
{
User: "Admin",
PWD: "admin123456",
Roles:
[
{role: "root", DB: "Admin"},
{role: "Clusteradmin", DB: "Admin"}
]
}
)

Create a Business library user (here is test) and need to create a user at each node (each shard node, each routing node)
Use test
Db.createuser (
{
User: "Test",
PWD: "test123456",
Roles:
[
{role: "Dbowner", DB: "Test"},
{role: "Clusteradmin", DB: "Admin"}
]
}
)

3. Turn on cluster authentication
The configuration of KeyFile is added to the configuration file of each node (routing node, meta-configuration node, shard node);
Security
KeyFile:/var/lib/mongo/auth/keyfile.key

Adding authorization configuration items to configuration files for each meta-configuration node and Shard node (that is, in addition to the MONGOs node)
Security
Authorization:enabled

Shutting down the cluster
Follow the routing nodes, Shard nodes, configure node order, and turn off the node services in turn:
Systemctl Stop Mongod-mongos
Systemctl Stop Mongod-shard3
Systemctl Stop Mongod-shard2
Systemctl Stop Mongod-shard1
Systemctl Stop Mongod-configsvr

Restarting the cluster
Systemctl Start Mongod-configsvr
Systemctl Start Mongod-shard1
Systemctl Start Mongod-shard2
Systemctl Start Mongod-shard3
Systemctl Start Mongod-mongos

4. Verifying the authentication of the cluster
MONGO 127.0.0.1:20000/admin

Use admin
Db.auth ("admin", "admin123456")

View Shard Status
Db.printshardingstatus ()

Use test
Db.auth ("Test", "test123456")

View the cluster status of the table in this library
Db.users.stats ()
If the first sharded field is found to be true, there is no exception to the cluster after adding the authentication function

mongodb3.6 Cluster Construction: Shard cluster authentication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.