Last active
December 17, 2017 18:01
-
-
Save markshust/b5239e2daf3546af013e to your computer and use it in GitHub Desktop.
sample mongodb setup - create user for db dbname with admin access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use admin; | |
| // create superuser | |
| db.createUser({user: "username", pwd: "PLAINTEXTPASSWORD", roles: ["userAdminAnyDatabase"]}); | |
| // create oplog user | |
| db.createUser({user: "oplogger", pwd: "PLAINTEXTPASSWORD", roles: [{role: "read", db: "local"}]}) | |
| // create user for another database | |
| use foo; | |
| db.createUser({user: "username", pwd: "PLAINTEXTPASSWORD", roles: ["readWrite"]}); | |
| // set engine to mmapv1, unbind, add replica set | |
| vi /etc/mongod.conf | |
| storage: | |
| engine: mmapv1 | |
| net: | |
| port: 27017 | |
| #bindIp: 127.0.0.1 | |
| replication: | |
| replSetName: rs0 | |
| // initiate replica set from mongo cli | |
| rs.initiate() | |
| // restart mongo. if issues connecting, clear out log file and restart | |
| sudo rm -f /var/log/mongodb/mongod.log | |
| sudo touch /var/log/mongodb/mongod.log | |
| sudo chown mongodb:mongodb /var/log/mongodb/mongod.log | |
| // setup keyfile | |
| sudo mkdir /opt/mongodb | |
| sudo openssl rand -base64 741 > /opt/mongodb/mongodb-keyfile | |
| sudo chown mongodb:mongodb /opt/mongodb/mongodb-keyfile | |
| sudo chmod 600 /opt/mongodb/mongodb-keyfile | |
| // update config | |
| sudo vi /etc/mongodb.conf | |
| // uncomment and update security keyFile with: /opt/mongodb/mongodb-keyfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment