Sharding Cluster 만들기(3) : conf파일

arky uhm·2025년 5월 23일

MongoDB

목록 보기
10/14

✅ mongod_config.conf

# mongod_config.conf - Configuration for Config Server Replica Set members

storage:
  dbPath: /data/db

systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true

net:
  port: 27017
  bindIp: 0.0.0.0
  tls:
    mode: requireTLS
    certificateKeyFile: /etc/ssl/mongodb/mongodb_sharded.pem
    CAFile: /etc/ssl/mongodb/ca_sharded.pem

security:
  authorization: enabled
  clusterAuthMode: x509

replication:
  replSetName: configRS

sharding:
  clusterRole: configsvr
  • 주요 설정
    • storage.dbPath: /data/db
      . 컨테이너 내에서 데이터가 저장될 경로로써 Docker Compose 파일에서 호스트의 data/configX 볼륨에 매핑됩니다.
    • net.port: 27017
      . 이 Config Server 인스턴스가 컨테이너 내부에서 리스닝하는 포트입니다. 외부 접근은 docker-compose_replica_shard.yml에 정의된 호스트 포트(30011, 30012, 30013 등)를 통해 이루어집니다.
    • net.bindIp: 0.0.0.0
      . 컨테이너 내의 모든 네트워크 인터페이스에 바인딩하여 다른 컨테이너(동일 네트워크의 다른 Config Server, Shard, Mongos)가 이 Config Server에 접근할 수 있도록 합니다.
    • net.tls.mode: requireTLS
      . 모든 인바운드 및 아웃바운드 연결에 대해 TLS 암호화를 필수로 설정합니다. 이로써 모든 통신이 암호화됩니다.
    • net.tls.certificateKeyFile: /etc/ssl/mongodb/mongodb_sharded.pem
      . 이 Config Server의 TLS 인증서와 프라이빗 키가 포함된 파일 경로입니다. 이 파일은 모든 샤드 클러스터 멤버(Config, Shard, Mongos)가 공유할 단일 인증서가 됩니다.
    • net.ication.replSetName: configRS
      . Config Server 레플리카 셋의 이름을 configRS로 정의합니다. 이 이름은 config1, config2, config3 세 멤버 모두에게 동일하게 적용되어야 합니다.
    • security.authorization: enabled
      . 사용자 인증 및 역할 기반 접근 제어(RBAC)를 활성화합니다. 클라이언트 접속 시 계정 인증이 필요합니다.
    • sharding.clusterRole: configsvr
      . 이 mongod 인스턴스가 샤딩 클러스터에서 Config Server 역할을 수행하도록 명시적으로 지정합니다. 이는 --configsvr 명령줄 옵션과 동일한 역할을 합니다.

✅ mongod_shard.conf

Config Server 설정(mongod_config.conf)과 매우 유사하지만, 샤드 서버의 역할에 맞게 replication.replSetName과 sharding.clusterRole 부분이 다릅니다.

# mongod_shard.conf - Configuration for Shard Server Replica Set members

storage:
  dbPath: /data/db

systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true

net:
  port: 27017
  bindIp: 0.0.0.0
  tls:
    mode: requireTLS
    certificateKeyFile: /etc/ssl/mongodb/mongodb_sharded.pem
    CAFile: /etc/ssl/mongodb/ca_sharded.pem

security:
  authorization: enabled
  clusterAuthMode: x509

replication:
  replSetName: shard1RS

sharding:
  clusterRole: shardsvr
  
  • 주요 설정 (Config Server 설정과의 차이점)
    • replication.replSetName: shard1RS
      . 가장 중요한 차이점입니다. Config Server의 replSetName은 configRS였지만, 각 샤드 레플리카 셋은 고유한 replSetName을 가져야 합니다. 우리는 첫 번째 샤드 셋을 shard1RS로 명명했습니다. 만약 나중에 shard2-a,b,c를 추가한다면, 해당 샤드 셋의 replSetName은 shard2RS가 되어야 합니다.
    • sharding.clusterRole: shardsvr
      . 이 mongod 인스턴스가 샤딩 클러스터에서 Shard Server 역할을 수행하도록 명시적으로 지정합니다 (mongod 프로세스는 mongod_shard_no_clusterRole.conf 파일의 설정을 읽고, 추가적으로 --shardsvr 옵션을 통해 "나는 샤드 서버다"라고 인식합니다). 이는 --shardsvr command-line option과 동일한 역할을 하는데, 만약 sharding.clusterRole 설정이 없다면, docker-compose.yml의 command 필드에서 --shardsvr 옵션을 직접 사용해야 합니다.
