Last active
February 10, 2021 20:18
-
-
Save kennwhite/e5236fce4c19da64dd92cbddbc891f46 to your computer and use it in GitHub Desktop.
Install MongoDB 4.x Enterprise on Debian 9
This file contains 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
#!/bin/bash | |
# To completely purge all remnants of Mongo (repo conf, pkgs, apt cache, DB files, pgp keys), for Debian 9 or Ubuntu 18: | |
# sudo service mongod stop ; sudo apt-get purge -y mongodb-enterprise* ; sudo rm -rf /etc/apt/sources.list.d/mongodb* ; sudo rm -rf /var/lib/mongodb ; sudo apt-get clean; sudo apt-get autoclean ; sudo apt-get -y autoremove ; sudo apt-key del 9DA31620334BD75D9DCB49F368818C72E52529D4 ; sudo rm -rf /etc/mongod* ; sudo rm -rf /var/log/mongo ; sudo rm -rf /etc/apt/sources.list.d/mongodb-enterprise.list /etc/systemd/system/multi-user.target.wants/mongod.service | |
# Inside an LXC container, if getting "Failed to start Atop process accounting daemon." then fix with: | |
echo $$ >/run/atopacctd.pid | |
apt install -f | |
echo Installing MongoDB 4.x Enterprise edition... | |
echo | |
sudo apt-get install -y gnupg2 libcurl3 | |
sudo apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 | |
echo "deb https://repo.mongodb.com/apt/debian stretch/mongodb-enterprise/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list | |
sudo apt-get update | |
sudo apt-get install -y mongodb-enterprise-server mongodb-enterprise-tools mongodb-enterprise-shell | |
sudo systemctl enable mongod.service | |
# Enable auth by default, save date-stamped backup conf file | |
echo Enabling authentication... | |
sudo sed -i-`date -u|tr ' ' '_'`.bak 's/^#security:*/security:\n authorization: enabled/' /etc/mongod.conf | |
sudo service mongod start | |
systemctl status mongod --no-pager | |
echo -n -e "\nChecking for a running mongod server in 5 seconds... " | |
sleep 5 | |
if pgrep "mongod" 2>&1>/dev/null; then echo -e "[OK]\n" ; else echo -e "[FAIL]\n" ; fi | |
# Add username to prompt in mongo shell | |
echo 'prompt=function(){user=db.runCommand({connectionStatus:1}).authInfo.authenticatedUsers[0];if(user){return user.user + "> "};return "> "}' > ~/.mongorc.js | |
_mpwd=$(head -c 32 /dev/urandom 2>&1 | sha1sum | head -c 14 ) | |
echo [Creating user 'dba' with 'root' role on 'admin' DB with password: $_mpwd] | |
echo "db.createUser({user:'dba',pwd:'$_mpwd',roles:['root']})"|mongo admin | |
echo "Attempting to connect to admin DB as user 'dba'..." | |
echo show dbs|mongo -u dba -p $_mpwd localhost/admin | |
echo | |
echo To login as root dba: mongo -u dba -p $_mpwd localhost/admin | |
# unset _mpwd | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment