Shardingの管理

based on v13

ここでは、shardingクラスタから情報を取得するためのコマンドを紹介します。

shardingクラスタを設定するためには、 Shardingの設定 を参照してください。

shardクラスタの確認

 
// mongosプロセスにつないでいるか、
// mongodプロセスに直接つないでいるかの確認
> db.runCommand({ isdbgrid : 1});

// mongosに接続している場合、このコマンドは、 { ismaster: 0.0, msg: "isdbgrid" } を返します。
> db.runCommand({ismaster:1})

存在するShardのリスト表示

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

どのデータベースがshard化されているかのリスト表示

ここで、configデータベースに対してクエリを実行します( mongos 経由ですが )。 この getSisterDB コマンドは以前はconfigデータベースを取得するために使われます。

> config = db.getSisterDB("config") 
> config.system.namespaces.find() 

shardingの詳細を確認

 
> use admin
> db.printShardingStatus());

// A very basic sharding configuration on localhost
sharding version: { "_id" : 1, "version" : 2 }
shards:
{ "_id" : ObjectId("4bd9ae3e0a2e26420e556876"), "host" : "localhost:30001" }
{ "_id" : ObjectId("4bd9ae420a2e26420e556877"), "host" : "localhost:30002" }
{ "_id" : ObjectId("4bd9ae460a2e26420e556878"), "host" : "localhost:30003" }

databases:
{ "name" : "admin", "partitioned" : false, 
"primary" : "localhost:20001", 
"_id" : ObjectId("4bd9add2c0302e394c6844b6") }
my chunks

{ "name" : "foo", "partitioned" : true,
"primary" : "localhost:30002", 
"sharded" : { "foo.foo" : { "key" : { "_id" : 1 }, "unique" : false } },
"_id" : ObjectId("4bd9ae60c0302e394c6844b7") }
my chunks
foo.foo { "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } 
on : localhost:30002 { "t" : 1272557259000, "i" : 1 }

printShardingStatus コマンドの出力に注目してください。 最初にこのクラスタを含む3つのshardの場所が出ています。次に、このクラスタがあるいくつかのデータベースが出ます。

最初のデータベースは、分割されていないadminデータベースです。 primary フィールドはデータベースの場所を指し、adminデータベースの場合には、port 20001で動いているconfigサーバになります。

二つめのデータベースは、 分割されて いることがわかります。 また、shardのキーと場所、そしてこのパーティションに含まれるchunkのレンジがわかります。 foo データベースにはデータがまだ何もないので、一つのchunkしかありません。この一つのchunkがshardキーの全体のレンジを含みます。

chunk操作

MongoDB 1.6 では、chunkの調整は自動的に行われます。しかし、手動で動かしたい場合には、以下のコマンドで可能です。

db.runCommand( { movechunk : "test.blog.posts" , 
find : { author : "eliot" } , 
to : "192.168.1.2" } )

パラメータ:

  • movechunk: <データベース名を含む、コレクションの完全な名前>
  • find: <移動したいchunkのクエリ>
  • to: <移動するchunkの移動先のアドレス>

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