본문 바로가기
MongoDB

[4.2]MongoDB sharding config-router 세팅하기

by 2세1의 행복한 개발 2020. 5. 26.
반응형

https://devel-lee.tistory.com/15

 

[4.2]mongoDB sharding shard 세팅하기

안녕하세요 오늘은 mongodb를 세팅하려고합니다 기본적인 서버는 router안에 config 3개를 넣고 나머지 두개 서버에 shard를 하나씩할 예정입니다 기본적으로 순서는 shard -> config -> router 순으로 합니다

devel-lee.tistory.com

안녕하세요. 오늘은 config,router를 세팅하려고 합니다

이전에 꼭 shard가 있어야 하므로 링크를 남깁니다

 

config랑 shard는 

conf파일에 

sharding:
  clusterRole: configsvr

만 다르고 나머지는 정말 똑같습니다

둘다 저장소이며 각자 저장하는 데이터만 다를뿐 형식은 같기 때문이죠

 

우선은 config는 서버를 여러대로 하면 정말 좋지만

우선 한대로 router와 함께 세팅했습니다

 

해당 서버는 router + configx3으로 이루어져 있습니다

 

config.conf 생성

vi /etc/mongo/conf/config1.conf
vi /etc/mongo/conf/config2.conf
vi /etc/mongo/conf/config3.conf

config1.conf

storage:
  dbPath: /etc/mongo/config1

systemLog:
  path: "/etc/mongo/config1/mongo.log"
  logAppend: true
  destination: file
  traceAllExceptions: false

processManagement:
  fork: true

sharding:
  clusterRole: configsvr

replication:
  replSetName: configRep

net:
  bindIp: 0.0.0.0
  port: 10001

config2.conf

storage:
  dbPath: /etc/mongo/config2

systemLog:
  path: "/etc/mongo/config2/mongo.log"
  logAppend: true
  destination: file
  traceAllExceptions: false

processManagement:
  fork: true

sharding:
  clusterRole: configsvr

replication:
  replSetName: configRep

net:
  bindIp: 0.0.0.0
  port: 10002

config3.conf

storage:
  dbPath: /etc/mongo/config3

systemLog:
  path: "/etc/mongo/config3/mongo.log"
  logAppend: true
  destination: file
  traceAllExceptions: false

processManagement:
  fork: true

sharding:
  clusterRole: configsvr

replication:
  replSetName: configRep

net:
  bindIp: 0.0.0.0
  port: 10003

conf파일에 보시면

dbPath가 있는데 해당 폴더가 없으면 실행이 안됩니다

꼭 폴더를 생성하신 후에 작업해주세요

 

config 실행

/bin/mongod -f /etc/mongo/conf/config1.conf
/bin/mongod -f /etc/mongo/conf/config2.conf
/bin/mongod -f /etc/mongo/conf/config3.conf

서버에 접속

mongo mongo_config:10001

config - replica set

rs.initiate()
cfg = rs.conf()
cfg.members[0].host = "mongo_config:10001"
rs.reconfig(cfg,{force:true})
rs.add("mongo_config:10002")
rs.add("mongo_config:10003")
rs.status()

이렇게 config가 쉽게 세팅이 끝났습니다

shard를 세팅하고 보면 다 똑같은 세팅이라 하다보면 익숙해집니다

 

router.conf 생성

vi /etc/mongo/conf/mongos.conf
systemLog:
  path: "/etc/mongo/mongos/mongo.log"
  logAppend: true
  destination: file
  traceAllExceptions: false

processManagement:
  fork: true

net:
  port: 27017
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:
#  authorization: enabled

sharding:
  configDB: configRep/mongo_config:10001,mongo_config:10002,mongo_config:10003

기본포트를 사용시 서버에서 mongo를 입력하면 바로 접속이 가능합니다

그래서 기본포트를 사용하여 mongs를 구현하였습니다

router 실행

/bin/mongos -f /etc/mongo/conf/mongos.conf

프로세스 확인

ps -ef | grep mongo
root      1875     1  0 May25 ?        00:00:14 /bin/mongod -f /etc/mongo/conf/config1.conf
root      1954     1  0 May25 ?        00:00:14 /bin/mongod -f /etc/mongo/conf/config2.conf
root      2040     1  0 May25 ?        00:00:14 /bin/mongod -f /etc/mongo/conf/config3.conf
root      2127     1  9 May25 ?        00:04:05 /bin/mongos -f /etc/mongo/conf/mongos.conf

접속

mongo

shard 추가

sh.addShard("rs1/mongo_shard1:20001,mongo_shard2:20002")

이렇게하면 끝났습니다.

그치만 이게 잘 되는지 확인을 해봐야겠죠?

 

log를 통하여 정상확인

tail -f /etc/mongo/mongos/mongo.log 

 

댓글