美文网首页mongodb
【mongoDB】mongoDB shard cluster 设

【mongoDB】mongoDB shard cluster 设

作者: Bogon | 来源:发表于2022-08-24 00:48 被阅读0次

    一般分片

    # test_shard01 test_shard02 为2个分片(1主1从1仲裁)
    # 登录对应分片集群的mongos
    #  /path/to/bin/mongo  --host xx.xx.xx  --port  XXX  -u "username"  -p "XXX"   --authenticationDatabase admin
    
    
    use admin
    sh.addShard("test_shard01/172.18.65.101:20002,172.18.65.102:20002");
    sh.addShard("test_shard02/172.18.65.103:20003,172.18.65.104:20003");
    
    sh.enableSharding("testDB");
    admindb = db.getSisterDB('admin');
    admindb.runCommand({shardcollection : "testDB.T1",key:{_id: 1}});
    admindb.runCommand({shardcollection : "testDB.T2",key:{groupId: 1}});
    
    
    

    文件分片

    # file_shard01 file_shard02 为2个分片(1主1从1仲裁)
    
    # fs.files         元数据
    # fs.chunks        实体数据
    
    # 登录对应分片集群的mongos
    # /path/to/bin/mongo  --host xx.xx.xx   --port XXX   -u "username"   -p "XXX"   --authenticationDatabase admin
    
    use admin
    sh.addShard("file_shard01/172.18.65.105:30002,172.18.65.106:30002");
    sh.addShard("file_shard02/172.18.65.107:30003,172.18.65.108:30003");
    
    
    sh.enableSharding("fileDB");
    
    filedb=db.getSisterDB("fileDB");
    filedb.fs.chunks.ensureIndex({files_id:1, n:1}, {unique: true})
    
    admindb=db.getSisterDB('admin');
    admindb.runCommand({shardcollection : "fileDB.fs.chunks",key:{files_id: 1}});
    
    
    image.png

    参考

    Mongo分片之选择片键
    http://t.zoukankan.com/lizexiong-p-15386985.html

    mongoDB Sharding GridFS
    https://www.mongodb.com/docs/manual/core/gridfs/

    如何在MongoDB中轻松使用GridFS?
    https://mp.weixin.qq.com/s/z7ke5OCBnNzutCMwW_hOuA
    https://mp.weixin.qq.com/s/6moozgPJfdZcKOOE37IFeg
    https://mp.weixin.qq.com/s/kYLcc175hux5VRgy524UBg
    https://mp.weixin.qq.com/s/2qvZBg1wedhlOLrPvo4-ZQ

    相关文章

      网友评论

        本文标题:【mongoDB】mongoDB shard cluster 设

        本文链接:https://www.haomeiwen.com/subject/uitngrtx.html