When following the replica set instructions for a single machine at: okbook.mongodb.org/operations/convert-replica-set-to-replicated-shard-cluster/
You may find an error when trying to setup the replica set.
"errmsg" : "can't currently get local.system.replset config from self or any seed (EMPTYUNREACHABLE)"
The problem here is they changed the code to disallow mixing of localhost and ip addresses. You have to change localhost to localhost.localdomain.
There are many ways to configure and initialize the replica set. The master for the replica set is first one you start. Using the commands as listed on the mongo page sets up 3 replica sets with the localhost:10001 as the master since this is the first mongod command to be invoked.
bin/mongod --dbpath /data/example/firstset1 --port 10001 --replSet firstset --oplogSize 700 --rest
bin/mongod --dbpath /data/example/firstset2 --port 10002 --replSet firstset --oplogSize 700 --rest
$ bin/mongod --dbpath /data/example/firstset3 --port 10003 --replSet firstset --oplogSize 700 --rest
After the above 3 commands we still dont have a replica set. We have to connect to localhost:10001 and initiate the replica set. There are equivalent commands all of which can be run from the mongo client connected to localhost:10001/admin:
> db.runCommand({"replSetInitiate" : {"_id" : "firstset", "members" : [{"_id" : 1, "host" : "localhost:10001"}, {"_id" : 2, "host" : "localhost:10002"}, {"_id" : 3, "host" : "localhost:10003"}]}})
The problem is the above command doesn't work.
When you go to url: localhost:11002 (NOTE PORT increased by 1000) you see:
05:50:47 [rsStart] couldn't connect to dc-pc:10003: couldn't connect to server dc-pc:10003
and you get error messages like:
"info" : "try querying local.system.replset to see current configuration",
TO fix: run the command db.reconfig(config) where config is set as:
config = {_id: 'firstset', members: [ {_id: 0, host: 'localhost:10001'},{_id: 1, host: 'localhost.localdomain:10002'}, {_id:2,host:'localhost.localdomain:10003'}] }
After running this command(my replica set was called rs0 instead of firstset):
rs0:PRIMARY> config = {_id: 'rs0', members: [ {_id: 0, host: 'localhost.localdomain:10001'},{_id: 1, host: 'localhost.localdomain:10002'}, {_id:2,host:'localhost.localdomain:10003'}] }
rs0:PRIMARY> rs.reconfig(config)
{ "ok" : 1 }
Then do an rs.status() and verify the master can see/ping all 3 replica set members:
rs0:PRIMARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2012-09-24T12:50:50Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "localhost.localdomain:10001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 35048,
"optime" : Timestamp(1348491046000, 1),
"optimeDate" : ISODate("2012-09-24T12:50:46Z"),
"self" : true
},
{
"_id" : 1,
"name" : "localhost.localdomain:10002",
"health" : 1,
"state" : 5,
"stateStr" : "STARTUP2",
"uptime" : 4,
"optime" : Timestamp(0, 0),
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2012-09-24T12:50:50Z"),
"pingMs" : 0,
"errmsg" : "initial sync need a member to be primary or secondary to do our initial sync"
},
{
"_id" : 2,
"name" : "localhost.localdomain:10003",
"health" : 1,
"state" : 5,
"stateStr" : "STARTUP2",
"uptime" : 4,
"optime" : Timestamp(0, 0),
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2012-09-24T12:50:50Z"),
"pingMs" : 0,
"errmsg" : "initial sync need a member to be primary or secondary to do our initial sync"
}
],
"ok" : 1
}
Then go back to the REST interface for the slaves and verify:
05:50:48 [rsStart] trying to contact localhost.localdomain:10001 05:50:48 [rsStart] replSet I am localhost.localdomain:10003 05:50:48 [rsStart] replSet got config version 2 from a remote, saving locally 05:50:48 [rsStart] replSet info saving a newer config version to local.system.replset 05:50:48 [rsStart] replSet saveConfigLocally done 05:50:48 [rsStart] replSet STARTUP2 05:50:48 [rsSync] replSet initial sync pending 05:50:48 [rsSync] replSet initial sync need a member to be primary or secondary to do our initial sync 05:50:50 [rsHealthPoll] replSet member localhost.localdomain:10001 is up 05:50:50 [rsHealthPoll] replSet member localhost.localdomain:10001 is now in state PRIMARY 05:50:50 [rsHealthPoll] replSet member localhost.localdomain:10002 is up 05:50:50 [rsHealthPoll] replSet member localhost.localdomain:10002 is now in state STARTUP2 05:51:04 [rsSync] replSet initial sync pending 05:51:04 [rsSync] replSet syncing to: localhost.localdomain:10001 05:51:04 [rsSync] replSet initial sync drop all databases 05:51:04 [rsSync] replSet initial sync clone all databases 05:51:04 [rsSync] replSet initial sync cloning db: config 05:51:04 [rsSync] replSet initial sync cloning db: admin 05:51:17 [rsSync] replSet initial sync cloning db: system 05:51:17 [rsSync] replSet initial sync data copy, starting syncup 05:51:17 [rsSync] replSet initial sync building indexes 05:51:17 [rsSync] replSet initial sync cloning indexes for : config 05:51:17 [rsSync] replSet initial sync cloning indexes for : admin 05:51:17 [rsSync] replSet initial sync cloning indexes for : system 05:51:17 [rsSync] replSet initial sync query minValid 05:51:17 [rsSync] replSet initial sync finishing up 05:51:17 [rsSync] replSet set minValid=50605726:1 05:51:17 [rsSync] replSet RECOVERING 05:51:17 [rsSync] replSet initial sync done 05:51:18 [rsHealthPoll] replSet member localhost.localdomain:10002 is now in state RECOVERING 05:51:18 [rsBackgroundSync] replSet syncing to: localhost.localdomain:10001 05:51:18 [rsSyncNotifier] replset setting oplog notifier to localhost.localdomain:10001 05:51:19 [rsSync] replSet SECONDARY 05:51:20 [rsHealthPoll] replSet member localhost.localdomain:10002 is now in state SECONDARY
No comments:
Post a Comment