Created
April 4, 2020 06:07
-
-
Save afahitech/b821b217f4f0f4356e522f0ae9e4dd4f to your computer and use it in GitHub Desktop.
How to install mongodb on Ubuntu 18.04
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
| # System update | |
| sudo apt update | |
| # Install mongoDB | |
| sudo apt install mongodb | |
| sudo systemctl status mongodb | |
| sudo systemctl stop mongodb | |
| sudo systemctl start mongodb | |
| sudo systemctl restart mongodb | |
| sudo systemctl disable mongodb | |
| sudo systemctl enable mongodb | |
| # Enable Remote MongoDB Access on Firewall | |
| sudo ufw allow 27017 | |
| sudo ufw allow from 192.168.1.7/32 to any port 27017 | |
| sudo ufw allow ssh | |
| sudo ufw enable | |
| sudo ufw status | |
| # Configure | |
| sudo nano /etc/mongodb.conf | |
| bind_ip = 127.0.0.1,192.168.1.7 | |
| #port = 27017 | |
| sudo systemctl restart mongodb | |
| # Create MongoDB Database | |
| mongo | |
| show dbs | |
| use admin | |
| db.createUser({user:"root", pwd:"root123", roles:[{role:"root", db:"admin"}]}) | |
| exit | |
| # Enable MongoDB authentication | |
| sudo nano /lib/systemd/system/mongodb.service | |
| # Under the [Service] config section, find the parameter ExecStart/ change as below | |
| ExecStart=/usr/bin/mongod --auth --unixSocketPrefix=${SOCKETPATH} --config ${CONF} $DAEMON_OPTS | |
| systemctl daemon-reload | |
| sudo systemctl restart mongodb | |
| sudo systemctl status mongodb | |
| # connect to mongodb | |
| mongo -u "root" -p --authenticationDatabase "admin" | |
| mongo --version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment