以下就是我们将要搭建的mongdb集群架构
创建第一个replset
---------------------------------------------------------------------------
创建目录
mkdir -p /data/replset_sharding/replset1/r0
mkdir -p /data/replset_sharding/replset1/r1
mkdir -p /data/replset_sharding/replset1/r2
mkdir -p /data/replset_sharding/replset1/log
?
?
改用下面的就行了(这是里为方便看日志,直接在命令行输出查看)
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset1/r0?--replSet? replset1?--port 18010?--directoryperdb --rest
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset1/r1 --replSet? replset1?--port 18011?--directoryperdb --rest
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset1/r2 --replSet? replset1?--port 18012?--directoryperdb --rest
?
?
初始化复本集:
?
/Apps/mongo/bin/mongo --port 18010
?
config_replset1?= {
_id:"replset1",
members:
[
{_id:0,host:"127.0.0.1:18010",priority:4},
{_id:1,host:"127.0.0.1:18011",priority:2},
{_id:2,host:"127.0.0.1:18012",arbiterOnly : true}
]
}
?
注意arbiter仲裁节点只投票,不接收复制的数据!
?
?
rs.initiate(config_replset1);
---------------------------------------------------------------------------
?
创建第二个replset
---------------------------------------------------------------------------
创建目录
mkdir -p /data/replset_sharding/replset2/r0
mkdir -p /data/replset_sharding/replset2/r1
mkdir -p /data/replset_sharding/replset2/r2
mkdir -p /data/replset_sharding/replset2/log
?
?
改用下面的就行了(这是里为方便看日志,直接在命令行输出查看)
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset2/r0?--replSet? replset2?--port 28010?--directoryperdb --rest
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset2/r1 --replSet? replset2?--port 28011?--directoryperdb --rest
?
/Apps/mongo/bin/mongod --dbpath?/data/replset_sharding/replset2/r2 --replSet? replset2?--port 28012?--directoryperdb --rest
?
?
初始化复本集:
?
/Apps/mongo/bin/mongo --port 28010
?
config_replset2?= {
_id:"replset2",
members:
[
{_id:0,host:"127.0.0.1:28010",priority:4},
{_id:1,host:"127.0.0.1:28011",priority:2},
{_id:2,host:"127.0.0.1:28012",arbiterOnly : true}
]
}
?
注意arbiter仲裁节点只投票,不接收复制的数据!
?
?
rs.initiate(config_replset2);
---------------------------------------------------------------------------
创建第三个replset
--------------------------------------------------------