yt-summer 发表于 2018-10-26 10:18:14

mongodb安装配置及副本集的操作

9tong1:PRIMARY> rs.add  
rs.add(   rs.addArb(
  
9tong1:PRIMARY> rs.add("192.168.254.9")          #默认端口不需要加端口号码
  

  
9tong1:PRIMARY> rs.add("192.168.254.9")
  
{ "ok" : 1 }
  
9tong1:PRIMARY> rs.status()
  
{
  "set" : "9tong1",
  "date" : ISODate("2015-07-01T04:04:51.535Z"),
  "myState" : 1,
  "members" : [
  {
  "_id" : 0,
  "name" : "samba:27017",
  "health" : 1,
  "state" : 1,
  "stateStr" : "PRIMARY",
  "uptime" : 1645,
  "optime" : Timestamp(1435723485, 1),
  "optimeDate" : ISODate("2015-07-01T04:04:45Z"),
  "electionTime" : Timestamp(1435722018, 2),
  "electionDate" : ISODate("2015-07-01T03:40:18Z"),
  "configVersion" : 2,
  "self" : true
  },
  {
  "_id" : 1,
  "name" : "192.168.254.9:27017",
  "health" : 1,
  "state" : 5,
  "stateStr" : "STARTUP2",
  "uptime" : 6,
  "optime" : Timestamp(0, 0),
  "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
  "lastHeartbeat" : ISODate("2015-07-01T04:04:51.261Z"),
  "lastHeartbeatRecv" : ISODate("2015-07-01T04:04:51.300Z"),
  "pingMs" : 2,
  "syncingTo" : "samba:27017",
  "configVersion" : 2
  }
  ],
  "ok" : 1
  
StateStr:STARTUPU2是复制数据追赶主节点的状态模式。
  

  
数据同步好后会变成SECONDARY
  {
  "_id" : 1,
  "name" : "192.168.254.9:27017",
  "health" : 1,
  "state" : 2,
  "stateStr" : "SECONDARY",
  "uptime" : 63,
  "optime" : Timestamp(1435723485, 1),
  "optimeDate" : ISODate("2015-07-01T04:04:45Z"),
  "lastHeartbeat" : ISODate("2015-07-01T04:05:47.313Z"),
  "lastHeartbeatRecv" : ISODate("2015-07-01T04:05:47.344Z"),
  "pingMs" : 1,
  "configVersion" : 2
  }
  ],
  "ok" : 1
  
也可以通过rs.conf()查看各个节点状态
  
9tong1:PRIMARY> rs.conf()
  
{
  "_id" : "9tong1",
  "version" : 2,
  "members" : [
  {
  "_id" : 0,
  "host" : "samba:27017",
  "arbiterOnly" : false,
  "buildIndexes" : true,
  "hidden" : false,
  "priority" : 1,
  "tags" : {
  },
  "slaveDelay" : 0,
  "votes" : 1
  },
  {
  "_id" : 1,
  "host" : "192.168.254.9:27017",
  "arbiterOnly" : false,
  "buildIndexes" : true,
  "hidden" : false,
  "priority" : 1,
  "tags" : {
  },
  "slaveDelay" : 0,
  "votes" : 1
  }
  ],
  "settings" : {
  "chainingAllowed" : true,
  "heartbeatTimeoutSecs" : 10,
  "getLastErrorModes" : {
  },
  "getLastErrorDefaults" : {
  "w" : 1,
  "wtimeout" : 0
  }
  }
  
}
  

  
9tong1:PRIMARY> use 9tong;
  
switched to db 9tong
  
9tong1:PRIMARY> db.user_contacts.find().count();
  
171639
  

  
从节点上查看
  
9tong1:SECONDARY> show dbs;
  
9tong   0.203GB
  
9tongAPI0.078GB
  
base      0.078GB
  
local   6.075GB
  
test      0.078GB
  
9tong1:SECONDARY> use 9tong;
  
switched to db 9tong
  
9tong1:SECONDARY> db.user_contacts.find().count();
  
171639
  

  
以上证明数据已经同步过来,状态变成SECONDARY
  

  
查看OPOLOG状态
  
9tong1:PRIMARY> db.printReplicationInfo()
  
configured oplog size:   1962.66015625MB
  
log length start to end: 3053secs (0.85hrs)
  
oplog first event time:Wed Jul 01 2015 11:40:18 GMT+0800 (CST)   #第一次更新时间
  
oplog last event time:   Wed Jul 01 2015 12:31:11 GMT+0800 (CST)   #最后一次更新时间
  
now:                     Wed Jul 01 2015 13:30:25 GMT+0800 (CST)   #现在时间
  

  
9tong1:SECONDARY> db.printReplicationInfo()
  
configured oplog size:   4469.238250732422MB
  
log length start to end: 1586secs (0.44hrs)
  
oplog first event time:Wed Jul 01 2015 12:04:45 GMT+0800 (CST)
  
oplog last event time:   Wed Jul 01 2015 12:31:11 GMT+0800 (CST)#与主节点最近一次时间一                                                                   样说明数据同步完成了。
  
now:                     Wed Jul 01 2015 13:31:01 GMT+0800 (CST)


页: [1]
查看完整版本: mongodb安装配置及副本集的操作