Skip to content

Instantly share code, notes, and snippets.

@stewones
Last active March 4, 2020 03:21
Show Gist options
  • Save stewones/cef220ed43c090fed51c9ab1b334d450 to your computer and use it in GitHub Desktop.
Save stewones/cef220ed43c090fed51c9ab1b334d450 to your computer and use it in GitHub Desktop.
install mongodb ubuntu
#!/bin/bash
# GET ALL USER INPUT
echo "super password"
read SUPER_PW
echo "api password"
read API_PW
tput setaf 2; echo 'Wellcome to mongodb install bash script';
sleep 2;
tput sgr0
cd ~
tput setaf 2; echo "Sit back and relax :) ......"
sleep 2;
tput setaf 2; echo 'installing Mongo DB';
sleep 2;
tput sgr0
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.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.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
tput setaf 2; echo 'configuring Mongo DB';
sleep 2;
tput sgr0
echo "Adding super user"
sleep 2
tput sgr0
mongo <<EOF
use admin
db.createUser({
user: "super",
pwd: "$SUPER_PW",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})
exit
EOF
echo "Adding api user"
sleep 2
tput sgr0
mongo <<EOF
use api
db.createUser({
user: "api",
pwd: "$API_PW",
roles: [ { role: "readWrite", db: "api" } ]
})
exit
EOF
sudo cat > /etc/mongod.conf <<'EOF'
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled
EOF
sudo systemctl restart mongod
sleep 3
tput sgr0
tput sgr0
echo
echo
tput setaf 3; echo "Installation & configuration succesfully finished."
echo
tput sgr0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment