MongoDB Shard Authentication

Source: Internet
Author: User
Tags auth

Start Configsvr

1. Ensure that the configsvr of the MONGDB is started in service mode, that is, from the script under/ETC/INIT.D, and that the user is mongod.

2. Ensure that the Mongod configuration files are identical.

3. Ensure that all keyfile file contents of the entire cluster are the same.

Start MONGOs

1. Start with the following command to ensure that the user switches to Mongod:

Runuser-s/bin/bash mongod-c '/usr/bin/mongos--configdb confighost-01:27019,confighost-02:27019,confighost-03 : 27019--port 27021--keyfile/data/mongodb/key.d/mongod.key '

2. If Warning:config servers confighost-01:27019 and confighost-03:27019 differ occur

You can delete the contents of the ConfigDB directory and run the CONFIGSVR service again.

3. After everything is OK, you can write the MONGOs startup configuration to the script/etc/init.d/mongos

4. Service MONGOs Start

Adding shards

Please note that you must add at least one shard before creating any user for the admin database, otherwise you may not be able to join later.

Sh.addshard ("rs-1/host-11.mycloud.com")

Sh.addshard ("rs-2/host-21.mycloud.com")

Create the first user for the admin userThe user's role must be userAdminAnyDatabase1. MONGOs Server Native login Mongo--port xxxxx #xxxxx表示mongos的监听端口use adminshow DBS # You can list the database Db.createuser ({User: "SysAdmin", pwd: "123", roles: [{role: "Useradminanydatabase", DB: "Admin"}]}); At this point, after exiting with MONGO--port XXXXX login to execute show DBS is not authorized. Re-loginYou can choose to log on to your computer or log in from another machine. Native Login: MONGO localhost:27021/admin-u sysadmin-p 123 Other Machines login: MONGO mongos-server:xxxxx/admin-u sysadmin-p 123 Create a user for the test databaseLog on to the admin database as an administrator on the MONGOs server: MONGO localhost:27021/admin-u sysadmin-p 123 Create an administrator user for the test database: Db.createuser ({User: " Yc-admin ", pwd:" 123 ", roles: [{role:" Useradmin ", DB:" Test "}]}); Switch to test database: Use test log in to the database as Test administrator: Db.auth (" Yc-admin "," 123 ") create another user of test: read-only User: Db.createuser ({User:" Yc-read ", pwd:" 123 ", roles: [{role:" read ", DB:" Test "}]}); Read-Write User: Db.createuser ({User: "Yc-write", pwd: "123", roles: [{role: "ReadWrite", DB: "Test"}]}); Add additional shardsSwitch to the Admin database use Admin to add useradmin user and root roles to the admin database (assuming the username is admin-root), see previous step. Clusteradmin User: Db.createuser ({User: "Yc-cstadmin", pwd: "123", roles: [{role: "Clusteradmin", DB:" Admin "}]}); Switch to Yc-cstadmin User: Db.auth (" Yc-cstadmin "," 123 ") Add Rs-3 Shard: Sh.addshard (" rs-3/host-31.mycloud.com ")   Note:Different roles for the database have different permissions: read: Read-only ReadWrite: Read-write root: All useradmin: User managementclusteradmin: Cluster management and monitoringAdding shards can only be done by the root of the admin database, and no other user has this permission.

MongoDB Shard Authentication

Related Article

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.