创建必要的目录和认证文件:
[root@mongo mongo]# mkdir keyfile
[root@mongo mongo]# echo "mongo cluster one" > keyfile/m1
[root@mongo mongo]# echo "mongo cluster one" > keyfile/m2
[root@mongo mongo]# echo "mongo cluster one" > keyfile/m3
启动不同端口的服务
mongod --replSet mco --keyFile /usr/local/mongo/keyfile/m1 --fork --port 28010 --dbpath=/usr/local/mongo/data0/ --logpath=/usr/local/mongo/log/m1.log --logappend
mongod --replSet mco --keyFile /usr/local/mongo/keyfile/m2 --fork --port 28011 --dbpath=/usr/local/mongo/data1/ --logpath=/usr/local/mongo/log/m2.log --logappend
mongod --replSet mco --keyFile /usr/local/mongo/keyfile/m3 --fork --port 28012 --dbpath=/usr/local/mongo/data2/ --logpath=/usr/local/mongo/log/m3.log --logappend
mongod --replSet mco --keyFile /usr/local/mongo/keyfile/m4 --fork --port 28013 --dbpath=/usr/local/mongo/data3/ --logpath=/usr/local/mongo/log/m4.log --logappend
mongod --replSet mco --keyFile /usr/local/mongo/keyfile/m5 --fork --port 28014 --dbpath=/usr/local/mongo/data4/ --logpath=/usr/local/mongo/log/m5.log --logappend --fastsync
配置主从
> config_mco={_id:'mco',members:[
... {_id:0,host:'localhost:28010',priority:1},
... {_id:1,host:'localhost:28011'},
... {_id:2,host:'localhost:28012'}]
... }
{
"_id" : "mco",
"members" : [
{
"_id" : 0,
"host" : "localhost:28010",
"priority" : 1
},
{
"_id" : 1,
"host" : "localhost:28011"
},
{
"_id" : 2,
"host" : "localhost:28012"
}
]
}