LoginSignup
4
3

More than 5 years have passed since last update.

MongoDBのシャーディングをローカルで動作確認する

Last updated at Posted at 2012-05-09

configサーバーの起動

configサーバーを起動する。configサーバーはシャーディングの設定などが保存される。

configサーバーの起動
$ mongod --port 27030 --dbpath=config

mongosの起動

起動時にconfigサーバーを指定する。
オプションでchanksizeを指定できる。省略すると200MBになる。ここではテストのため1MBを指定する。

mongosの起動
$ mongos --port 27017 --configdb localhost:27030 --chunkSize 1

各シャードの起動

各シャードの起動
$ mongod --port 27021 --dbpath=shard1
$ mongod --port 27022 --dbpath=shard2
$ mongod --port 27023 --dbpath=shard3

シャーディングの設定

mongosに接続して各シャードを関連付ける

mongosへの接続
$ mongo localhost:27017/admin
MongoDB shell version: 1.7.5connecting to: admin
> db.runCommand({"addShard" : "localhost:27021"})
> db.runCommand({"addShard" : "localhost:27022"})
> db.runCommand({"addShard" : "localhost:27023"})
> db.adminCommand({"enableSharding" : "db_name"})
> db.adminCommand({"shardCollection" : "db_name.collection_name", key : {"key_name" : 1}})

あとはmongosに接続してオラオラすればよい

mongosへの接続
$ mongo localhost:27017/db_name
MongoDB shell version: 1.7.5connecting to: db_name
> 
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3