MongoDB的分片测试

分片结构端口分布如下:
Shard Server 1:27020
Shard Server 2:27021
Shard Server 3:27022
Shard Server 4:27023
Config Server :27100
Route Process:40000

1.正确安装MongoDb

http://blog.youkuaiyun.com/u013298318/article/details/52248478

2.启动Shard Server

[root@100 /]# mkdir -p /www/mongoDB/shard/s0
[root@100 /]# mkdir -p /www/mongoDB/shard/s1
[root@100 /]# mkdir -p /www/mongoDB/shard/s2
[root@100 /]# mkdir -p /www/mongoDB/shard/s3
[root@100 /]# mkdir -p /www/mongoDB/shard/log
[root@100 /]# /usr/local/mongoDB/bin/mongod —shardsvr --port 27020 --dbpath=/www/mongoDB/shard/s0 --logpath=/www/mongoDB/shard/log/s0.log --logappend --fork
[root@100 /]#  /usr/local/mongoDB/bin/mongod —shardsvr --port 27021 --dbpath=/www/mongoDB/shard/s1 --logpath=/www/mongoDB/shard/log/s1.log --logappend --fork

[root@100 /]#  /usr/local/mongoDB/bin/mongod —shardsvr --port 27022 --dbpath=/www/mongoDB/shard/s2 --logpath=/www/mongoDB/shard/log/s2.log --logappend --fork
[root@100 /]#  /usr/local/mongoDB/bin/mongod —shardsvr --port 27023 --dbpath=/www/mongoDB/shard/s3 --logpath=/www/mongoDB/shard/log/s3.log --logappend --fork


3.启动Config Server

[root@100 /]# mkdir -p /www/mongoDB/shard/config
[root@100 /]# /usr/local/mongoDB/bin/mongod --configsvr --port 27100 --dbpath=/www/mongoDB/shard/config --logpath=/www/mongoDB/shard/log/config.log --logappend --fork


4.启动Route Process

/usr/local/mongoDB/bin/mongos --port 40000 --configdb localhost:27100 --fork --logpath=/www/mongoDB/shard/log/route.log --chunkSize 500


5.配置Sharding

使用MongoDB Shell登录到mongos,添加Shard节点

[root@100 shard]# /usr/local/mongoDB/bin/mongo admin --port 40000
MongoDB shell version: 2.0.7
connecting to: 127.0.0.1:40000/admin
mongos> db.runCommand({ addshard:"localhost:27020" })
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> db.runCommand({ addshard:"localhost:27021" })
{ "shardAdded" : "shard0001", "ok" : 1 }

mongos> db.runCommand({ addshard:"localhost:27022" })
{ "shardAdded" : "shard0002", "ok" : 1 }
mongos> db.runCommand({ addshard:"localhost:27023" })
{ "shardAdded" : "shard0003", "ok" : 1 }
mongos> db.runCommand({ enablesharding:"shardtest" }) #设置分片存储的数据库
{ "ok" : 1 }
mongos> db.runCommand({ shardcollection: "shardtest.log", key: { id:1,time:1}})
{ "collectionsharded" : "shardtest.log", "ok" : 1 }

6.插入测试数据

for(i=0;i<10000;i++){db.shardtest.userid.insert({"user_id":i})}

7.查看分片状态

use config

db.shards.find()

use shardtest

db.userid.stats()

db.printShardStatus()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值