Skip to content

Instantly share code, notes, and snippets.

@CloudLinuxDeveloper
Last active May 17, 2020 11:40
Show Gist options
  • Select an option

  • Save CloudLinuxDeveloper/bab591f71130e2cc58688b51300fe26f to your computer and use it in GitHub Desktop.

Select an option

Save CloudLinuxDeveloper/bab591f71130e2cc58688b51300fe26f to your computer and use it in GitHub Desktop.
How to install mongodb on Ubuntu 20.04/18.04 Ltd.
#mongodb
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