mongodb 手动分片的命令汇总
手动分片的操作
自动分片会带来性能的下降. 所以要合理使用手动分片. 并且配合Tag一起使用.
# 对于4个shard的程序, 预先处理的指令
1. 加入分片服务器
sh.addShard( "192.168.1.60:27017" )
sh.addShard( "192.168.1.61:27017" )
sh.addShard( "192.168.1.62:27017" )
sh.addShard( "192.168.1.63:27017" )
2. 启动collection分片, 并指定分片键
db.location.ensureIndex({"hostid":1})
sh.enableSharding("mydb")
sh.shardCollection("mydb.location", { "hostid": 1})
运行 sh.status()
{ "_id" : "mydb", "partitioned" : true, "primary" : "shard0003" }
mydb.location
shard key: { "hostid" : 1 }
chunks:
shard0003 1
{ "hostid" : { "$minKey" : 1 } } -->> { "hostid" : { "$maxKey" : 1 } } on : shard0003 Timestamp(1, 0)
sh.addShardTag("shard0000", "TAG0")
sh.addShardTag("shard0001", "TAG1")
sh.addShardTag("shard0002", "TAG2")
sh.addShardTag("shard0003", "TAG3")
# 具体操作
1. 加入tagrange,
加入两个
sh.addTagRange("mydb.location", { hostid: "0000000" }, { hostid: "3100000" }, "TAG0")
sh.addTagRange("mydb.location", { hostid: "3100000" }, { hostid: "3200000" }, "TAG1")
由于当前的primary位 shard0003,
sh.addTagRange("mydb.location", { hostid: "3200000" }, { hostid: "3300000" }, "TAG2")
sh.addTagRange("mydb.location", { hostid: "3300000" }, { hostid: "3500000" }, "TAG3")
sh.addTagRange("mydb.location", { hostid: "3500000" }, { $maxKey: 1 }, "TAG3")
4. add chunck
// 将primary 放到第二个分片上
db.runCommand({movePrimary:"mydb",to:"shard0001"})
查看分片情况
db.chunks.find({ns:"mydb.location"})
手动建立空的chunk
for ( var x=300; x<350; x++ ){
var prefix = String(x*10000);
sh.splitAt( "mydb.location", { "hostid":prefix } )
}
然后移动chunk到对应的地方, 移动chunk的命令
sh.moveChunk("mydb.location", { hostid: "3000000"}, "shard0000")
==shard0000
for ( var x=300; x<310; x++ ){
var prefix = String(x*10000);
sh.moveChunk( "mydb.location", { "hostid":prefix }, "shard0000" )
}
==shard0001 310 - 320
==shard0002 320 - 330
==shard0003 330 - 350
其他一些查询操作
// 查找大于 340000的数据, 并且
db.chunks.find({ns:"mydb.location", min:{$gte:{ "hostid" : "3400000" }}})
db.getSiblingDB("admin").runCommand( { moveChunk : "mydb.location" ,
find : { "hostid" : "3400000" } ,
to : "shard0003" } )
1. 建立索引
use mydb
db.location.ensureIndex({"hostid":1})
db.location.ensureIndex({"posTime":1})
db.location.ensureIndex({"hostno":1})
db.location.createIndex( { loc : "2dsphere" } )
db.location.ensureIndex({"posTime":1,"loc":"2dsphere"})
db.location.ensureIndex({"posTime":1,"hostno":1,"loc":"2dsphere"})
db.location.getIndexes()
mongodb 手动分片的命令汇总的更多相关文章
- MongoDB 常用shell命令汇总
//指定用户名和密码连接到指定的MongoDB数据库 mongo 192.168.1.200:27017/admin -u user -p password use youDbName 1.Mongo ...
- MongoDB之分片
本文介绍分片的思想和MongoDB中的实现方法. 首先须要介绍一些主要的概念. 分片 分片.也叫做分区.是一种经常使用的数据库优化技术.其含义就是将数据拆分,将数据分散到不同机器上的过程.这样就能够使 ...
- 20145222《信息安全系统设计基础》Linux常用命令汇总
学习Linux时常用命令汇总 通过Ctrl+f键可在该网页搜索到你想要的命令. Linux中命令格式为:command [options] [arguments] //中括号代表是可选的,即有些命令不 ...
- mongodb(分片)
分片(即sharding)是将数据拆分至不同数据节点的方式. 1.在mongoDB中提供了自动分片的方式,它会根据数据块(chunk)大小的设定,对片键进行拆分: 2.mongoDB配置分片,要配置三 ...
- MongoDB之分片集群(Sharding)
MongoDB之分片集群(Sharding) 一.基本概念 分片(sharding)是一个通过多台机器分配数据的方法.MongoDB使用分片支持大数据集和高吞吐量的操作.大数据集和高吞吐量的数据库系统 ...
- mongodb系列~mongo常用命令
mongodb常用命令大全1 索引相关命令 db.chenfeng.ensureIndex({"riqi":1}) 添加索引会阻塞nohup mongo --eval " ...
- mongodb的分片(2)
在上一片博客,详细说明了mongodb的分片搭建的详细过程:分片搭建 在这里会说一些分片的维护与操作! 在集群搭建完,我们使用了sh.status()查看分片之后的数据,如下: #连接的是mongos ...
- mongodb的分片
分片是把大型数据集合进行分区成更小的可管理的片的过程. 副本集的每一个成员(仲裁节点除外)都一份数据的完整拷贝! 分片的目的:在节省硬件成本的基础上,提高系统的整体性能.但是却增加了管理和性能的开销. ...
- MongoDB 自动分片 auto sharding
MongoDB部署实验系列文章 MongoDB做为NoSQL数据库,最近几年持续升温,越来越多的企业都开始尝试用MongoDB代替原有Database做一些事情.MongoDB也在集群,分片,复制上也 ...
随机推荐
- Asp.net MVC中提交集合对象,实现Model绑定(转载)
Asp.net MVC中的Model自动绑定功能,方便了我们对于request中的数据的处理, 从客户端的请求数据,自动地以Action方法参数的形式呈现.有时候我们的Action方法中想要接收数组类 ...
- Spark metrics on wordcount example
I read the section Metrics on spark website. I wish to try it on the wordcount example, I can't make ...
- Java正则表达式, 提取双引号中间的部分
String str="this is \"Tom\" and \"Eric\", this is \"Bruce lee\", ...
- SU unif2命令学习
- 绑定GoDaddy域名到OpenShift应用
一.申请GoDaddy域名 二.托管OpenShift应用 三.绑定www.mydomain.com 四.重定向mydomin.com到www.mydomain.com 五.It's go time ...
- node工具--express
//使用supervisor Connect是基于HTTP米快创建的:Express则是基于Connect上创建的: 绝大多数web服务器和浏览器之间的任务是通过url和method完成的,两者的组 ...
- Xamarin Anroid App访问网站失败
Xamarin Anroid App访问网站失败 错误信息:net::ERR_NAME_NOT_RESOLVED如果电脑同时有有线网卡和无线网卡,电脑使用无线网卡上网,而有线网卡不上网.这时,就会出现 ...
- 循环多少次?[HDU1799]
循环多少次? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- python 代码片段13
#coding=utf-8 # 条件转化 data=raw_input("enter 'y' or 'n'") if data[0]=='y': print "you t ...
- wc2016总结
因为我太弱了,高一才第一次来wc. 前几天讲课,被各种小学微积分和初中高等代数虐,简直naive.只好自己做做bzoj,想着练练模板之类的东西. 考试当天自觉状态不错,翻开试题感觉各种神奇(这难道是串 ...