'mongo sharding'에 해당되는 글 1건

  1. 몽고DB Sharding 설정 및 테스트 16

테스트 환경 : Win7 64bit, SSD 128G, Memory 8G

 
1. DB 폴더 생성(관리자 권한 실행)

D:\DB\MONGO>mkdir SHARD1, SHARD2, CONFIG

 
2. 샤딩 서비스 실행

가. 설정 서버 실행

D:\DB\MONGO>mongod --dbpath D:\DB\MONGO\CONFIG --port 20000

 
나. 라우팅 서버 실행

D:\DB\MONGO>mongos --port 30000 --configdb localhost:20000

 
다. 샤딩 인스턴스 1, 2 실행

D:\DB\MONGO>mongod --dbpath D:\DB\MONGO\SHARD1 --port 10000
D:\DB\MONGO>mongod --dbpath D:\DB\MONGO\SHARD2 --port 10001  

 
3. 샤딩 구성

가. mongos 라우팅 인스턴스 접속

C:\Users\judydba>mongo localhost:30000/admin

MongoDB shell version: 2.0.2

connecting to: localhost:30000/admin


 
나. 샤드 구성
addshard 명령어로 샤드를 추가

mongos> db.runCommand( {addshard : "localhost:10000", allowLocal:true})

{ "shardAdded" : "shard0000", "ok" : 1 }

mongos> db.runCommand( {addshard : "localhost:10001", allowLocal:true})

{ "shardAdded" : "shard0001", "ok" : 1 }

※ allowLocal 키는 localhost에 샤드를 실행할 때만 필요합니다. 몽고디비는 실수로 로컬에 클러스터를 설정하는 사태를 막기 위해. allowLocal:true는 생략 가능
 

다. 데이터 샤딩
데이타 분산을 위한 데이터베이스와 컬렉션 수준으로 명시적 설정 
testdb의 test collection을 분산.
분산을 위한 샤드 키는 seq 설정

mongos> db.runCommand({ "enablesharding" : "testdb" })

{ "ok" : 1 }

mongos> db.runCommand({ "shardcollection" : "testdb.test", "key" : {"seq" : 1}})

{ "collectionsharded" : "testdb.test", "ok" : 1 }

 
라. 샤드 구성 확인
청크 사이즈  64M

mongos> use config

switched to db config

mongos> db.shards.find();

{ "_id" : "shard0000", "host" : "localhost:10000" }

{ "_id" : "shard0001", "host" : "localhost:10001" }

mongos> db.databases.find()

{ "_id" : "admin", "partitioned" : false, "primary" : "config" }

{ "_id" : "testdb", "partitioned" : true, "primary" : "shard0000" }

mongos> db.chunks.find()

{ "_id" : "testdb.test-seq_MinKey", "lastmod" : { "t" : 1000, "i" : 0 }, "ns" :

"testdb.test", "min" : { "seq" : { $minKey : 1 } }, "max" : { "seq" : { $maxKey

: 1 } }, "shard" : "shard0000" }
 

mongos> db.printShardingStatus()

--- Sharding Status ---

  sharding version: { "_id" : 1, "version" : 3 }

  shards:

        {  "_id" : "shard0000",  "host" : "localhost:10000" }

        {  "_id" : "shard0001",  "host" : "localhost:10001" }

  databases:

        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }

        {  "_id" : "testdb",  "partitioned" : true,  "primary" : "shard0000" }

                testdb.test chunks:

                                shard0000       1

                        { "seq" : { $minKey : 1 } } -->> { "seq" : { $maxKey : 1

 } } on : shard0000 { "t" : 1000, "i" : 0 }

 
 
4. 테스트
500000 데이타를 입력

mongos> use testdb
switched to db testdb

mongos> for(i=0; i<500000; i++) { db.test.insert({"_id" : i, "seq" : i+5000, "date": new Date() }); }


5. 청크 정보 확인

mongos> use config

switched to db config

mongos> db.chunks.find()

{ "_id" : "testdb.test-seq_MinKey", "lastmod" : { "t" : 2000, "i" : 1 }, "ns" :

"testdb.test", "min" : { "seq" : { $minKey : 1 } }, "max" : { "seq" : 5000 }, "s

hard" : "shard0000" }

{ "_id" : "testdb.test-seq_5000.0", "lastmod" : { "t" : 1000, "i" : 3 }, "ns" :

"testdb.test", "min" : { "seq" : 5000 }, "max" : { "seq" : 17024 }, "shard" : "s

hard0000" }

{ "_id" : "testdb.test-seq_17024.0", "lastmod" : { "t" : 2000, "i" : 2 }, "ns" :

 "testdb.test", "min" : { "seq" : 17024 }, "max" : { "seq" : 419135 }, "shard" :

 "shard0001" }

{ "_id" : "testdb.test-seq_419135.0", "lastmod" : { "t" : 2000, "i" : 3 }, "ns"

: "testdb.test", "min" : { "seq" : 419135 }, "max" : { "seq" : { $maxKey : 1 } }

, "shard" : "shard0001" }
 

mongos> db.printShardingStatus()

--- Sharding Status ---

  sharding version: { "_id" : 1, "version" : 3 }

  shards:

        {  "_id" : "shard0000",  "host" : "localhost:10000" }

        {  "_id" : "shard0001",  "host" : "localhost:10001" }

  databases:

        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }

        {  "_id" : "testdb",  "partitioned" : true,  "primary" : "shard0000" }

                testdb.test chunks:

                                shard0000       2

                                shard0001       2

                        { "seq" : { $minKey : 1 } } -->> { "seq" : 5000 } on : s

hard0000 { "t" : 2000, "i" : 1 }

                        { "seq" : 5000 } -->> { "seq" : 17024 } on : shard0000 {

 "t" : 1000, "i" : 3 }

                        { "seq" : 17024 } -->> { "seq" : 419135 } on : shard0001

 { "t" : 2000, "i" : 2 }

                        { "seq" : 419135 } -->> { "seq" : { $maxKey : 1 } } on :

 shard0001 { "t" : 2000, "i" : 3 }

데이타가 증가할 수록 moveChunk 폴더가 생기면서 데이타가 분리되었음을 확인가능함.

shard0000, shard0001 청크가 2개씩 존재하며, 각 샤드키로 분산되어 있다.

shard0000 : seq 1 ~ 50000
shard0000 : seq 5000~17024
shard0001 : seq 17024 ~ 419135
shard0001 : seq 419135 ~ Max

 


'Etc' 카테고리의 다른 글

몽고DB Replicated Shard Cluster + Arbitor  (0) 2012.03.19
몽고DB 활용 사례  (0) 2012.03.19
SQL 설치 유용한 스크립트  (0) 2012.02.24
journal 폴더가 왜 생기는 걸까?  (0) 2012.02.21
몽고DB Config 설정하기(Win7)  (0) 2012.02.20