Skip to content

Instantly share code, notes, and snippets.

@reggi
Created March 17, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reggi/0bdf6c3beb73c707cb7a72a5dd8ee4cc to your computer and use it in GitHub Desktop.
Save reggi/0bdf6c3beb73c707cb7a72a5dd8ee4cc to your computer and use it in GitHub Desktop.
echo "\nchanging the directory to home dir --------------------------------------------------------------------------------------------------------\n"
cd ~/
echo "\nkilling all running mongo processes -------------------------------------------------------------------------------------------------------\n"
mongod --shutdown --config /shared/replica-sets/mongod-repl-1.conf
mongod --shutdown --config /shared/replica-sets/mongod-repl-2.conf
mongod --shutdown --config /shared/replica-sets/mongod-repl-3.conf
echo "\nremoving all data directories -------------------------------------------------------------------------------------------------------------\n"
rm -rf /var/mongodb/db/1
rm -rf /var/mongodb/db/2
rm -rf /var/mongodb/db/3
echo "\nremoving all log files --------------------------------------------------------------------------------------------------------------------\n"
rm -rf /var/mongodb/db/mongod1.log
rm -rf /var/mongodb/db/mongod2.log
rm -rf /var/mongodb/db/mongod3.log
echo "\nremoving all log files --------------------------------------------------------------------------------------------------------------------\n"
rm -rf /var/mongodb/pki/m103-keyfile
echo "\ncreating the keyfile ----------------------------------------------------------------------------------------------------------------------\n"
sudo mkdir -p /var/mongodb/pki
sudo chown vagrant:vagrant -R /var/mongodb
openssl rand -base64 741 > /var/mongodb/pki/m103-keyfile
chmod 600 /var/mongodb/pki/m103-keyfile
echo "\ncreating data directories ----------------------------------------------------------------------------------------------------------------\n"
mkdir -p /var/mongodb/db/1
mkdir -p /var/mongodb/db/2
mkdir -p /var/mongodb/db/3
echo "\ntouching the logs ------------------------------------------------------------------------------------------------------------------------\n"
touch /var/mongodb/db/mongod1.log
touch /var/mongodb/db/mongod2.log
touch /var/mongodb/db/mongod3.log
echo "\nremoving auth in the config --------------------------------------------------------------------------------------------------------------\n"
echo 'storage:
dbPath: /var/mongodb/db/1
net:
bindIp: localhost,192.168.103.100
port: 27001
# security:
# authorization: enabled
# keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod1.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl' > /shared/replica-sets/mongod-repl-1.conf
echo "\nstarting up mongo repl 1 -----------------------------------------------------------------------------------------------------------------\n"
mongod --config /shared/replica-sets/mongod-repl-1.conf
echo "\nreplicaSet initiate ------------------------------------------------------------------------------------------\n"
mongo admin --port 27001 --eval='rs.initiate()'
echo "\ncreating the user ------------------------------------------------------------------------------------------\n"
mongo mongodb://localhost:27001/admin?replicaSet=m103-repl --eval='db.createUser({user:"m103-admin",pwd:"m103-pass",roles:[{role:"root",db:"admin"}]});'
echo "\nshutting down the server ------------------------------------------------------------------------------------------\n"
mongod --shutdown --config /shared/replica-sets/mongod-repl-1.conf
mongod --shutdown --config /shared/replica-sets/mongod-repl-2.conf
mongod --shutdown --config /shared/replica-sets/mongod-repl-3.conf
echo "\nenabling auth in the config ------------------------------------------------------------------------------------------\n"
echo 'storage:
dbPath: /var/mongodb/db/1
net:
bindIp: localhost,192.168.103.100
port: 27001
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod1.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl' > /shared/replica-sets/mongod-repl-1.conf
echo "\nstarting up mongo repl 1 [2] ------------------------------------------------------------------------------------------\n"
mongod --config /shared/replica-sets/mongod-repl-1.conf
mongod --config /shared/replica-sets/mongod-repl-2.conf
mongod --config /shared/replica-sets/mongod-repl-3.conf
echo "\nadding notes\n"
mongo --host "m103-repl/localhost:27001" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin" --eval='rs.add("m103:27002")'
mongo --host "m103-repl/localhost:27001" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin" --eval='rs.add("m103:27003")'
mongo --host "m103-repl/localhost:27001" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin" --eval='rs.status()'
sleep 5
echo "\nvalidate_lab_initialize_local_replica_set ------------------------------------------------------------------------------------------\n"
validate_lab_initialize_local_replica_set
echo "\ndone ------------------------------------------------------------------------------------------\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment