全3台の定義ファイルを変更
$ sudo vi /etc/mongodb.conf
## ReplicaSetsの名前をつける。のちの設定で使用。
==
replSet = log_rep
==
## 変更後サービスの再起動
$ sudo service mongodb restart
現状のステータス
以降、PrimaryのMongoにアクセスして設定を行う。
> rs.status()自分自身の定義
{
"startupStatus" : 3,
"info" : "run rs.initiate(...) if not yet done for the set",
"errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)",
"ok" : 0
}
> config = {_id: 'log_rep', members: [{_id: 0, host: '10.20.30.191:27017'}]} ★定義ファイルで指定した名前が_id部初期化
{
"_id" : "log_rep",
"members" : [
{
"_id" : 0,
"host" : "10.20.30.191:27017"
}
]
}
> rs.initiate(config)
{
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}
>
初期化完了
> rs.status()SECONDARYの定義追加
{
"set" : "log_rep",
"date" : ISODate("2012-03-23T09:49:38Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "10.20.30.191:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1332496142000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-23T09:49:02Z"),
"self" : true
}
],
"ok" : 1
}
PRIMARY> rs.add("10.20.30.192")Secondaryのほうは何もしなくて良い
{ "ok" : 1 }
PRIMARY> rs.status()
{
"set" : "log_rep",
"date" : ISODate("2012-03-23T09:55:43Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "10.20.30.191:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1332496301000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-23T09:51:41Z"),
"self" : true
},
{
"_id" : 1,
"name" : "10.20.30.192:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY", ★無事SECONDARYになった!
"uptime" : 242,
"optime" : {
"t" : 1332496301000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-23T09:51:41Z"),
"lastHeartbeat" : ISODate("2012-03-23T09:55:41Z"),
"pingMs" : 0
}
],
"ok" : 1
}
SECONDARY> rs.status()Arbiterの設定
{
"set" : "log_rep",
"date" : ISODate("2012-03-23T10:01:54Z"),
"myState" : 2,
"syncingTo" : "10.20.30.191:27017",
"members" : [
{
"_id" : 0,
"name" : "10.20.30.191:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 604,
"optime" : {
"t" : 1332496301000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-23T09:51:41Z"),
"lastHeartbeat" : ISODate("2012-03-23T10:01:53Z"),
"pingMs" : 1
},
{
"_id" : 1,
"name" : "10.20.30.192:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"optime" : {
"t" : 1332496301000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-23T09:51:41Z"),
"self" : true
}
],
"ok" : 1
}
Arbiterの設定もPrimaryで行う。
Secondary追加時同様、しばらく待つとできあがる
PRIMARY> rs.addArb("10.20.30.190:27017")
PRIMARY> rs.status()
{
"set" : "log_rep",
"date" : ISODate("2012-03-26T08:23:53Z"),
"myState" : 1,
"syncingTo" : "10.20.30.192:27017",
"members" : [
{
"_id" : 0,
"name" : "10.20.30.191:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1332749742000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-26T08:15:42Z"),
"self" : true
},
{
"_id" : 1,
"name" : "10.20.30.192:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 514,
"optime" : {
"t" : 1332749742000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-26T08:15:42Z"),
"lastHeartbeat" : ISODate("2012-03-26T08:23:53Z"),
"pingMs" : 1
},
{
"_id" : 2,
"name" : "10.20.30.190:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER", ★ Arbiterが追加されたことを確認
"uptime" : 390,
"optime" : {
"t" : 0,
"i" : 0
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2012-03-26T08:23:53Z"),
"pingMs" : 1
}
],
"ok" : 1
}
Arbiterのほうでmongoに入るとARBITERになってるのが確認できる
ARBITER>
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。