拓扑结构介绍:(两个分片的分片集群)
共采用3台虚拟机进行模拟,采用的是一机多实例的模式
hosts文件:
192.168.43.120 mongod01 member1.test.com member2.test.com
192.168.43.121 mongod02 member3.test.com member4.test.com
192.168.43.122 mongod03 member5.test.com member6.test.com
角色分布:
192.168.43.120 mongod01 shard1(27010) shard2(27011) config(27019) mongos(27017)
192.168.43.121 mongod02 shard1(27010) shard2(27011) config(27019) mongos(27017)
192.168.43.122 mongod03 shard1(27010) shard2(27011) config(27019) mongos(27017)
版本 :mongodb-linux-x86_64-rhel70-4.2.1.tgz(这里使用Archive包)
OS :CentOS Linux release 7.7.1908 (Core)
备注 :我们的部署方式是,先部署1个分片(shard1),后因业务扩展增加1个分片(shard2)。
一、系统基础配置(所有节点)
1.系统基础配置,请参阅:《MongoDB的安装配置文档》
[root@mongod01 opt]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.43.120 mongod01 member1.test.com member2.test.com
192.168.43.121 mongod02 member3.test.com member4.test.com
192.168.43.122 mongod03 member5.test.com member6.test.com
[root@mongod01 opt]#
2.MongoDB的安装
[root@mongod01 opt]# ll
total 112892
-rw-r--r-- 1 root root 115601247 Aug 28 16:50 mongodb-linux-x86_64-rhel70-4.2.1.tgz
[root@mongod01 opt]# tar -xf mongodb-linux-x86_64-rhel70-4.2.1.tgz
[root@mongod01 opt]# mv mongodb-linux-x86_64-rhel70-4.2.1 /usr/local/mongodb
[root@mongod01 opt]# ls
mongodb-linux-x86_64-rhel70-4.2.1.tgz
[root@mongod01 opt]# export PATH=/usr/local/mongodb/bin:$PATH
[root@mongod01 opt]# echo $PATH
/usr/local/mongodb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@mongod01 opt]# mongo
mongo mongodump mongofiles mongoreplay mongos mongotop
mongod mongoexport mongoimport mongorestore mongostat
[root@mongod01 opt]#
[root@mongod01 opt]# tail -n 1 ~/.bashrc
export PATH=/usr/local/mongodb/bin:$PATH
[root@mongod01 opt]#
二、搭建Shard1集群
1.建立目录结构(所有节点均执行)
在member1/member3/member5上执行以下命令:
[root@mongod01 opt]# mkdir -p /data/shard1/
[root@mongod01 opt]# mkdir -p /data/config/
在member2/member4/member6上执行以下命令:
[root@mongod01 opt]# mkdir -p /data/shard2/
[root@mongod01 opt]# mkdir -p /data/mongos/
2.配置shard1(所有节点均执行)
[root@mongod01 opt]# mongod --bind_ip 0.0.0.0 --replSet shard1 --dbpath /data/shard1 --logpath /data/shard1/mongod.log --port 27010 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
about to fork child process, waiting until server is ready for connections.
forked process: 1447
child process started successfully, parent exiting
[root@mongod01 opt]#
[root@mongod01 opt]# ps -ef | grep mongo
root 1447 1 2 17:24 ? 00:00:01 mongod --bind_ip 0.0.0.0 --replSet shard1 --dbpath /data/shard1 --logpath /data/shard1/mongod.log --port 27010 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
root 1484 1337 0 17:25 pts/0 00:00:00 grep --color=auto mongo
[root@mongod01 opt]# ls /data/shard1/
collection-0--6201776936303923309.wt index-1--6201776936303923309.wt _mdb_catalog.wt WiredTigerLAS.wt
collection-2--6201776936303923309.wt index-3--6201776936303923309.wt mongod.lock WiredTiger.lock
collection-4--6201776936303923309.wt index-5--6201776936303923309.wt mongod.log WiredTiger.turtle
collection-6--6201776936303923309.wt index-7--6201776936303923309.wt sizeStorer.wt WiredTiger.wt
collection-8--6201776936303923309.wt index-9--6201776936303923309.wt storage.bson
diagnostic.data journal WiredTiger
[root@mongod01 opt]#
3.测试shard1的配置
[root@mongod01 opt]# mongo --host member3.test.com:27010
MongoDB shell version v4.2.1
connecting to: mongodb://member3.test.com:27010/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("27980534-a175-4c31-8e31-0bdd856da8d1") }
MongoDB server version: 4.2.1
>
4.初始化shard1复制集
目前:3个实例并没有实际的关联,我们通过初始化将3个节点关联起来,我们选用mongod01节点来进行初始化。
[root@mongod01 opt]# mongo --host member1.test.com:27010
MongoDB shell version v4.2.1
connecting to: mongodb://member1.test.com:27010/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("75f17945-5120-43dc-b2e1-41b41ba36fa8") }
MongoDB server version: 4.2.1
> rs.initiate({
... _id: "shard1",
... "members" : [
... {
... "_id": 0,
... "host" : "member1.test.com:27010"
... },
... {
... "_id": 1,
... "host" : "member3.test.com:27010"
... },
... {
... "_id": 2,
... "host" : "member5.test.com:27010"
... }
... ]
... });
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1598607067, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1598607067, 1)
}
shard1:SECONDARY>
shard1:PRIMARY>
三、搭建config(所有节点执行)
1.配置config
与shard1类似的方式,我们可以搭建config服务器。在member1/member3/member5上执行以下命令:
[root@mongod01 opt]# mongod --bind_ip 0.0.0.0 --replSet config --dbpath /data/config --logpath /data/config/mongod.log --port 27019 --fork --configsvr --wiredTigerCacheSizeGB 0.3
about to fork child process, waiting until server is ready for connections.
forked process: 1557
child process started successfully, parent exiting
[root@mongod01 opt]#
[root@mongod01 opt]# ps -ef | grep mongo
root 1447 1 1 17:24 ? 00:00:13 mongod --bind_ip 0.0.0.0 --replSet shard1 --dbpath /data/shard1 --logpath /data/shard1/mongod.log --port 27010 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
root 1557 1 2 17:39 ? 00:00:01 mongod --bind_ip 0.0.0.0 --replSet config --dbpath /data/config --logpath /data/config/mongod.log --port 27019 --fork --configsvr --wiredTigerCacheSizeGB 0.3
root 1607 1337 0 17:39 pts/0 00:00:00 grep --color=auto mongo
[root@mongod01 opt]# netstat -anultp | grep 27019
tcp 0 0 0.0.0.0:27019 0.0.0.0:* LISTEN 1557/mongod
[root@mongod01 opt]#
2.测试config
[root@mongod01 opt]# mongo --host member5.test.com:27019
MongoDB shell version v4.2.1
connecting to: mongodb://member5.test.com:27019/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("fe8496d3-76fa-49c7-8496-499e71164a5b") }
MongoDB server version: 4.2.1
> exit
bye
3.初始化config复制集
目前:3个实例并没有实际的关联,我们通过初始化将3个节点关联起来,我们选用mongod01节点来进行初始化。
[root@mongod01 opt]# mongo --host member1.test.com:27019
MongoDB shell version v4.2.1
connecting to: mongodb://member1.test.com:27019/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b23e5db4-5314-4196-85dd-858f3b1c57c0") }
MongoDB server version: 4.2.1
> rs.initiate({
... _id: "config",
... "members" : [
... {
... "_id": 0,
... "host" : "member1.test.com:27019"
... },
... {
... "_id": 1,
... "host" : "member3.test.com:27019"
... },
... {
... "_id": 2,
... "host" : "member5.test.com:27019"
... }
... ]
... });
{
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1598607774, 1),
"electionId" : ObjectId("000000000000000000000000")
},
"lastCommittedOpTime" : Timestamp(0, 0),
"$clusterTime" : {
"clusterTime" : Timestamp(1598607774, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1598607774, 1)
}
config:SECONDARY>
config:PRIMARY>
四、搭建mongos(所有节点执行)
1.配置mongos
mongos的搭建比较简单,我们在member2/member4/member6上搭建3个mongos。注意以下参数:
configdb: 表示config使用的集群地址;
[root@mongod01 opt]# mongos --bind_ip 0.0.0.0 --logpath /data/mongos/mongos.log --port 27017 --configdb config/member1.test.com:27019,member3.test.com:27019,member5.test.com:27019 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 1681
child process started successfully, parent exiting
[root@mongod01 opt]#
2.连接测试
[root@mongod01 opt]# mongo --host member3.test.com:27017
MongoDB shell version v4.2.1
connecting to: mongodb://member3.test.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("274df7ea-7009-43ad-a9b2-69e3bfc30b9b") }
MongoDB server version: 4.2.1
Server has startup warnings:
2020-08-28T17:47:38.546+0800 I CONTROL [main]
2020-08-28T17:47:38.546+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2020-08-28T17:47:38.546+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2020-08-28T17:47:38.546+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2020-08-28T17:47:38.546+0800 I CONTROL [main]
mongos>
3.连接到mongos,将shard1加入到集群中
我们选用mongod01节点来进行操作:
[root@mongod01 opt]# mongo --host member1.test.com:27017
MongoDB shell version v4.2.1
connecting to: mongodb://member1.test.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5676b3ac-d0cb-461c-9fd1-3e0807655dae") }
MongoDB server version: 4.2.1
Server has startup warnings:
2020-08-28T17:47:33.351+0800 I CONTROL [main]
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2020-08-28T17:47:33.351+0800 I CONTROL [main]
mongos> sh.addShard("shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010");
{
"shardAdded" : "shard1",
"ok" : 1,
"operationTime" : Timestamp(1598608469, 7),
"$clusterTime" : {
"clusterTime" : Timestamp(1598608469, 7),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos>
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f48d1aaccf718da44dc704b")
}
shards:
{ "_id" : "shard1", "host" : "shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010", "state" : 1 }
active mongoses:
"4.2.1" : 3
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
mongos>
五、创建分片表
MongoDB的分片是基于表的,我们选用mongod01进行操作:
1.查看当前分片信息
[root@mongod01 opt]# mongo --host member1.test.com:27017
MongoDB shell version v4.2.1
connecting to: mongodb://member1.test.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e9cbd814-3448-472c-9166-4ac45632b734") }
MongoDB server version: 4.2.1
Server has startup warnings:
2020-08-28T17:47:33.351+0800 I CONTROL [main]
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2020-08-28T17:47:33.351+0800 I CONTROL [main]
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f48d1aaccf718da44dc704b")
}
shards:
{ "_id" : "shard1", "host" : "shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010", "state" : 1 }
active mongoses:
"4.2.1" : 3
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shard1 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
mongos>
2.设置foo库的bar集合基于_id(分片键)进行hash分片
mongos>
mongos> sh.enableSharding("foo");
{
"ok" : 1,
"operationTime" : Timestamp(1598608896, 5),
"$clusterTime" : {
"clusterTime" : Timestamp(1598608896, 5),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos> sh.shardCollection("foo.bar", {_id: 'hashed'});
{
"collectionsharded" : "foo.bar",
"collectionUUID" : UUID("1f425b6a-f84f-4ca1-9f25-b68dff0b834c"),
"ok" : 1,
"operationTime" : Timestamp(1598608903, 16),
"$clusterTime" : {
"clusterTime" : Timestamp(1598608903, 16),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos> sh.status();
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f48d1aaccf718da44dc704b")
}
shards:
{ "_id" : "shard1", "host" : "shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010", "state" : 1 }
active mongoses:
"4.2.1" : 3
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shard1 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
{ "_id" : "foo", "primary" : "shard1", "partitioned" : true, "version" : { "uuid" : UUID("06a2922d-c9a6-41aa-8410-d03f440f8536"), "lastMod" : 1 } }
foo.bar
shard key: { "_id" : "hashed" }
unique: false
balancing: true
chunks:
shard1 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : shard1 Timestamp(1, 0)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 1)
mongos>
3.写入测试数据
mongos> use foo
switched to db foo
mongos> for (var i = 0; i < 10000; i++) {
... db.bar.insert({i: i});
... }
WriteResult({ "nInserted" : 1 })
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f48d1aaccf718da44dc704b")
}
shards:
{ "_id" : "shard1", "host" : "shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010", "state" : 1 }
active mongoses:
"4.2.1" : 3
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shard1 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
{ "_id" : "foo", "primary" : "shard1", "partitioned" : true, "version" : { "uuid" : UUID("06a2922d-c9a6-41aa-8410-d03f440f8536"), "lastMod" : 1 } }
foo.bar
shard key: { "_id" : "hashed" }
unique: false
balancing: true
chunks:
shard1 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : shard1 Timestamp(1, 0)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 1)
mongos>
六、扩容,向分片集加入新的分片(所有节点操作)
1.搭建shard2并将其加入分片集中,观察发生的效果。
在member2/member4/member6上执行以下命令:
[root@mongod01 opt]# mongod --bind_ip 0.0.0.0 --replSet shard2 --dbpath /data/shard2 --logpath /data/shard2/mongod.log --port 27011 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
about to fork child process, waiting until server is ready for connections.
forked process: 1876
child process started successfully, parent exiting
[root@mongod01 opt]# ps -ef | grep mongo
root 1447 1 1 17:24 ? 00:00:53 mongod --bind_ip 0.0.0.0 --replSet shard1 --dbpath /data/shard1 --logpath /data/shard1/mongod.log --port 27010 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
root 1557 1 1 17:39 ? 00:00:34 mongod --bind_ip 0.0.0.0 --replSet config --dbpath /data/config --logpath /data/config/mongod.log --port 27019 --fork --configsvr --wiredTigerCacheSizeGB 0.3
root 1681 1 0 17:47 ? 00:00:11 mongos --bind_ip 0.0.0.0 --logpath /data/mongos/mongos.log --port 27017 --configdb config/member1.test.com:27019,member3.test.com:27019,member5.test.com:27019 --fork
root 1876 1 8 18:10 ? 00:00:01 mongod --bind_ip 0.0.0.0 --replSet shard2 --dbpath /data/shard2 --logpath /data/shard2/mongod.log --port 27011 --fork --shardsvr --wiredTigerCacheSizeGB 0.3
root 1912 1337 0 18:11 pts/0 00:00:00 grep --color=auto mongo
[root@mongod01 opt]# netstat -anultp | grep 27011
tcp 0 0 0.0.0.0:27011 0.0.0.0:* LISTEN 1876/mongod
[root@mongod01 opt]#
2.测试
[root@mongod01 opt]# mongo --host member6.test.com:27011
MongoDB shell version v4.2.1
connecting to: mongodb://member6.test.com:27011/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a3718155-30fa-4cd0-a097-386821fc7854") }
MongoDB server version: 4.2.1
> exit
bye
3.初始化shard2复制集
这里,我们选择mongod01进行初始化操作:
[root@mongod01 opt]# mongo --host member2.test.com:27011
MongoDB shell version v4.2.1
connecting to: mongodb://member2.test.com:27011/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("880fad95-25af-4cf2-8308-6c50cf9c14f4") }
MongoDB server version: 4.2.1
> rs.initiate({
... _id: "shard2",
... "members" : [
... {
... "_id": 0,
... "host" : "member2.test.com:27011"
... },
... {
... "_id": 1,
... "host" : "member4.test.com:27011"
... },
... {
... "_id": 2,
... "host" : "member6.test.com:27011"
... }
... ]
... });
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1598609665, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1598609665, 1)
}
shard2:SECONDARY>
shard2:SECONDARY>
shard2:PRIMARY>
4.通过mongos,将shard2加入到集群中
连接到任意mongos:
[root@mongod01 opt]# mongo --host member1.test.com:27017
MongoDB shell version v4.2.1
connecting to: mongodb://member1.test.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("845d8b44-e3b9-4418-aa62-8e4530ba4a5d") }
MongoDB server version: 4.2.1
Server has startup warnings:
2020-08-28T17:47:33.351+0800 I CONTROL [main]
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
2020-08-28T17:47:33.351+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2020-08-28T17:47:33.351+0800 I CONTROL [main]
mongos>
进行加群操作:
mongos> sh.addShard("shard2/member2.test.com:27011,member4.test.com:27011,member6.test.com:27011");
{
"shardAdded" : "shard2",
"ok" : 1,
"operationTime" : Timestamp(1598609852, 6),
"$clusterTime" : {
"clusterTime" : Timestamp(1598609852, 6),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
mongos>
5.观察集群状态
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f48d1aaccf718da44dc704b")
}
shards:
{ "_id" : "shard1", "host" : "shard1/member1.test.com:27010,member3.test.com:27010,member5.test.com:27010", "state" : 1 }
{ "_id" : "shard2", "host" : "shard2/member2.test.com:27011,member4.test.com:27011,member6.test.com:27011", "state" : 1 }
active mongoses:
"4.2.1" : 3
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
1 : Success
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shard1 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
{ "_id" : "foo", "primary" : "shard1", "partitioned" : true, "version" : { "uuid" : UUID("06a2922d-c9a6-41aa-8410-d03f440f8536"), "lastMod" : 1 } }
foo.bar
shard key: { "_id" : "hashed" }
unique: false
balancing: true
chunks:
shard1 1
shard2 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : shard2 Timestamp(2, 0)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(2, 1)
mongos>
参阅:
https://github.com/geektime-geekbang/geektime-mongodb-course/blob/master/sharded-cluster/lab-script.md
https://www.mongodb.com/download-center/community/releases/archive