Last active
October 30, 2020 09:29
-
-
Save phainamikaze/d32cba68aeb9992b5a96376c03496367 to your computer and use it in GitHub Desktop.
install-mongodb-on-ubuntu
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
| wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - | |
| #wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - | |
| echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list | |
| #echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list | |
| sudo apt-get update | |
| sudo apt-get install -y mongodb-org=4.2.3 mongodb-org-server=4.2.3 mongodb-org-shell=4.2.3 mongodb-org-mongos=4.2.3 mongodb-org-tools=4.2.3 | |
| #sudo apt-get install -y mongodb-org=4.0.20 mongodb-org-server=4.0.20 mongodb-org-shell=4.0.20 mongodb-org-mongos=4.0.20 mongodb-org-tools=4.0.20 | |
| sudo systemctl start mongod | |
| sudo systemctl enable mongod | |
| mongo | |
| use admin | |
| db.createUser( | |
| { | |
| user: "root", | |
| pwd: "Passw0rd", | |
| roles: [ { role: "root", db: "admin" } ] | |
| } | |
| ) | |
| #add below script /etc/mongod.comf | |
| security: | |
| authorization: 'enabled' | |
| net: | |
| port: 27017 | |
| bindIp: 0.0.0.0 |
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
| openssl rand -base64 756 > <path-to-keyfile> | |
| chmod 400 <path-to-keyfile> | |
| edit /etc/mongodb.conf | |
| security: | |
| keyFile: <path-to-keyfile> | |
| replication: | |
| replSetName: <replicaSetName> | |
| connect to mongo local and run | |
| rs.initiate( | |
| { | |
| _id : <replicaSetName>, | |
| members: [ | |
| { _id : 0, host : "mongo1.example.net:27017" }, | |
| { _id : 1, host : "mongo2.example.net:27017" }, | |
| { _id : 2, host : "mongo3.example.net:27017" } | |
| ] | |
| } | |
| ) | |
| Use rs.status() to locate the primary member. | |
| use admin | |
| db.createUser( | |
| { | |
| user: "admin", | |
| pwd: "admin", | |
| roles: [ { "role" : "root", "db" : "admin" } ] | |
| } | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment