LoginSignup
6
6

More than 5 years have passed since last update.

MongoDB 3.2で設定サーバ(configサーバ)をレプリカセットで立てるメモ

Last updated at Posted at 2016-08-30

MongoDB 3.2から設定サーバ(configサーバ)はレプリカセット構成になった。なので、configサーバの立て方が以前と少し違う。どこにもコマンド例がなかったため、備忘録として残しておく。

configサーバを3台レプリカで組む

configサーバを起動するときは、--configsvrに加えて--replSet (レプリカセット名)のオプションもつけなくてはいけない

コマンド例

$ ./bin/mongod --configsvr --replSet rsConfig --dbpath config00 --logpath config00.log --port 30000 --fork

$ ./bin/mongod --configsvr --replSet rsConfig --dbpath config01 --logpath config01.log --port 30001 --fork

$ ./bin/mongod --configsvr --replSet rsConfig --dbpath config02 --logpath config02.log --port 30002 --fork

そして、この3台でクラスタを組む。どこか一台に入ってrs.initiate

コマンド例

mongod> rs.initiate(
   {
      _id: "rsConfig",
      version: 1,
      members: [
         { _id: 0, host : "127.0.0.1:30000" },
         { _id: 1, host : "127.0.0.1:30001" },
         { _id: 2, host : "127.0.0.1:30002" }
      ]
   }
)

configサーバを3台レプリカにmongosルータから接続する

そして、mongosルータから繋ぐ場合は以下のようにレプリカセットを指定する

コマンド例

$ ./bin/mongos --configdb "rsConfig/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"  --logpath mongos00.log --port 31000 --fork

6
6
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
6
6