• MongoDB整理笔记の新增Shard Server


        1、启动一个新Shard Server 进程

    [root@localhost ~]# mkdir /data/shard/s2
    [root@localhost ~]# /Apps/mongo/bin/mongod --shardsvr --port 20002 --dbpath /data/shard/s2
    --fork --logpath /data/shard/log/s2.log --directoryperdb
    all output going to: /data/shard/log/s2.log
    forked process: 6772

        2、配置新Shard Server

    [root@localhost ~]# /Apps/mongo/bin/mongo admin --port 40000
    MongoDB shell version: 1.8.1
    connecting to: 127.0.0.1:40000/admin
    > db.runCommand({ addshard:"localhost:20002" })
    { "shardAdded" : "shard0002", "ok" : 1 }
    > printShardingStatus()
    --- Sharding Status ---
    sharding version: { "_id" : 1, "version" : 3 }
    shards:
    { "_id" : "shard0000", "host" : "localhost:20000" }
    { "_id" : "shard0001", "host" : "localhost:20001" }
    { "_id" : "shard0002", "host" : "localhost:20002" } --新增Shard Server
    databases:
    { "_id" : "admin", "partitioned" : false, "primary" : "config" }
    { "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
    test.users chunks:
    shard0002 2
    shard0000 21
    shard0001 21
    too many chunksn to print, use verbose if you want to force print
    test.users_2 chunks:
    shard0001 46
    shard0002 1
    shard0000 45
    too many chunksn to print, use verbose if you want to force print
    View Code

       3、 查看分片表状态,以验证新Shard Server

    > use test
    switched to db test
    > db.users_2.stats()
    {
    "sharded" : true,
    "ns" : "test.users_2",
    ……
    "shard0002" : { --新的Shard Server 已有数据
    "ns" : "test.users_2",
    "count" : 21848,
    "size" : 2097408,
    "avgObjSize" : 96,
    "storageSize" : 2793472,
    "numExtents" : 5,
    "nindexes" : 1,
    "lastExtentSize" : 2097152,
    "paddingFactor" : 1,
    "flags" : 1,
    "totalIndexSize" : 1277952,
    "indexSizes" : {
    "_id_" : 1277952
    },
    "ok" : 1
    }
    },
    "ok" : 1
    }
    >
    View Code

        我们可以发现,当我们新增Shard Server 后数据自动分布到了新Shard 上,这是由MongoDB内部自已实现的。

  • 相关阅读:
    PHP htmlspecialchars和htmlspecialchars_decode(函数)
    使用CURL抓取淘宝页面
    PHP 自定义字符串中的变量名解析
    Notepad++前端开发常用插件介绍
    使用phpExcel实现Excel数据的导入导出(完全步骤)
    moment.js 日期包装类 (说明示例)
    php函数前面加&符号 和 变量前面加&符号的意义
    window 查看端口/杀进程
    eureka 去除注册中心保护机制
    mysql 表关联更新另一张表的数据
  • 原文地址:https://www.cnblogs.com/tomcatx/p/4245677.html
Copyright © 2020-2023  润新知