日期:2014-05-16  浏览次数:20409 次

mongo 构建副本集

sudo mongod --dbpath /data/mongo/ReplicaSetData/data1 --logpath /data/mongo/logs/mg1.log --port 27018 --oplogSize 100 --replSet bermuda --fork

sudo mongod --dbpath /data/mongo/ReplicaSetData/data2 --logpath /data/mongo/logs/mg2.log --port 27019 --oplogSize 100 --replSet bermuda --fork

sudo mongod --dbpath /data/mongo/ReplicaSetData/data3 --logpath /data/mongo/logs/mg3.log --port 27020 --oplogSize 100 --replSet bermuda --fork

sudo mongod --dbpath /data/mongo/ReplicaSetData/data4 --logpath /data/mongo/logs/mg4.log --port 27021 --oplogSize 100 --replSet bermuda --fork


sudo mongod --dbpath /data/mongo/ReplicaSetData/data5 --logpath /data/mongo/logs/mg5.log --port 27022 --oplogSize 100 --replSet bermuda --fork



config = {_id:"bermuda",members:[
	 	{_id:0,host:'127.0.0.1:27018'},
	 	{_id:1,host:'127.0.0.1:27019'},
		{_id:2,host:'127.0.0.1:27020'}]
	}


rs.initiate(config)



rs.add({"_id" : 3,host : "localhost:27021"});

rs.add({"_id" : 4,host : "127.0.0.1:27022",arbiterOnly:true}); 

#切换主从副本
rs.stepDown(30)