Skip to content

Instantly share code, notes, and snippets.

@dev117uday
Created August 19, 2021 10:08
Show Gist options
  • Save dev117uday/d341db1998b9a2a726eee341d57c60b2 to your computer and use it in GitHub Desktop.
Save dev117uday/d341db1998b9a2a726eee341d57c60b2 to your computer and use it in GitHub Desktop.
Lab Setting Up a Replica Set : MongoDB university
mkdir -p /var/mongodb/db/{1,2,3}
sudo mkdir -p /var/mongodb/pki/
openssl rand -base64 741 > /var/mongodb/pki/m103-keyfile
chmod 400 /var/mongodb/pki/m103-keyfile
storage:
  dbPath: /var/mongodb/db/1
net:
  bindIp: localhost
  port: 27001
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
  destination: file
  path: /var/mongodb/logs/mongod1.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: m103-repl

storage:
  dbPath: /var/mongodb/db/2
net:
  bindIp: localhost
  port: 27002
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
  destination: file
  path: /var/mongodb/logs/mongod2.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: m103-repl

storage:
  dbPath: /var/mongodb/db/3
net:
  bindIp: localhost
  port: 27003
security:
  authorization: enabled
  keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
  destination: file
  path: /var/mongodb/logs/mongod3.log
  logAppend: true
processManagement:
  fork: true
replication:
  replSetName: m103-repl
mongo --port 27001

rs.initiate()

use admin

db.createUser({
  user: "m103-admin",
  pwd: "m103-pass",
  roles: [
    {role: "root", db: "admin"}
  ]
})

# then exit

mongo --host "localhost:27001" -u "m103-admin"
-p "m103-pass" --authenticationDatabase "admin"

rs.status()

rs.add("localhost:27012")
rs.add("localhost:27013")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment