본문 바로가기

Software Engineering/MongoDB

[MongoDB] Replicat set 구성을 위한 사전 지식 정리

사진: Unsplash 의 Zhen Yao

 

실행 환경

  • Ubuntu 20.04
  • MongoDB 7.0 Community Server

참고 문서

 

Deploy a Self-Managed Replica Set - MongoDB Manual v7.0

Three member replica sets provide enough redundancy to survive most network partitions and other system failures. These sets also have sufficient capacity for many distributed read operations. Replica sets should always have an odd number of members. This

www.mongodb.com

 

사전 확인

  • 3개의 멤버 노드를 레플리카 셋으로 구성된다.
  • 레플리카 셋은 항상 홀수의 멤버 구성을 가져야함, 그래야 리더 선출이 문제 없이 진행된다.

진행 순서

  • 각 노드에 mongodb를 설치한다.
  • 가능하면 모든 노드가 기본 포트인 27017을 사용하도록 한다.
  • 몽고DB 5.0 부터는 아이피 주소 대신 호스트 네임으로 설정을 진행해야한다. 
  • conf 파일에 replication.replSetName, net.bindIp 항목을 설정한다.
  • primary로 사용할 노드에 mongosh로 접속한다.
  • rs.initiate() 명령을 실행한다. 기본 레플리카 셋 설정으로 레플리카가 구성된다.
rs.initiate( {
   _id : "rs0",
   members: [
      { _id: 0, host: "mongodb0.example.net:27017" },
      { _id: 1, host: "mongodb1.example.net:27017" },
      { _id: 2, host: "mongodb2.example.net:27017" }
   ]
})
  • rs.conf() 명령으로 레플리카 셋 상태를 확인한다. 
  • 레플릿카 셋이 primary 노드가 있는지 확인 한다.

키 파일 생성

 

Deploy Self-Managed Replica Set With Keyfile Authentication - MongoDB Manual v7.0

We recommend keyfiles only for testing and development environments, due to their limitations in manageability and cryptographic strength. For production environments, we strongly advise using x.509 certificates. While keyfiles can be secure in specific, c

www.mongodb.com

  • 키 파일을 생성한다.
openssl rand -base64 756 > <path-to-keyfile>
chmod 400 <path-to-keyfile>
  • 키 파일을 모든 레플리카셋 멤버에게 복사한다.
  • 키 파일은 반드시 읽기 전용으로 관리한다.
  • 가능하면 키 파일은 버전 관리 시스템에 등록하지 않고, 별도로 관리 한다.