-
[MongoDB] Create a Shareded Cluster in MongoDBprogramming 2019. 3. 13. 19:00
Requirement에 고정된 key에 따라 데이터가 지속적으로 확장되는 프로젝트가 있었다.
key를 기준으로 sharding이 되고 가져올때 빠르게 가져오고 관리적 측면이 편해야 했는데 이를 모두 충족시켜주는건 MongoDB Cluster라 생각되어 시스템을 구축하게 되었다.
생각보다 많은 자료가 있어서 초반 기념잡은 이후에 진행은 어렵지 않았다.
reference:
1. http://www.sunzhongkui.me/deploy-mongodb-sharded-replica-set-cluster/
2. http://rocksea.tistory.com/290
3. http://rocksea.tistory.com/13server 1
mongod –dbpath /user-history/hostname –port 10001 –replSet third –fork –quiet –oplogSize 1024 –logpath /user-history/log/hostname_3.log
server2
mongod –dbpath /user-history/hostname –port 10001 –replSet third –fork –quiet –oplogSize 1024 –logpath /user-history/log/hostname_3.log
각 서버에 mongod 데몬을 띄운후 해당 replSet을 엮어주기 위해 10001 포트 admin으로 접근한다.
# mongo hostname:10001/admin > db.runCommand({“replSetInitiate” : {“_id” : “third”, “members” : [{“_id” : 1, “host” : “server1-hostname:10003″}, {“_id” : 2, “host” : “server2-hostname:10003″}]}})
mongos admin에 접근하여 shard를 추가해준다.
#mongohostname/admin > db.runCommand( { addshard : “third/server1-hostname:10003,server2-hostname:10003″})
#db.printShardingStatus();
=> first,second가 이미 있는 상태에서 third를 추가하였고 각 shard에 어떻게 분배되고 있는지 확인 할 수 있다.
Arbiter
* Primary가 문제시 남은 노드중 Primary를 결정해주는 역할
나는 arbiter을 처음에 추가하지 않았기에 셋팅 후 추가를 하였다.
1) mongod –port 11000 –dbpath /user-history/arbiter –replSet first –fork –quiet –logpath /user-history/log/first-arbiter.log
2) rs.add({_id: 3, host: “hostname:11000″, arbiterOnly:true})
3) 추가 후 rs.stats()에서 보면 추가된 상태로 나오며 sateStr은 STARTUP2로 설정된것을 볼 수 있다.반응형'programming' 카테고리의 다른 글
[Spark tip] struct type을 csv로 저장시 에러 (0) 2019.04.08 Gevent / Celery 에 대하여 (0) 2019.03.13 Timsort python sorted 알고리즘 (0) 2019.03.13 MSSql Server Password Maximum error (0) 2019.03.13 python 한글+영어 길이 자르기 (0) 2019.03.13 댓글