設定例

based on v8

下記は、2つのshard (1 shardは1サーバ)、1つのconfig db、一つのmongosプロセス、それらすべてを一つのテストサーバで動かす例です。

$ mkdir /data/db/a 
$ mkdir /data/db/b 
$ mkdir /data/db/config 
$ ./mongod --dbpath /data/db/a --port 10000 > /tmp/sharda.log & 
$ cat /tmp/sharda.log 
$ ./mongod --dbpath /data/db/b --port 10001 > /tmp/shardb.log & 
$ cat /tmp/shardb.log 
$ ./mongod --dbpath /data/db/config --port 20000 > /tmp/configdb.log & 
$ cat /tmp/configdb.log 
$ ./mongos --configdb localhost:20000 > /tmp/mongos.log & 
$ cat /tmp/mongos.log 

$ # mongosプロセスへ接続 
$ ./mongo 
MongoDB shell version: 1.1.0- 
url: test 
connecting to: test 
type "help" for help 
> use admin 
switched to db admin 
> db.runCommand( { addshard : "localhost:10000", allowLocal : true } ) 
{"ok" : 1 , "added" : "localhost:10000"} 
> db.runCommand( { addshard : "localhost:10001", allowLocal : true } ) 
{"ok" : 1 , "added" : "localhost:10001"} 

> config = connect("localhost:20000") 
> config = config.getSisterDB("config") 

> test = db.getSisterDB("test") 
test 

> db.runCommand( { enablesharding : "test" } ) 
{"ok" : 1} 
> db.runCommand( { shardcollection : "test.people", key : {name : 1} } ) 
{"ok" : 1} 

> db.runCommand({listshards:1}) 
{"servers" : [{"_id" : ObjectId( "4a9d40c981ba1487ccfaa634") , "host" : "localhost:10000"}, 
{"_id" : ObjectId( "4a9d40df81ba1487ccfaa635") , "host" : "localhost:10001"}] , 
"ok" : 1} 
> 

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.

These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group.

blog comments powered by Disqus