Last active
July 26, 2020 05:27
-
-
Save Maria-UET/31424f89ecd0528b414cedf7c5353a7c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
######## Run this bash script on ONE replica set node to initiate the Mongodb replica set ######### | |
# HOWTO: | |
# System recommendation : Ubuntu 16.04 | |
# Download the script on your master/primary replica set node | |
# Open in bash and make it executable with command: chmod +x replicaset_initiate.sh | |
# Run with command: sudo ./replicaset_initiate.sh | |
# OTHER USEFUL SCRIPTS: | |
# For MongoDB installation: https://gist.github.com/Maria-UET/1368387e2e72d2de96fc824919dad176 | |
# For making a MongoDB replica set with three nodes: https://gist.github.com/Maria-UET/af4332f6dd9e57f2d0f6141dbb8dd447 | |
# The username of your MongoDB user | |
USR="admin" | |
# The password of your MongoDB user. Password should be ideally read from a config.ini file, keeping passwords in bash scripts is not secure. | |
PASS="password123" | |
DB="admin" | |
ROLE="root" | |
USER="manager" | |
# Replace with the hostnames of each node in the replica set | |
NODE1='node1' | |
NODE2='node2' | |
NODE3='node3' | |
PORT=27017 | |
# Select ONLY one node as primary and set its priority : 1 | |
mongo config = { | |
_id : "rs0", | |
members : [ | |
{_id : 0, host : "'$NODE1':$PORT", priority : 0}, | |
{_id : 1, host : "'$NODE2':$PORT", priority : 0}, | |
{_id : 2, host : "'$NODE3':$PORT", priority : 1}, | |
] | |
} | |
mongo rs.initiate(config) | |
sudo mongo --username $USR --password $PASS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment