mongodb sharding maintenance (分片维护1)

一、关于sharding strategy 及 chunk split

mongos> sh.status()

--- Sharding Status ---

sharding version: {

"_id" : 1,

"minCompatibleVersion" : 5,

"currentVersion" : 6,

"clusterId" : ObjectId("5850e59fce8b5f7ab7cfad34")

}

shards:

active mongoses:

"3.4.0" : 1

autosplit:

Currently enabled: yes

balancer:

Currently enabled:  yes

Currently running:  no

Balancer lock taken at Wed Dec 14 2016 06:24:31 GMT+0000 (UTC) by ConfigServer:Balancer

Failed balancer rounds in last 5 attempts:  0

Migration Results for the last 24 hours:

No recent migrations

databases:

mongos> use admin

switched to db admin

mongos> sh.addShard("shard1/mongo01-jp:27027")

{ "shardAdded" : "shard1", "ok" : 1 }

mongos> sh.addShard("shard2/mongo02-jp:27028")

{ "shardAdded" : "shard2", "ok" : 1 }

mongos> sh.addShard("shard3/mongo03-jp:27029")

{ "shardAdded" : "shard3", "ok" : 1 }

mongos> sh.status()

--- Sharding Status ---

sharding version: {

"_id" : 1,

"minCompatibleVersion" : 5,

"currentVersion" : 6,

"clusterId" : ObjectId("5850e59fce8b5f7ab7cfad34")

}

shards:

{  "_id" : "shard1",  "host" : "shard1/mongo01-jp:27027,mongo02-jp:27027",  "state" : 1 }

{  "_id" : "shard2",  "host" : "shard2/mongo02-jp:27028,mongo03-jp:27028",  "state" : 1 }

{  "_id" : "shard3",  "host" : "shard3/mongo01-jp:27029,mongo03-jp:27029",  "state" : 1 }

active mongoses:

"3.4.0" : 1

autosplit:

Currently enabled: yes

balancer:

Currently enabled:  yes

Currently running:  no

Balancer lock taken at Wed Dec 14 2016 06:24:31 GMT+0000 (UTC) by ConfigServer:Balancer

Failed balancer rounds in last 5 attempts:  0

Migration Results for the last 24 hours:

No recent migrations

databases:

mongos> use config

switched to db config

mongos> db.chunks.find()

mongos> db.settings.find()

mongos> db.settings.save({"_id":"chunksize","value":NumberLong(5)})

WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "chunksize" })

mongos> db.settings.find()

{ "_id" : "chunksize", "value" : NumberLong(5) }

注: 默认每个chunk大小为64M,支持可以手工设置;较小的chunk可以使数据分布的更均衡,便于迁移,但是带来的问题就是split更加频繁,增加了mongos路由的开支(每个chunk持有的数据量变小,每次query需要访问更多chunks);较大的chunk不便迁移,但是split次数较少,metadata信息较少,mongos路由简单;如果chunk过大会导致数据分布不均。个人认为64M还是较小,建议增加到256M。spit操作只会有insert或者update触发。

mongos> use admin

switched to db admin

mongos> sh.enableSharding("test")

{ "ok" : 1 }

mongos> sh.shardCollection("test.user",{uid:1})    基于uid range 分片

{ "collectionsharded" : "test.user", "ok" : 1 }

mongos> use test

switched to db test

mongos> db.user.ensureIndex({uid:1})   对于一个空collection,系统会自动创建索引

{

"raw" : {

"shard1/mongo01-jp:27027,mongo02-jp:27027" : {

"createdCollectionAutomatically" : true,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1,

"$gleStats" : {

"lastOpTime" : {

"ts" : Timestamp(1481700282, 2),

"t" : NumberLong(1)

},

"electionId" : ObjectId("7fffffff0000000000000001")

}

},

"shard2/mongo02-jp:27028,mongo03-jp:27028" : {

"createdCollectionAutomatically" : true,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1,

"$gleStats" : {

"lastOpTime" : {

"ts" : Timestamp(1481700282, 2),

"t" : NumberLong(1)

},

"electionId" : ObjectId("7fffffff0000000000000001")

}

},

"shard3/mongo01-jp:27029,mongo03-jp:27029" : {

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 2,

"numIndexesAfter" : 2,

"note" : "all indexes already exist",

"ok" : 1,

"$gleStats" : {

"lastOpTime" : {

"ts" : Timestamp(1481700282, 1),

"t" : NumberLong(1)

},

"electionId" : ObjectId("7fffffff0000000000000001")

}

}

},

"ok" : 1

}

