加入收藏 | 设为首页 | 会员中心 | 我要投稿 哈尔滨站长网 (https://www.0451zz.cn/)- 人体识别、图像分析、开发者工具、基础存储、物联安全!
当前位置: 首页 > 运营中心 > 建站资源 > 优化 > 正文

Web架构之路:MongoDB集群及高可用实践

发布时间:2019-10-16 20:11:38 所属栏目:优化 来源:热爱技术君
导读:MongoDB集群有副本集及主从复制两种模式,不过主从模式在MongoDB 3.6已经彻底废弃,今天主要探讨副本集的搭建和使用,以及分片。 副本集介绍 副本集(Replica Set)即副本的集合,在MongoDB中通过先定义一个副本集合,然后将多个节点(副本)加入到这个集合中

启动后,需要通过sh.addShard()命令添加分片服务器:

  1. sh.addShard('127.0.0.1:27020') 
  2. sh.addShard('127.0.0.1:27021') 
  3. sh.addShard('127.0.0.1:27022') 
  4. sh.addShard('127.0.0.1:27023') 

配置完成后,可以通过sh.status()命令,查看分片情况:

  1. mongos> sh.status() 
  2. --- Sharding Status ---  
  3.  sharding version: { 
  4.     "_id" : 1, 
  5.     "minCompatibleVersion" : 5, 
  6.     "currentVersion" : 6, 
  7.     "clusterId" : ObjectId("5d8ddd1d94796dc650e29f67") 
  8.  } 
  9.  shards: 
  10.  { "_id" : "shard0000", "host" : "127.0.0.1:27020", "state" : 1 } 
  11.  { "_id" : "shard0001", "host" : "127.0.0.1:27021", "state" : 1 } 
  12.  { "_id" : "shard0002", "host" : "127.0.0.1:27022", "state" : 1 } 
  13.  { "_id" : "shard0003", "host" : "127.0.0.1:27023", "state" : 1 } 
  14.  active mongoses: 
  15.  "4.2.0" : 1 
  16.  autosplit: 
  17.  Currently enabled: yes 
  18.  balancer: 
  19.  Currently enabled: yes 
  20.  Currently running: no 
  21.  Failed balancer rounds in last 5 attempts: 0 
  22.  Migration Results for the last 24 hours:  
  23.  No recent migrations 
  24.  databases: 
  25.  { "_id" : "config", "primary" : "config", "partitioned" : true } 
  26.  config.system.sessions 
  27.  shard key: { "_id" : 1 } 
  28.  unique: false 
  29.  balancing: true 
  30.  chunks: 
  31.  shard0000  1 
  32.  { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$max 

(编辑:哈尔滨站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读