# mongod --rest --replSet myset
mongod --replSet myset --port 27017 --dbpath /data/db1
mongod --replSet myset --port 27018 --dbpath /data/db2
mongod --replSet myset --port 27019 --dbpath /data/db3
or set master config file:
dbpath = /data/db
#bind_ip = 127.0.0.1
port = 27017
#logpath = /var/log/mongodb.log
#logappend = true
master = true
replSet = myset
#nojournal = false
rest = true
and set slave config file:
dbpath = /data/db
#bind_ip = 127.0.0.1
port = 27017
#logpath = /var/log/mongodb.log
#logappend = true
replSet = myset
#nojournal = false
rest = true
slave = true
source = gambit:27017
* enter each's host name in your /etc/hosts file if you're using different hosts
-------------------------------------
initialize host replica set
# mongo --port 27017
> rs.initiate();
(http://www.mongodb.org/display/DOCS/Replica+Sets+-+Basics)
(http://www.kchodorow.com/blog/2010/07/30/replica-sets-part-1-master-slave-is-so-2009/)
got error couldn't initiate : can't find self in the replset config
supply config using localhost works!
> config = {_id: 'myset', members: [
{_id: 0, host:'localhost:27017'},
{_id: 1, host:'localhost:27018'},
{_id: 2, host:'localhost:27019'}]
}
> rs.initiate(config)
changing config
> config = {_id: 'myset', members: [
{_id: 0, host:'192.168.1.10:27017'},
{_id: 1, host:'192.168.1.9:27017'}]
}
> rs.reconfig(config)
make query in slave available
> rs.slaveOk()
to create a cold standby set secondary as secondary-only
> config = rs.config()
> config.members[1].priority = 0
> rs.reconfig(config)
(http://docs.mongodb.org/manual/administration/replication-architectures/ )
(http://docs.mongodb.org/manual/core/replication/ )
(http://docs.mongodb.org/manual/reference/configuration-options/ )
(http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial )
(http://www.mongodb.org/display/DOCS/Master+Slave )
-------------------------------------
restoring replication
clear local.* from new primary;
clear all /data/db files from new secondary;
restore from a primary fail
> config = {_id: 'myset', members: [
{_id: 1, host:'localhost:27018'},
{_id: 2, host:'localhost:27019'}]
}
> rs.initiate(config)
got "errmsg" : "local.oplog.rs is not empty on the initiating member. cannot initiate.",
> rs.reconfig(config, {force:1})
got "ok" : 1
point new secondary source to new primary
restore from a secondary fail
> config = {_id: 'myset', members: [
{_id: 0, host:'localhost:27017'},
{_id: 1, host:'localhost:27019'}]
}
> rs.initiate(config)
got "errmsg" : "local.oplog.rs is not empty on the initiating member. cannot initiate.",
> rs.reconfig(config, {force:1})
got "ok" : 1
* try copying files before restoration
No comments:
Post a Comment