mongos> for (i=1;i<=100000;i++) db.user.insert({uid:‘user‘+i,age:(i%15),address:‘#‘+i+‘,nongda south road,beijing‘,preferbooks:[‘book‘+i,‘hello world‘]})

WriteResult({ "nInserted" : 1 })

mongos> sh.status()

--- Sharding Status ---

sharding version: {

"_id" : 1,

"minCompatibleVersion" : 5,

"currentVersion" : 6,

"clusterId" : ObjectId("5850e59fce8b5f7ab7cfad34")

}

shards:

{  "_id" : "shard1",  "host" : "shard1/mongo01-jp:27027,mongo02-jp:27027",  "state" : 1 }

{  "_id" : "shard2",  "host" : "shard2/mongo02-jp:27028,mongo03-jp:27028",  "state" : 1 }

{  "_id" : "shard3",  "host" : "shard3/mongo01-jp:27029,mongo03-jp:27029",  "state" : 1 }

active mongoses:

"3.4.0" : 1

autosplit:

Currently enabled: yes

balancer:

Currently enabled:  yes

Currently running:  no

Balancer lock taken at Wed Dec 14 2016 06:24:31 GMT+0000 (UTC) by ConfigServer:Balancer

Failed balancer rounds in last 5 attempts:  0

Migration Results for the last 24 hours:

8 : Success

databases:

{  "_id" : "test",  "primary" : "shard3",  "partitioned" : true }

test.user

shard key: { "uid" : 1 }

unique: false

balancing: true

chunks:

shard1 5

shard2 4

shard3 4

{ "uid" : { "$minKey" : 1 } } -->> { "uid" : "user10" } on : shard3 Timestamp(9, 1)

{ "uid" : "user10" } -->> { "uid" : "user17659" } on : shard1 Timestamp(4, 1)

{ "uid" : "user17659" } -->> { "uid" : "user2" } on : shard1 Timestamp(3, 4)

{ "uid" : "user2" } -->> { "uid" : "user2832" } on : shard1 Timestamp(6, 0)

{ "uid" : "user2832" } -->> { "uid" : "user32174" } on : shard3 Timestamp(7, 0)

{ "uid" : "user32174" } -->> { "uid" : "user36003" } on : shard1 Timestamp(8, 0)

{ "uid" : "user36003" } -->> { "uid" : "user5211" } on : shard2 Timestamp(8, 1)

{ "uid" : "user5211" } -->> { "uid" : "user5974" } on : shard2 Timestamp(6, 4)

{ "uid" : "user5974" } -->> { "uid" : "user6713" } on : shard2 Timestamp(4, 7)

{ "uid" : "user6713" } -->> { "uid" : "user8" } on : shard2 Timestamp(4, 4)

{ "uid" : "user8" } -->> { "uid" : "user87659" } on : shard3 Timestamp(8, 2)

{ "uid" : "user87659" } -->> { "uid" : "user9999" } on : shard3 Timestamp(8, 3)

{ "uid" : "user9999" } -->> { "uid" : { "$maxKey" : 1 } } on : shard1 Timestamp(9, 0)

mongos> use config

switched to db config

mongos>  db.settings.find()

{ "_id" : "chunksize", "value" : NumberLong(5) }

mongos> db.shards.find()

{ "_id" : "shard1", "host" : "shard1/mongo01-jp:27027,mongo02-jp:27027", "state" : 1 }

{ "_id" : "shard2", "host" : "shard2/mongo02-jp:27028,mongo03-jp:27028", "state" : 1 }

{ "_id" : "shard3", "host" : "shard3/mongo01-jp:27029,mongo03-jp:27029", "state" : 1 }

mongos>  db.databases.find()

{ "_id" : "test", "primary" : "shard3", "partitioned" : true }

注:  每个未分片的DB都会有一个primary shard

mongos> db.chunks.find()

{ "_id" : "test.user-uid_MinKey", "lastmod" : Timestamp(9, 1), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : { "$minKey" : 1 } }, "max" : { "uid" : "user10" }, "shard" : "shard3" }

{ "_id" : "test.user-uid_\"user2\"", "lastmod" : Timestamp(6, 0), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user2" }, "max" : { "uid" : "user2832" }, "shard" : "shard1" }

{ "_id" : "test.user-uid_\"user8\"", "lastmod" : Timestamp(8, 2), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user8" }, "max" : { "uid" : "user87659" }, "shard" : "shard3" }

{ "_id" : "test.user-uid_\"user10\"", "lastmod" : Timestamp(4, 1), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user10" }, "max" : { "uid" : "user17659" }, "shard" : "shard1" }

{ "_id" : "test.user-uid_\"user17659\"", "lastmod" : Timestamp(3, 4), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user17659" }, "max" : { "uid" : "user2" }, "shard" : "shard1" }

{ "_id" : "test.user-uid_\"user2832\"", "lastmod" : Timestamp(7, 0), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user2832" }, "max" : { "uid" : "user32174" }, "shard" : "shard3" }

{ "_id" : "test.user-uid_\"user6713\"", "lastmod" : Timestamp(4, 4), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user6713" }, "max" : { "uid" : "user8" }, "shard" : "shard2" }

{ "_id" : "test.user-uid_\"user32174\"", "lastmod" : Timestamp(8, 0), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user32174" }, "max" : { "uid" : "user36003" }, "shard" : "shard1" }

{ "_id" : "test.user-uid_\"user5974\"", "lastmod" : Timestamp(4, 7), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user5974" }, "max" : { "uid" : "user6713" }, "shard" : "shard2" }

{ "_id" : "test.user-uid_\"user36003\"", "lastmod" : Timestamp(8, 1), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user36003" }, "max" : { "uid" : "user5211" }, "shard" : "shard2" }

{ "_id" : "test.user-uid_\"user5211\"", "lastmod" : Timestamp(6, 4), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user5211" }, "max" : { "uid" : "user5974" }, "shard" : "shard2" }

{ "_id" : "test.user-uid_\"user87659\"", "lastmod" : Timestamp(8, 3), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user87659" }, "max" : { "uid" : "user9999" }, "shard" : "shard3" }

{ "_id" : "test.user-uid_\"user9999\"", "lastmod" : Timestamp(9, 0), "lastmodEpoch" : ObjectId("5850f399db3a37e0bc576a2b"), "ns" : "test.user", "min" : { "uid" : "user9999" }, "max" : { "uid" : { "$maxKey" : 1 } }, "shard" : "shard1" }

mongos> use admin

switched to db admin

mongos> sh.shardCollection("test.user2",{"_id":"hashed"})   基于hash 分片

{ "collectionsharded" : "test.user2", "ok" : 1 }

mongos> use test

switched to db test

mongos> for (i=1;i<=100000;i++) db.user2.insert({uid:‘user‘+i,age:(i%15),address:‘#‘+i+‘,shangdi south road,beijing‘,preferbooks:[‘book‘+i,‘hello world‘]})

WriteResult({ "nInserted" : 1 })

mongos> sh.status()

--- Sharding Status ---

sharding version: {

"_id" : 1,

"minCompatibleVersion" : 5,

"currentVersion" : 6,

"clusterId" : ObjectId("5850e59fce8b5f7ab7cfad34")

}

shards:

{  "_id" : "shard1",  "host" : "shard1/mongo01-jp:27027,mongo02-jp:27027",  "state" : 1 }

{  "_id" : "shard2",  "host" : "shard2/mongo02-jp:27028,mongo03-jp:27028",  "state" : 1 }

{  "_id" : "shard3",  "host" : "shard3/mongo01-jp:27029,mongo03-jp:27029",  "state" : 1 }

active mongoses:

"3.4.0" : 1

autosplit:

Currently enabled: yes

balancer:

Currently enabled:  yes

Currently running:  no

Balancer lock taken at Wed Dec 14 2016 06:24:31 GMT+0000 (UTC) by ConfigServer:Balancer

Failed balancer rounds in last 5 attempts:  0

Migration Results for the last 24 hours:

11 : Success

databases:

{  "_id" : "test",  "primary" : "shard3",  "partitioned" : true }

test.user

shard key: { "uid" : 1 }

unique: false

balancing: true

chunks:

shard1 5

shard2 4

shard3 4

{ "uid" : { "$minKey" : 1 } } -->> { "uid" : "user10" } on : shard3 Timestamp(9, 1)

{ "uid" : "user10" } -->> { "uid" : "user17659" } on : shard1 Timestamp(4, 1)

{ "uid" : "user17659" } -->> { "uid" : "user2" } on : shard1 Timestamp(3, 4)

{ "uid" : "user2" } -->> { "uid" : "user2832" } on : shard1 Timestamp(6, 0)

{ "uid" : "user2832" } -->> { "uid" : "user32174" } on : shard3 Timestamp(7, 0)

{ "uid" : "user32174" } -->> { "uid" : "user36003" } on : shard1 Timestamp(8, 0)

{ "uid" : "user36003" } -->> { "uid" : "user5211" } on : shard2 Timestamp(8, 1)

{ "uid" : "user5211" } -->> { "uid" : "user5974" } on : shard2 Timestamp(6, 4)

{ "uid" : "user5974" } -->> { "uid" : "user6713" } on : shard2 Timestamp(4, 7)

{ "uid" : "user6713" } -->> { "uid" : "user8" } on : shard2 Timestamp(4, 4)

{ "uid" : "user8" } -->> { "uid" : "user87659" } on : shard3 Timestamp(8, 2)

{ "uid" : "user87659" } -->> { "uid" : "user9999" } on : shard3 Timestamp(8, 3)

{ "uid" : "user9999" } -->> { "uid" : { "$maxKey" : 1 } } on : shard1 Timestamp(9, 0)

test.user2

shard key: { "_id" : "hashed" }

unique: false

balancing: true

chunks:

shard1 3

shard2 3

shard3 2

{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-7785268750491956891") } on : shard2 Timestamp(4, 0)

{ "_id" : NumberLong("-7785268750491956891") } -->> { "_id" : NumberLong("-6358150028456512613") } on : shard1 Timestamp(4, 1)

{ "_id" : NumberLong("-6358150028456512613") } -->> { "_id" : NumberLong("-6148914691236517204") } on : shard1 Timestamp(3, 10)

{ "_id" : NumberLong("-6148914691236517204") } -->> { "_id" : NumberLong("-3074457345618258602") } on : shard1 Timestamp(3, 3)

{ "_id" : NumberLong("-3074457345618258602") } -->> { "_id" : NumberLong(0) } on : shard2 Timestamp(3, 4)

{ "_id" : NumberLong(0) } -->> { "_id" : NumberLong("3074457345618258602") } on : shard2 Timestamp(3, 5)

{ "_id" : NumberLong("3074457345618258602") } -->> { "_id" : NumberLong("6148914691236517204") } on : shard3 Timestamp(3, 6)

{ "_id" : NumberLong("6148914691236517204") } -->> { "_id" : { "$maxKey" : 1 } } on : shard3 Timestamp(3, 7)

二、关于balancing

balancing如果一个shard上chunks比其他shard更多,即不平衡状态,那么mongos将会自动对chunks迁移以达到平衡,balancing的过程不会影响用户的数据操作。集群中任何mongos实例都可以启动balancing线程,默认balancer是开启状态;Config 数据库(Config servers中)中有个lock表,当balancer活跃时,相应的mongos将会尝试通过修改document方式获取“lock”,如果获取“lock”成功,则此mongos负责balancing工作。大家需要注意,mongos实例的本地系统时间会对lock机制带来影响,需要所有的mongos(包括集群中的所有shards、config servers)的时间保持一致(ntpd指令)。

balancer将chunks从持有chunks最多的shard上迁移到持久chunks最少的shard,每次迁移一个,直到集群相对平衡 (最多chunks节点与最少chunks节点之间相差不超过threshold个)。chunks迁移可能会消耗磁盘空间,那些已经迁移出去的chunks不会立即删除,而是归档到一个特定的目录下,“归档”(archive)特性默认是开启的;此外迁移还会消耗一定的网络带宽,或许会影响到性能,影响用户操作的IO吞吐量。建议每次迁移一个chunk,且只有当“最多”与“最少”的差值达到threshold时才开始balancer;或者指定一个时间区间,balancer只会在此时间段内才会迁移chunks。

threshold该值目前没有办法修改,当chunks总数< 20时,threshold=2,总数 >= 80时,threshold=8,其他为4。一旦balancing工作启动,只有当chunks分布均衡后才会停止。

默认情况下,mongodb会尽可能的耗尽可用磁盘空间,所以需要关注mongodb对磁盘的消耗量;不过当向集群中添加shard节点时,可以指定当前shard允许使用的最大磁盘空间(max size),当shard的磁盘消耗量达到最大值后,balancer将不会向其再迁移chunks,但这不影响此shard上继续接受write操作。

balancer运行在mongos实例上,控制chunks的分布和迁移,全局只有一个balancer处于active状态,可以通过“sh.getBalancerState()”或者“sh.status()”查看balancer是否开启,可以通过“sh.getBalancerHost()”查看balancer运行在哪个mongos上。

1)可以通过sh.setBalancerState(false)来关闭balancer功能,也可以通过设定为true开启balancer。

2)可以通过sh.startBlancer()或者sh.stopBalancer()来开关闭balancer。

3)可以通过db.locks.find({_id:"balancer"})查看balancer持有锁的情况。

4)可以通过修改settting表中的配置来指定balancer的运行时间区间 。其中start和stop格式为“HH:mm”,不需要指定日期。修改activeWindow配置时需要确保balancer的state为true

mongos> sh.getBalancerState()

true

mongos> sh.setBalancerState(false)

{ "ok" : 1 }

mongos> sh.getBalancerState()

false

mongos> sh.setBalancerState(true)

{ "ok" : 1 }

mongos> use config

switched to db config

mongos> db.locks.find({_id:"balancer"})

{ "_id" : "balancer", "state" : 2, "ts" : ObjectId("5850de85ce8b5f7ab7cfacdd"), "who" : "ConfigServer:Balancer", "process" : "ConfigServer", "when" : ISODate("2016-12-14T06:24:31.625Z"), "why" : "CSRS Balancer" }

mongos> db.settings.find()

{ "_id" : "chunksize", "value" : NumberLong(5) }

{ "_id" : "balancer", "stopped" : false, "mode" : "full" }

mongos> db.settings.update(

... { _id:"balancer"},

... { $set: { activeWindow: { start:"23:00",stop:"6:00"} } },

... { upsert: true }

... )

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

mongos> db.settings.find()

{ "_id" : "chunksize", "value" : NumberLong(5) }

{ "_id" : "balancer", "stopped" : false, "mode" : "full", "activeWindow" : { "start" : "23:00", "stop" : "6:00" } }

参数 _secondaryThrottlewaitForDelete:

_secondaryThrottle表示是对secondary进行节流,默认为true,其语义等同write concern中的{w:2},即当chunk迁移时(documents复制)destination shard中至少有一个secondary接收成功,balancer才会继续进行下一个chunk;不过开发者可以关闭此参数(同{w:1}),同时与write concern一起使用

_waitForDelete表示balancer是否等待source shard删除已经迁移成功的chunk后才继续处理下一个chunk,默认为false,即不等待。

mongos> use config

switched to db config

mongos> db.settings.update (

... { "_id":"balancer"},

... { $set: {"_secondaryThrottle":false, "writeConncern":{"w":"majority"} } },

... { upsert: true}

... )

WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

mongos> db.setting.update(

... {"_id":"balancer"},

... {$set:{"_waitForDelete":true } },

... {upsert:true}

... )

WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "balancer" })

mongos>

时间: 2024-11-07 11:53:27

mongodb sharding maintenance (分片维护1)的相关文章

MongoDB Sharding Cluster分片集群

MongoDB Sharding Cluster 第1章 分片技术简述: sharding是MongoDB用来将大型集合分割高不同服务器上所采用的方法,尽管分片起源于关系型数据库分区,但MongoDB分片完全又是另一回事 和mysql分区方案相比,MongoDB的最大区别在于它几乎能自动完成所有事情,只要告诉MongoDB要分配数据,它就能自动维护数据在不同的服务器之间的均衡 1.1 分片的目的: ?  垂直扩展:增加更多的cpu和存储资源来扩展容量,也属于硬件扩展 ?  水平扩展:将数据集分布

MongoDB Sharding Cluster

第1章 分片技术简述: sharding是MongoDB用来将大型集合分割高不同服务器上所采用的方法,尽管分片起源于关系型数据库分区,但MongoDB分片完全又是另一回事 和mysql分区方案相比,MongoDB的最大区别在于它几乎能自动完成所有事情,只要告诉MongoDB要分配数据,它就能自动维护数据在不同的服务器之间的均衡 1.1 分片的目的: ?  垂直扩展:增加更多的cpu和存储资源来扩展容量,也属于硬件扩展 ?  水平扩展:将数据集分布在多个服务器上,水平扩展即分片 1.2 分片设计思

MongoDB学习笔记——分片(Sharding)

分片(Sharding) 分片就是将数据进行拆分,并将其分别存储在不同的服务器上 MongoDB支持自动分片能够自动处理数据在分片上的分布 MongoDB分片有三种角色 配置服务器:一个单独的mongod进程,主要记录了哪个分片服务器包含了哪些数据的信息,保存的只是数据的分布表,如果配置服务器不可用时,将变为只读,不能进行分片和数据迁移, 配置服务器的1KB空间相当于真实数据的200MB,所以配置服务器不需要太多的资源和配置.但是每个配置服务器都建议部署在不同的物理机上, 配置服务器相当于整个集

57-4 数据库分片概念及mongodb sharding的实现

04 数据库分片的概念及mongodb sharding的实现 配置环境: node1: 192.168.1.121 CentOS release 6.7 node2: 192.168.1.122 CentOS release 6.7 node3: 192.168.1.123 CentOS release 6.7 [[email protected] ~]# vim /etc/hosts 添加 192.168.1.121   node1 192.168.1.122   node2 192.168

Mongodb Sharding 分片

Mongodb Sharding 介绍 Sharding in MongoDB 分片组建: Shards(建议用Replica).Query Routers.Config Servers. Shards store the data. To provide high availability and dataconsistency, in a production sharded cluster, each shard is a replica set [1].For more informat

Mongodb 笔记07 分片

分片 1. 分片(sharding)是指将数据拆分,将其分散存放在不同的机器上的过程.有时也用分区(partitioning)来表示这个概念.将数据分散到不同的机器上,不需要功能强大的大型计算机就可以 存储更多的数据,处理更大的负载. 2. MongoDB支持自动分片(autosharding),可以使数据库架构对应用程序不可见,也可以简化系统管理.对应用程序而言,好像始终在使用一个单机的MongoDB服务器一样.另一方面, mongoDB自动处理数据在分片上的分布,也更容易添加和删除分片技术.

MongoDB中的分片

通过分片能够增加更多的机器来应对不断增加的负载和数据,还不影响应用.分片(sharding)是指将数据拆分,将其分散到不同的机器上,不需要功能强大的大型计算机就可以存储更多的数据,处理更大的负载. MongoDB支持自动分片,可以摆脱手动分片的管理困扰,集群自动切分数据,做负载均衡.分片的基本思想就是将集合切分成小块,这些块分散到若干片里面,每个片只负责总数据的一部分.应用程序不必知道哪片对应哪些数据,甚至不知道数据已经拆分,所以在分片之前要运行一个路由进程(mongos),这个路由知道所有数据

第五部分 架构篇 第二十一章 MongoDB Sharding 架构(实践)

这是一种将海量的数据水平扩展的数据库集群系统,数据分别存储在sharding的各个节点上,使用者通过简单的配置就可以很方便地构建一个分布式MongoDB集群. MongoDB的数据分块成为chunk,每个chunk都是Collection中一段连续的数据记录,通常最大尺寸是200MB,超出则生成新的数据块. 要构建一个MongoDB Sharding Cluster需要以下三个角色: Shard Server 即存储实际数据的分片,每个Shard可以使一个mongod实例,也可以使一组mongo

【MongoDB】03、MongoDB索引及分片

一.MongoDB配置 mongodb配置文件/etc/mongodb.conf中的配置项,其实都是mongod启动选项(和memcached一样) [[email protected] ~]# mongod --help Allowed options: General options:   -h [ --help ]               show this usage information   --version                   show version inf