zoukankan      html  css  js  c++  java
  • 从零搭建mongo分片集群的简洁方法

    一、目录

      1、mongo路径,config数据路径,shard数据路径

        

       

      2、shard数据路径的结构(共6个分片,分别位于D盘和E盘)

         1)D盘中

          

        2)E盘中

          

      3、启动各个服务端的批处理

       

        1)启动configs服务器

    mongod --dbpath=d:shard_configs --port 23017

       2)启动mongos服务器

    mongos  --port 25017  --configdb 10.0.0.186:23017

       3)启动各个shard分片服务器

    mongod --dbpath=d:shard_datashard_data_000 --port 27017
    mongod --dbpath=d:shard_datashard_data_001 --port 27018
    mongod --dbpath=d:shard_datashard_data_002 --port 27019
    mongod --dbpath=e:shard_datashard_data_003 --port 27020
    mongod --dbpath=e:shard_datashard_data_004 --port 27021
    mongod --dbpath=e:shard_datashard_data_005 --port 27022

    二、将各个分片添加到集群中

      1、防火墙上开放23017和25017端口

        

       2、将各个分片添加到集群中

    C:UsersAdministrator>mongo 10.0.0.186:25017
    MongoDB shell version: 2.4.5
    connecting to: 10.0.0.186:25017/test
    mongos> use admin
    switched to db admin
    mongos> db.runCommand({addshard:"10.0.0.186:27017",allowLocal:true})
    { "shardAdded" : "shard0000", "ok" : 1 }
    mongos> db.runCommand({addshard:"10.0.0.186:27018",allowLocal:true})
    { "shardAdded" : "shard0001", "ok" : 1 }
    mongos> db.runCommand({addshard:"10.0.0.186:27019",allowLocal:true})
    { "shardAdded" : "shard0002", "ok" : 1 }
    mongos> db.runCommand({addshard:"10.0.0.186:27020",allowLocal:true})
    { "shardAdded" : "shard0003", "ok" : 1 }
    mongos> db.runCommand({addshard:"10.0.0.186:27021",allowLocal:true})
    { "shardAdded" : "shard0004", "ok" : 1 }
    mongos> db.runCommand({addshard:"10.0.0.186:27022",allowLocal:true})
    { "shardAdded" : "shard0005", "ok" : 1 }
    mongos>

      3、查看最终的分片结果

    mongos> use config
    switched to db config
    mongos> db.shards.find()
    { "_id" : "shard0000", "host" : "10.0.0.186:27017" }
    { "_id" : "shard0001", "host" : "10.0.0.186:27018" }
    { "_id" : "shard0002", "host" : "10.0.0.186:27019" }
    { "_id" : "shard0003", "host" : "10.0.0.186:27020" }
    { "_id" : "shard0004", "host" : "10.0.0.186:27021" }
    { "_id" : "shard0005", "host" : "10.0.0.186:27022" }
    mongos>

    三、创建数据库和集合,并制定分片键

      1、创建数据库,集合,索引

      

      2、指定news,forum集合的分片键

        1)数据库web_content启动分片功能

    mongos> use admin
    switched to db admin
    mongos> db.runCommand({"enablesharding":"web_content"})
    { "ok" : 1 }
    mongos>

        2)指定两个集合的分片键

    mongos> use admin
    switched to db admin
    mongos> db.runCommand({"shardcollection":"web_content.news","key":{"url_md5":1}}
    )
    { "collectionsharded" : "web_content.news", "ok" : 1 }
    mongos> db.runCommand({"shardcollection":"web_content.forum","key":{"url_md5":1}
    })
    { "collectionsharded" : "web_content.forum", "ok" : 1 }
    mongos>

        3)查看初始时的分片情况

          news集合:

            

          forum集合:

            

  • 相关阅读:
    函数和函数模版在一个。cpp中的情况!(除了左移和右移,其他的不要用友元函数!!!)
    const typedef 和指针的问题(这里必须初始化的才初始化了,不必须的则没有初始化)
    const constptr 和引用的盲点(未解决)
    对于数据流建模和行为级建模的梳理(重点)
    vivado实现模16的计数器
    用vivado实现4比特加法器
    三输入或门(发现这个玩意很不好耍,编程出现错误,不知道哪里出现的,一不小心2输成3也无法查证)
    SpringMVC第一个例子
    Mybatis与Spring的mapper代理整合方法
    Mybatis与Spring的原生Dao整合
  • 原文地址:https://www.cnblogs.com/edisonfeng/p/3636576.html
Copyright © 2011-2022 走看看