mongodb adds authentication steps

1 Start mongos without authentication first

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongos -f /usr/b2c-conf/mongos_router.yaml

/usr/software/mongodb-linux- x86_64-rhel62-3.4.3/bin/mongodb -f /usr/b2c-conf/mmongod_config.yaml

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongodb -f /usr/b2c- conf/shard-a.yaml


2 Connect to mongos process

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongo --port=27017



3 Create user administrator

use admin

use admindb.createUser(

  {

    user: "myUserAdmin",

    pwd: "abc123",

    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]

  })



4 Create a user for the test library

use test

db.createUser(

  {

    user: "myTester",

    pwd: "xyz123",

    roles: [ { role: "readWrite", db: "test" },

             { role: "read", db: "reporting" } ]

  })



5 in the config file Add authentication startup method

# On UNIX systems, the keyfile must not have group or world permissions.

# The content of the keyfile must be the same on all mongod and mongos instances



echo -e "csair mongo secret key" > /opt/mongo/ The keyfile



mongos configuration file adds the following configuration properties:

security:

keyFile: /opt/mongo/keyfile

clusterAuthMode: "keyFile" The



mongod configuration file adds the following configuration properties:

security:

keyFile: /opt/mongo/keyfile

authorization: enabled



6 Start mongos with authentication

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongos -f  /usr/b2c-conf/mongos_router.yaml

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongodb -f  /usr/b2c-conf/mmongod_config.yaml

/usr/software/mongodb-linux-x86_64-rhel62-3.4.3/bin/mongodb -f  /usr/b2c-conf/shard-a.yaml

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326119537&siteId=291194637