카이도스의 Tech Blog

Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) 본문

DB

Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정)

카이도스 2024. 2. 23. 23:14
728x90
반응형

2024.02.23 - [DB] - Mongodb Shard Cluster 설치 - 2(연동 작업)

 

Mongodb Shard Cluster 설치 - 2(연동 작업)

2024.02.23 - [DB] - Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) vm(PROXMOX) 여유가 있는편이라 적정한 스펙으로 10개 생성 후 진행했습니다. 서버가 부

djdakf1234.tistory.com

2024.02.26 - [DB] - Mongodb Shard Cluster - 구성 고도화

 

Mongodb Shard Cluster - 구성 고도화

2024.02.23 - [DB] - Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) 2024.02.23 - [DB] - Mongodb Shard Cluster 설치 - 2(연동 작업) Mongodb Shard Cluster 설치 - 2(연동 작

djdakf1234.tistory.com


Mongo Shard 구성도

vm(PROXMOX) 여유가 있는편이라 적정한 스펙으로 10개 생성 후 진행했습니다.
서버가 부족하다면 포트 변경 통해 적은 서버로도 구성 가능하니 참고부탁드립니다.


서버구성

  • 버전
    • Ubuntu 22.04
    • mongodb version v7.0.5
  • mongos
    • 10.10.X.180:27017
  • Config Server
    • 10.10.X.181:27050
    • 10.10.X.184:27050
    • 10.10.X.187:27050
  • Shard1
    • 10.10.X.181:27017
    • 10.10.X.182:27017
    • 10.10.X.183:27017
  • Shard2
    • 10.10.X.184:27017
    • 10.10.X.185:27017
    • 10.10.X.186:27017
  • Shard3
    • 10.10.X.187:27017
    • 10.10.X.188:27017
    • 10.10.X.189:27017

Mongodb shard 기본 셋팅

더보기
# 사전작업
## 호스트네임 변경
sudo hostnamectl set-hostname 호스트네임

# apt
sudo apt update && sudo apt upgrade -y

# 커널 설정 (/etc/sysctl.conf)
sudo su -
cat <<EOT>> /etc/sysctl.conf
vm.swappiness=1

net.core.netdev_max_backlog=30000
net.ipv4.tcp_max_syn_backlog=30000

net.ipv4.tcp_syn_retries=3
net.ipv4.tcp_retries1=3

net.core.rmem_max=268435456
net.core.wmem_max=268435456
net.core.rmem_default=10485760
net.core.wmem_default=10485760
net.ipv4.tcp_rmem=4096 87380 134217728
net.ipv4.tcp_wmem=4096 87380 134217728

net.core.somaxconn=65535
net.ipv4.tcp_fin_timeout=12
vm.max_map_count=9999999
net.ipv4.ip_local_port_range=1024 61000
net.ipv4.tcp_max_tw_buckets=540000
EOT

# 반영
sysctl -p

# Limits 설정 (/etc/security/limits.conf)
cat <<EOT>> /etc/security/limits.conf
*         hard    nofile     1048576
*         soft    nofile     1048576
*         hard    nproc      unlimited
*         soft    nproc      unlimited
*         hard    stack      unlimited
*         soft    stack      unlimited
*         hard    core       unlimited
*         soft    core       unlimited
EOT

# 리부팅
reboot
------------------------------------------------------------------------------------------------------------------------------
# 설치
## 몽고디비 7.0 공용 키 다운
curl -fsSL https://pgp.mongodb.com/server-7.0.asc |    sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg    --dearmor

## 몽고디비 리스트 파일 생성
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

## 패키지 내려받기
sudo apt update && sudo apt install -y mongodb-org

------------------------------------------------------------
# 각 서버에 맞게 생성
## data 디렉터리 생성
sudo mkdir -p /data/mongodb/data/configdb
sudo mkdir -p /data/mongodb/data/shard_1
sudo mkdir -p /data/mongodb/data/shard_2
sudo mkdir -p /data/mongodb/data/shard_3

## log 디렉터리 생성
sudo mkdir -p /data/mongodb/log/mongos
sudo mkdir -p /data/mongodb/log/configdb
sudo mkdir -p /data/mongodb/log/shard_1
sudo mkdir -p /data/mongodb/log/shard_2
sudo mkdir -p /data/mongodb/log/shard_3

## conf 디렉터리, 파일 생성
sudo mkdir -p /data/mongodb/conf && cd /data/mongodb/conf 
sudo touch mongos.conf
sudo touch configsvr.conf
sudo touch shard_1.conf
sudo touch shard_2.conf
sudo touch shard_3.conf

# pid 디렉터리 생성
sudo mkdir -p /data/mongodb/pid

# 소유권 변경
sudo chown -R ubuntu:ubuntu /data/

configsvr.conf

더보기
# configsvr.conf
cat <<EOT>> /data/mongodb/conf/configsvr.conf
storage:
  dbPath: /data/mongodb/data/configdb

systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/log/configdb/configdb.log

net:
  port: 27050
  bindIp: 0.0.0.0

processManagement:
  fork: true
  pidFilePath: /data/mongodb/pid/configdb.pid
  timeZoneInfo: /usr/share/zoneinfo

replication:
  replSetName: "configrs"

sharding:
  clusterRole: configsvr
EOT

shard_1.conf

더보기
# shard_1.conf
cat <<EOT>> /data/mongodb/conf/shard_1.conf
storage:
  dbPath: /data/mongodb/data/shard_1

systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/log/shard_1/shard_1.log

net:
  port: 27017
  bindIp: 0.0.0.0

processManagement:
  fork: true
  pidFilePath: /data/mongodb/pid/shard_1.pid
  timeZoneInfo: /usr/share/zoneinfo

replication:
  replSetName: rs1

sharding:
  clusterRole: shardsvr
EOT

shard_2.conf

더보기
# shard_2.conf
cat <<EOT>> /data/mongodb/conf/shard_2.conf
storage:
  dbPath: /data/mongodb/data/shard_2

systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/log/shard_2/shard_2.log

net:
  port: 27017
  bindIp: 0.0.0.0

processManagement:
  fork: true
  pidFilePath: /data/mongodb/pid/shard_2.pid
  timeZoneInfo: /usr/share/zoneinfo

replication:
  replSetName: rs2

sharding:
  clusterRole: shardsvr
EOT

shard_3.conf

더보기
# shard_3.conf
cat <<EOT>> /data/mongodb/conf/shard_3.conf
storage:
  dbPath: /data/mongodb/data/shard_3

systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/log/shard_3/shard_3.log

net:
  port: 27017
  bindIp: 0.0.0.0

processManagement:
  fork: true
  pidFilePath: /data/mongodb/pid/shard_3.pid
  timeZoneInfo: /usr/share/zoneinfo

replication:
  replSetName: rs3

sharding:
  clusterRole: shardsvr
EOT

mongos.conf

더보기
# mongos.conf
cat <<EOT>> /data/mongodb/conf/mongos.conf
systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/log/mongos/mongos.log

net:
  port: 27017
  bindIp: 0.0.0.0

processManagement:
#  fork: true
# pidFilePath: /data/mongodb/pid/mongos.pid
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  configDB: "configrs/10.10.x.181:27050,10.10.x.184:27050,10.10.x.187:27050"
EOT
728x90
반응형

'DB' 카테고리의 다른 글

sharding 테스트  (0) 2024.02.23
Mongodb Shard Cluster 설치 - 2(연동 작업)  (0) 2024.02.23
Redis 설치  (1) 2024.02.04
op로그 덤프&&복구  (0) 2024.02.04
Mongodb - bakcup(cron)/백업 스크립트  (2) 2024.02.04
Comments