时间:2021-07-01 10:21:17 帮助过:8人阅读
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:27017",
"priority" : 3
},
{
"_id" : 1,
"host" : "127.0.0.1:27018",
"priority" : 2
},
{
"_id" : 2,
"host" : "127.0.0.1:27019",
"priority" : 1
},
{
"_id" : 3,
"host" : "127.0.0.1:27020",
"arbiterOnly" : true
}
]
}
> rs.initiate(cfg); (初始化配置)
{ "ok" : 1 }
shard1:PRIMARY> rs.conf(); (查看配置信息)
{
"_id" : "shard1",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 3,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 1,
"host" : "127.0.0.1:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 2,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 2,
"host" : "127.0.0.1:27019",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 3,
"host" : "127.0.0.1:27020",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
shard1:OTHER> rs.status() (查看副本集)
{
"set" : "shard1",
"date" : ISODate("2017-09-14T05:23:16.893Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "127.0.0.1:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1117,
"optime" : Timestamp(1505366494, 1),
"optimeDate" : ISODate("2017-09-14T05:21:34Z"),
"electionTime" : Timestamp(1505366495, 1),
"electionDate" : ISODate("2017-09-14T05:21:35Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "127.0.0.1:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 102,
"optime" : Timestamp(1505366494, 1),
"optimeDate" : ISODate("2017-09-14T05:21:34Z"),
"lastHeartbeat" : ISODate("2017-09-14T05:23:16.113Z"),
"lastHeartbeatRecv" : ISODate("2017-09-14T05:23:16.663Z"),
"pingMs" : 0,
"configVersion" : 1
},
{
"_id" : 2,
"name" : "127.0.0.1:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 102,
"optime" : Timestamp(1505366494, 1),
"optimeDate" : ISODate("2017-09-14T05:21:34Z"),
"lastHeartbeat" : ISODate("2017-09-14T05:23:16.127Z"),
"lastHeartbeatRecv" : ISODate("2017-09-14T05:23:16.668Z"),
"pingMs" : 0,
"configVersion" : 1
},
{
"_id" : 3,
"name" : "127.0.0.1:27020",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 102,
"lastHeartbeat" : ISODate("2017-09-14T05:23:16.055Z"),
"lastHeartbeatRecv" : ISODate("2017-09-14T05:23:16.674Z"),
"pingMs" : 1,
"configVersion" : 1
}
],
"ok" : 1
}
shard1:PRIMARY>
到此处配置成功:
6.测试验证:
参考文档:http://blog.csdn.net/zhang_yanan/article/details/25972693 进行测试验证
在master上创建用户和数据库进行测试验证集群是否成功
db.createUser(
{
user: "root",
pwd: "Zykj@558996",
roles: [ { role: "root", db: "admin" } ]
}
)
use admin
db.createUser(
... {
... user: "DBA3",
... pwd: "Zykj@558996",
... roles: [ { role: "readWrite", db: "dbtest001" } ]
... }
... )
也可以安装mongodb客户端软件来操作进行验证集群搭建是否成功
7.部署参考文档:
http://blog.csdn.net/luonanqin/article/details/8497860;
http://suifu.blog.51cto.com/9167728/1853478
http://blog.csdn.net/zhang_yanan/article/details/25972693
MongoDB高可用集群配置的几种方案参考:https://yq.aliyun.com/articles/61516
本文出自 “10931853” 博客,转载请与作者联系!
Replica Set副本集方式的mongodb集群搭建
标签:replica set副本集方式的mongodb集群搭建