Last active
August 2, 2022 10:23
-
-
Save imshaiknasir/9bfe8ea3a581515ea73d51668b284365 to your computer and use it in GitHub Desktop.
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 | |
# Stop the mongod process | |
sudo systemctl stop mongod | |
# Remove any MongoDB packages that you had previously installed. | |
sudo apt-get purge mongodb* | |
# Remove MongoDB databases and log files. | |
sudo rm -r /var/log/mongodb | |
sudo rm -r /var/lib/mongodb | |
# Delete source-list file: | |
sudo rm -f /etc/apt/sources.list.d/mongodb* | |
# List out any mongo packages(if any) | |
sudo apt-get update | grep mongo | |
# Import the public key | |
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - | |
# For Ubuntu 20.04 | |
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list | |
# List out any mongo packages(if any) | |
sudo apt-get update | grep mongo | |
# Install the MongoDB packages. | |
sudo apt-get install -y mongodb-org | |
# Enable mongod on system startup | |
sudo systemctl enable mongod | |
# Start mongod server: | |
sudo systemctl start mongod | |
echo "Now, follow these instructions:" | |
replicateConf='\n# Add the replica config in mongod.conf file:\nreplication:\n oplogSizeMB: 256\n replSetName: rs0\n enableMajorityReadConcern: true\n' | |
initiaters='\n# Initiate the replica set:\nmongosh --eval "rs.initiate()"\n' | |
restartBash='\n# Restart the terminal\n' | |
reinitiaters='\n# Initiate the replica set:\nmongosh --eval "rs.initiate()"\n' | |
echo -e $replicateConf $initiaters $restartBash $reinitiaters | |
# If you get "not started as node process" issue: () | |
$ mongosh --eval "db.adminCommand( { shutdown : 1} )" | |
$ sudo systemctl start mongod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment