【MongoDB】02、MongoDB复制
> 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() step down as primary (momentarily) (disconnects)
rs.syncFrom(hostportstr) make a secondary to 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() shorthand for db.getMongo().setSlaveOk()
db.isMaster() check who is primary
db.printReplicationInfo() check oplog size and time range
reconfiguration helpers disconnect from the database so the shell will display
an error, even if the command succeeds.
see also http://:28017/_replSet for additional diagnostic info
>
> rs.status()
{
"startupStatus" : 3, # 已运行的节点3个
"info" : "run rs.initiate(...) if not yet done for the set", # 提示应该初始化
"ok" : 0,
"errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)"
}
> rs.initiate() # 初始化
{
"info2" : "no configuration explicitly specified -- making one",
"me" : "Node7:27017",
"info" : "Config now saved locally.Should come online in about a minute.",
"ok" : 1
}
> rs.status()
{
"set" : "testSet",
"date" : ISODate("2017-03-26T06:28:25Z"),
"myState" : 1,
"members" : [ #副本集成员信息
{
"_id" : 0, # 节点表示符
"name" : "Node7:27017", # 节点名称
"health" : 1, # 健康状态
"state" : 1, # 是否有状态信息
"stateStr" : "PRIMARY", # 状态字符串:主节点
"uptime" : 1387, # 已运行时间,单位为S
"optime" : Timestamp(1490509672, 1), # oplog最近更新时间戳
"optimeDate" : ISODate("2017-03-26T06:27:52Z"), # 同上,时间
"self" : true # 是否是当前节点
}
],
"ok" : 1
}
testSet:PRIMARY>
testSet:PRIMARY> rs.conf()
{
"_id" : "testSet",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "Node7:27017"
}
]
}
testSet:PRIMARY> show dbs
local1.078125GB
testSet:PRIMARY> db
test
testSet:PRIMARY> use local
switched to db local
testSet:PRIMARY> show collections # 初始化后oplog.rs集合生成了
oplog.rs
startup_log
system.replset
testSet:PRIMARY>
页:
[1]