MongoDB中怎么切换副本集-创新互联
MongoDB中怎么切换副本集,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
10余年的古交网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整古交建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“古交网站设计”,“古交网站推广”以来,每个客户项目都认真落实执行。MongoDB 副本集切换方法
1、rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)
操作步骤如下:
[root@127-0-0-1 conf]# mongo --port 2777
shard1:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.001GB
yoon 0.000GB
shard1:PRIMARY> rs.help()
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg
rs.conf() get the current configuration object from local.system.replset
rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)
rs.add(hostportstr) add a new member to the set with default attributes (disconnects)
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)
rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)
rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)
rs.syncFrom(hostportstr) make a secondary sync from the given member
rs.freeze(secs) make a node ineligible to become primary for the time specified
rs.remove(hostportstr) remove a host from the replica set (disconnects)
rs.slaveOk() allow queries on secondary nodes
rs.printReplicationInfo() check oplog size and time range
rs.printSlaveReplicationInfo() check replica set members and replication lag
db.isMaster() check who is primary
reconfiguration helpers disconnect from the database so the shell will display
an error, even if the command succeeds.
shard1:PRIMARY> rs.stepDown() #这个命令会让primary降级为Secondary节点
shard1:PRIMARY> rs.stepDown(30) #这个命令会让primary降级为Secondary节点并维持30S,如果这段时间没有新的primary选举出来,这个节点重新加入进行选举
2、通过设置优先级
A.为了保证数据的一致性,必须先关闭应用的写服务
B.提升要升级为primary节点的Secondary节点的优先级
操作如下:
查看当前配置信息:
shard1:PRIMARY> rs.conf()
{
"_id" : "shard1",
"version" : 4,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:2777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 3,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "127.0.0.1:3777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "127.0.0.1:4777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5f27de76c8d22581cdeb2f2e")
}
}
shard1:PRIMARY> config=rs.conf() # 查看当前配置,存入config变量中
shard1:PRIMARY> config.members[2].priority = 3 # 修改config变量,将第三组端口为4777的成员优先级设置为3
shard1:PRIMARY> rs.reconfig(config) # 配置生效
shard1:PRIMARY> db.isMaster()
{
"hosts" : [
"127.0.0.1:2777",
"127.0.0.1:3777",
"127.0.0.1:4777"
],
"setName" : "shard1",
"setVersion" : 7,
"ismaster" : true,
"secondary" : false,
"primary" : "127.0.0.1:4777",
"me" : "127.0.0.1:4777",
"electionId" : ObjectId("7fffffff0000000000000004"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1596599298, 1),
"t" : NumberLong(4)
},
"lastWriteDate" : ISODate("2020-08-05T03:48:18Z"),
"majorityOpTime" : {
"ts" : Timestamp(1596599298, 1),
"t" : NumberLong(4)
},
"majorityWriteDate" : ISODate("2020-08-05T03:48:18Z")
}..
...
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联-成都网站建设公司行业资讯频道,感谢您对创新互联的支持。
网站栏目:MongoDB中怎么切换副本集-创新互联
当前链接:http://scyanting.com/article/dspogh.html