shard1-a:
  image: mongo:latest
  hostname: shard1-a
  container_name: shard1-a
  # ... 다른 설정들 ...
  volumes:
    - ./mongod_shard_no_clusterRole.conf:/etc/mongod.conf # 이 파일 사용
  command: ["mongod", "--config", "/etc/mongod.conf", "--shardsvr"] # <<-- 여기에 `--shardsvr` 옵션이 명시적으로 들어갑니다.
  # ... 나머지 설정들 ...

나머지 storage, systemLog, net, security, tls 설정은 Config Server와 동일하게 적용됩니다. 모든 샤드 클러스터 구성 요소가 동일한 TLS 인증서(mongodb_sharded.pem, ca_sharded.pem)와 보안 설정을 공유하도록 합니다.
mongod_shard.conf 파일 1개로 shard1-a, shard1-b, shard1-c 세 멤버 모두에게 동일하게 사용됩니다.


✅ mongos.conf

# mongos.conf - Configuration for Mongos Router

systemLog:
  destination: file
  path: /var/log/mongodb/mongos.log
  logAppend: true

net:
  port: 27017
  bindIp: 0.0.0.0
  tls:
    mode: requireTLS
    certificateKeyFile: /etc/ssl/mongodb/mongodb_sharded.pem
    CAFile: /etc/ssl/mongodb/ca_sharded.pem

security:
  clusterAuthMode: x509

sharding:
  configDB: configRS/config1:27017,config2:27017,config3:27017
  • 주요 설정
    • systemLog.path: /var/log/mongodb/mongos.log
      . mongos 프로세스의 로그 파일 경로를 지정합니다.
    • net.port: 27017
      . mongos 인스턴스가 컨테이너 내부에서 리스닝하는 포트로써 외부 접근은 docker-compose.yml에 정의된 호스트 포트(30001, 30002)를 통해 이루어집니다.
    • net.bindIp: 0.0.0.0
      . 컨테이너 내의 모든 네트워크 인터페이스에 바인딩하여 클라이언트와 Config Server, Shard Server가 mongos에 접근할 수 있도록 합니다.
    • net.tls.mode, net.tls.certificateKeyFile, net.tls.CAFile
      . Config Server 및 Shard Server와 동일하게 TLS 암호화를 필수로 설정하고, 동일한 인증서 및 CA 파일을 사용하는데, 이는 클라이언트<-->mongos 연결 및 mongos<-->mongod (Config/Shard) 연결 모두에 적용됩니다.
    • security.clusterAuthMode: x509
      . mongos와 Config Server, Shard Server 간의 내부 통신에 X.509 인증서를 사용하여 인증하도록 합니다.
    • sharding.configDB: configRS/config1:27017,config2:27017,config3:27017
      . 이 설정이 mongos.conf의 핵심이고, mongos가 클러스터 메타데이터를 어디에서 가져와야 하는지 Config Server Replica Set의 정보를 제공합니다.
      . 형식: <ConfigServerReplSetName>/<ConfigHost1>:<ContainerInternalPort>,<ConfigHost2>:<ContainerInternalPort>,<ConfigHost3>:<ContainerInternalPort>
      . 여기서 configRS는 Config Server 레플리카 셋의 이름입니다.
      . config1:27017,config2:27017,config3:27017는 Docker 내부 네트워크에서 컨테이너 이름과 컨테이너 내부 포트(27017)를 사용하여 Config Server 멤버들에 접근하도록 지정합니다.

mongos.conf 파일도 마찬가지로 1개로 mongos1과 mongos2 두 Mongos 라우터 컨테이너에 동일하게 사용될 것입니다.

주의) YAML 파일의 들여쓰기(Indentation) 오류 : YAML 파일은 들여쓰기에 매우 민감합니다. 한 칸이라도 들여쓰기가 잘못되면 파서가 옵션을 올바르게 인식하지 못할 수 있습니다.

0개의 댓글