Skip to content

Build up mongo replica set, and enabled key file authentication

Notifications You must be signed in to change notification settings

post-human-world/mongo-replica-set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Build up Mongo replica set

This repository need you run a few commands to set up replica set and it uses docker compose to launch the replica set. The docker compose file will deploy 3 separate containers:

  • mongo1
    • set as primary with priority 7
    • map container port 27017 to localhost 27021
  • mongo2
  • mongo3

All container are using one internal network so that them can connect to each other. Also they use same mongod.cfg and enabled key file authentication.

Usage

  1. Build up all containers
docker compose up -d --build 
  1. Run script in mongo1 terminal. The script will initialize replica configuration and create a root user. This script may cost 30 seconds, because it need to wait node to become primary
/config/init.sh
  1. Access mongodb with url: mongodb://tom-rs:jerry@localhost:27021/?directConnection=true&authMechanism=DEFAULT

Reference

About

Build up mongo replica set, and enabled key file authentication

Topics

Resources

Stars

Watchers

Forks

Languages