3台机器,3个复制集(shard1,shard2,shard3),3个shards ,3个config servers,3个mongos
机器:
192.168.1.158
192.168.1.224
192.168.1.78
-------------------------------------------------------------------------------
先建目录(192.168.1.158)
/data/servers/sharding/shard1-1、/data/servers/sharding/shard2-1、/data/servers/sharding/shard3-1、/data/servers/sharding/config
192.168.1.224
/data/servers/sharding/shard1-2、/data/servers/sharding/shard2-2、/data/servers/sharding/shard3-2、/data/servers/sharding/config
192.168.1.78
/data/servers/sharding/shard1-3、/data/servers/sharding/shard2-3、/data/servers/sharding/shard3-3、/data/servers/sharding/config
----------------------------------------------------------------------------
分别在3台机器上启动复制集shard1:
192.168.1.158
bin/mongod --shardsvr --replSet shard1 --dbpath /data/servers/sharding/shard1-1 --logpath /data/servers/sharding/shard1.log --port 28011 --logappend --oplogSize 100 --fork
192.168.1.224
bin/mongod --shardsvr --replSet shard1 --dbpath /data/servers/sharding/shard1-2 --logpath /data/servers/sharding/shard1.log --port 28011 --logappend --oplogSize 100 --fork
192.168.1.78
bin/mongod --shardsvr --replSet shard1 --dbpath /data/servers/sharding/shard1-3 --logpath /data/servers/sharding/shard1.log --port 28011 --logappend --oplogSize 100 --fork
用 mongo 连接其中一台机器的 28011端口的 mongod,初始化 Replica Sets“shard1”,执行:
bin/mongo --port 28011
> use admin
>config = {_id:'shard1',members:[ {_id:0,host:'192.168.1.158:28011'}, {_id:1,host:'192.168.1.224:28011'}, {_id:2,host:'192.168.1.78:28011'}]}
>rs.initiate(config)
----------------------------------------------------------
分别在3台机器上启动复制集shard2:
192.168.1.158
bin/mongod --shardsvr --replSet shard2 --dbpath /data/servers/sharding/shard2-1 --logpath /data/servers/sharding/shard2.log --port 28022 --logappend --oplogSize 100 --fork
192.168.1.224
bin/mongod --shardsvr --replSet shard2 --dbpath /data/servers/sharding/shard2-2 --logpath /data/servers/sharding/shard2.log --port 28022 --logappend --oplogSize 100 --fork
192.168.1.78
bin/mongod --shardsvr --replSet shard2 --dbpath /data/servers/sharding/shard2-3 --logpath /data/servers/sharding/shard2.log --port 28022 --logappend --oplogSize 100 --fork
用 mongo 连接其中一台机器的 28022端口的 mongod,初始化 Replica Sets“shard1”,执行:
bin/mongo --port 28022
> use admin
>config = {_id:'shard2',members:[ {_id:0,host:'192.168.1.158:28022'}, {_id:1,host:'192.168.1.224:28022'}, {_id:2,host:'192.168.1.78:28022'}]}
>rs.initiate(config)
------------------------------------------------------------
分别在3台机器上启动复制集shard3:
192.168.1.158
bin/mongod --shardsvr --replSet shard3 --dbpath /data/servers/sharding/shard3-1 --logpath /data/servers/sharding/shard3.log --port 28033 --logappend --oplogSize 100 --fork
192.168.1.224
bin/mongod --shardsvr --replSet shard3 --dbpath /data/servers/sharding/shard3-2 --logpath /data/servers/sharding/shard3.log --port 28033 --logappend --oplogSize 100 --fork
192.168.1.78
bin/mongod --shardsvr --replSet shard3 --dbpath /data/servers/sharding/shard3-3 --logpath /data/servers/sharding/shard3.log --port 28033 --logappend --oplogSize 100 --fork
用 mongo 连接其中一台机器的 28033端口的 mongod,初始化 Replica Sets“shard1”,执行:
bin/mongo --port 28033
> use admin
>config = {_id:'shard3',members:[ {_id:0,host:'192.168.1.158:28033'}, {_id:1,host:'192.168.1.224:28033'}, {_id:2,host:'192.168.1.78:28033'}]}
>rs.initiate(config)
------------------------------------------------------------------------------------------------------------
分别在3台机器上启动config server
bin/mongod --configsvr --dbpath /data/servers/sharding/config --port 20000 --logpath /data/servers/sharding/config.log --logappend --fork
(操作的时候误把--configsvr 写成 --shardsvr ,不知道后果会怎么样。。。)
---------------------------------------------------------------------------------------------------------------------
配置 3 台 Route Process, 分别在3台机器上启动mongos
bin/mongos --configdb 192.168.1.158:20000,192.168.1.224:20000,192.168.1.78:20000 --port 30000 --logpath /data/servers/sharding/mongos.log --logappend --fork
----------------------------------------------------------------------------------------------------------
配置 shard cluster ,连接到其中一台机器的端口 30000 的 mongos 进程,并切换到 admin 数据库做以下配置 (这样也行:sh.addShard("shard1/192.168.1.158:28011") 版本2.2前是用下面这种方式,要有三个host)
bin/mongo --port 3000
>use admin
mongos>db.runCommand({addshard:"shard1/192.168.1.158:28011,192.168.1.224:28011,192.168.1.78:28011"});
{ "shardAdded" : "shard1", "ok" : 1 }
mongos>db.runCommand({addshard:"shard2/192.168.1.158:28022,192.168.1.224:28022,192.168.1.78:28022"});
{ "shardAdded" : "shard2", "ok" : 1 }
mongos>db.runCommand({addshard:"shard3/192.168.1.158:28033,192.168.1.224:28033,192.168.1.78:28033"});
{ "shardAdded" : "shard3", "ok" : 1 }
×××××××××××××××测试sharding××××××××××××××××××××
激活数据库及集合的分片
mongos> db.runCommand({enablesharding:"test"})
{ "ok" : 1 }
mongos> db.runCommand({shardcollection:"test.users",key:{_id:1}})
{ "collectionsharded" : "test.users", "ok" : 1 }
mongos> use test
switched to db test
插入数据测试
mongos> for (var i=1;i<=200000;i++) db.users.insert({id:i,addr_1:"Beijing",addr_2:"Shanghai"});
WriteResult({ "nInserted" : 1 })
mongos> db.users.stats()
{
"sharded" : true,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"ns" : "test.users",
"count" : 199999,
"numExtents" : 14,
"size" : 22399888,
"storageSize" : 33697792,
"totalIndexSize" : 6516272,
"indexSizes" : {
"_id_" : 6516272
},
"avgObjSize" : 112,
"nindexes" : 1,
"nchunks" : 5,
"shards" : {
"shard1" : {
"ns" : "test.users",
"count" : 38932,
"size" : 4360384,
"avgObjSize" : 112,
"numExtents" : 6,
"storageSize" : 11182080,
"lastExtentSize" : 8388608,
"paddingFactor" : 1,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"nindexes" : 1,
"totalIndexSize" : 1267280,
"indexSizes" : {
"_id_" : 1267280
},
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("56d11f4e39d85dcded6d7706")
}
},
"shard2" : {
"ns" : "test.users",
"count" : 161066,
"size" : 18039392,
"avgObjSize" : 112,
"numExtents" : 7,
"storageSize" : 22507520,
"lastExtentSize" : 11325440,
"paddingFactor" : 1,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"nindexes" : 1,
"totalIndexSize" : 5240816,
"indexSizes" : {
"_id_" : 5240816
},
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("56d1209068bcf815c91b4cdd")
}
},
"shard3" : {
"ns" : "test.users",
"count" : 1,
"size" : 112,
"avgObjSize" : 112,
"numExtents" : 1,
"storageSize" : 8192,
"lastExtentSize" : 8192,
"paddingFactor" : 1,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"nindexes" : 1,
"totalIndexSize" : 8176,
"indexSizes" : {
"_id_" : 8176
},
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("56d121247c2081829a8e3044")
}
}
},
"ok" : 1
}
分享到:
相关推荐
赠送jar包:mongodb-driver-sync-4.2.3.jar; 赠送原API文档:mongodb-driver-sync-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-sync-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-sync-4.2.3....
赠送jar包:mongodb-driver-core-4.2.3.jar; 赠送原API文档:mongodb-driver-core-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-core-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-core-4.2.3....
赠送jar包:mongodb-driver-sync-4.2.3.jar; 赠送原API文档:mongodb-driver-sync-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-sync-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-sync-4.2.3....
mongodb-windows安装包: mongodb-compass-1.31.2-win32-x64.msi 打开直接安装
MongoDB异步驱动程序(mongodb-async-driver)是为Java开发者设计的一个库,它允许应用程序以非阻塞的方式与MongoDB服务器进行通信,提高了处理大量并发请求的能力。 在"mongodb-async-driver-2.0.1.jar"这个特定...
`mongodb-driver-3.5.0.jar`是完整版的MongoDB Java驱动,它扩展了`mongodb-driver-core`,提供了更高级别的操作接口,如`MongoClient`和`MongoDatabase`,方便开发者进行数据库操作。这个驱动程序使开发者能够方便...
mongodb-win32-x86_64-2012plus-4.2.20-signed
java和mongodb连接,需要mongodb-driver,您还必须下载其依赖项: bson和 mongodb-driver-core》》3个包: mongodb-driver-3.8.2.jar; bson-3.8.2.jar; mongodb-driver-core-3.8.2.jar
`mongodb-linux-x86_64-rhel70-4.2.5.tgz`是一个专为RHEL 7.0系统设计的MongoDB二进制包,版本为4.2.5。 首先,安装MongoDB需要确保系统满足最低要求,例如兼容的Linux内核版本、足够的内存以及适当的硬件配置。...
mongodb-linux-x86_64-4.0.10.tgz的下载 mongodb-linux-x86_64-4.0.10.tgz的下载 mongodb-linux-x86_64-4.0.10.tgz的下载
MongoDB Community Server(mongodb-org-server_5.0.4_amd64.deb)适用于适用于Debian10 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...
mongodb-driver-core 4.3.3版本
MongoDB window 安装包,mongodb-windows-x86_64-4.4.0-signed.msi,免除下载速度慢的烦恼!
mongodb-windows-x86_64-7.0.5-signed.msi 数据库构建工具
mongodb可视化管理mongodb-compass-1.43.0-win32-x64.exe mongodb compass官网下载地址:https://www.mongodb.com/try/download/compass mongodb相关下载地址: mongodb社区版:...
本文将详细解析"mongodb-linux-x86_64-4.0.8.tgz"这个压缩包文件及其核心内容,帮助读者深入了解MongoDB在Linux平台上的安装与使用。 首先,"mongodb-linux-x86_64-4.0.8.tgz"是一个专为Linux 64位系统设计的...
mongodb-async-driver-2.0.1驱动文件 jar MongoDB Async Java Driver Documentation Welcome to the MongoDB Async Java driver documentation hub. Getting Started The Getting Started guide contains ...
这个“mongodb-linux-x86_64-rhel62-4.0.0.tgz”文件是专门为基于Red Hat Enterprise Linux 6.2 (RHEL62)的64位Linux系统设计的MongoDB 4.0.0版本的安装包。MongoDB 4.0是一个重要的版本,因为它引入了许多新特性和...
mongodb-driver-3.4.3,mongodb java开发中常用组件。
mongodb-linux-x86_64-rhel70-4.2.7.tgz