[MongoDB]: How to configure & reconfigure a RS
[root@ip-10-0-0-28 /]# ps -ef | grep mongo
root 7135 2216 0 01:26 pts/0 00:00:00 mongod –replSet rs2 –dbpath /root/data4 –logpath /root/data4/mongod1.log –port 27010 –smallfiles –nojournal
root 7191 2216 0 01:26 pts/0 00:00:00 mongod –replSet rs2 –dbpath /root/data5 –logpath /root/data5/mongod2.log –port 27011 –smallfiles –nojournal
root 7209 2216 0 01:26 pts/0 00:00:00 mongod –replSet rs2 –dbpath /root/data6 –logpath /root/data6/mongod3.log –port 27012 –smallfiles –nojournal
root 7249 2216 0 01:28 pts/0 00:00:00 grep mongo
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]#
[root@ip-10-0-0-28 /]# mongo –port 27010
MongoDB shell version: 3.0.4
connecting to: 127.0.0.1:27010/test
Server has startup warnings:
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten]
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten]
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2015-06-30T01:26:33.663+0000 I CONTROL [initandlisten]
>
>
>
>
> var rsconf = {
… _id: “rs2”,
… members: [
… {
… _id: 0,
… host: ‘ip-10-0-0-28:27010’
… },
… {
… _id: 1,
… host: ‘ip-10-0-0-28:27011’
… },
… {
… _id: 2,
… host: ‘ip-10-0-0-28:27012’
… }
… ]
… };
>
>
> rs.initiate(rsconf);
{ “ok” : 1 }
rs2:OTHER>
rs2:SECONDARY>
rs2:SECONDARY>
rs2:SECONDARY>
rs2:SECONDARY>
rs2:SECONDARY>
rs2:SECONDARY>
rs2:PRIMARY>
rs2:PRIMARY>
rs2:PRIMARY>
rs2:PRIMARY> rs.status()
{
“set” : “rs2”,
“date” : ISODate(“2015-06-30T01:29:28.629Z”),
“myState” : 1,
“members” : [
{
“_id” : 0,
“name” : “ip-10-0-0-28:27010”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 175,
“optime” : Timestamp(1435627757, 1),
“optimeDate” : ISODate(“2015-06-30T01:29:17Z”),
“electionTime” : Timestamp(1435627761, 1),
“electionDate” : ISODate(“2015-06-30T01:29:21Z”),
“configVersion” : 1,
“self” : true
},
{
“_id” : 1,
“name” : “ip-10-0-0-28:27011”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 11,
“optime” : Timestamp(1435627757, 1),
“optimeDate” : ISODate(“2015-06-30T01:29:17Z”),
“lastHeartbeat” : ISODate(“2015-06-30T01:29:27.412Z”),
“lastHeartbeatRecv” : ISODate(“2015-06-30T01:29:27.419Z”),
“pingMs” : 0,
“configVersion” : 1
},
{
“_id” : 2,
“name” : “ip-10-0-0-28:27012”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 11,
“optime” : Timestamp(1435627757, 1),
“optimeDate” : ISODate(“2015-06-30T01:29:17Z”),
“lastHeartbeat” : ISODate(“2015-06-30T01:29:27.412Z”),
“lastHeartbeatRecv” : ISODate(“2015-06-30T01:29:27.416Z”),
“pingMs” : 0,
“configVersion” : 1
}
],
“ok” : 1
}
rs2:PRIMARY>
rs2:PRIMARY>
rs2:PRIMARY>
rs2:PRIMARY> var rsconf_new = {
… _id: “rs2”,
… members: [
… {
… _id: 0,
… host: ‘ip-10-0-0-28:27012’
… },
… {
… _id: 1,
… host: ‘ip-10-0-0-28:27011’
… },
… {
… _id: 2,
… host: ‘ip-10-0-0-28:27010’
… }
… ]
… };
rs2:PRIMARY>
rs2:PRIMARY> rs.re
rs.reconfig( rs.remove(
rs2:PRIMARY> rs.reconfig(rsconf_new)
{
“ok” : 0,
“errmsg” : “New and old configurations both have members with host of ip-10-0-0-28:27012 but in the new configuration the _id field is 0 and in the old configuration it is 2 for replica set rs2”,
“code” : 103
}
rs2:PRIMARY>
rs2:PRIMARY>