mongodb分片

分片
mongos把分片的mongod管理起来
何时分片
单个节点磁盘不足
单个mongod不能满足写数据的性能要求
将大量数据放到内存中提高性能
什么是片键
选择递增(分布不均匀,查询比较好)还是随机片键
片键对操作和性能的影响
实施分片
启动配置服务器
启动mongos
添加mongod实例
对数据库启用分片
对集合进行分片
[root@localhost ~]# cd /var/lib/mongod
bash: cd: /var/lib/mongod: No such file or directory
[root@localhost ~]# cd /var/lib/mongo
[root@localhost mongo]# cd dbs
[root@localhost dbs]# mkdir config
[root@localhost dbs]# cd config
[root@localhost config]# pwd
/var/lib/mongo/dbs/config
[root@localhost config]# mongod --dbpath /var/lib/mongo/dbs/config --port 20000
mongos --port 30000 --configdb localhost:20000
[root@localhost ~]# ps -ef |grep mong
root      3350  3108  1 20:37 pts/3    00:00:04 mongod --dbpath /var/lib/mongo/dbs/config --port 20000
root      3399  3387  0 20:43 pts/1    00:00:00 mongos --port 30000 --configdb localhost:20000
[root@localhost ~]# cd /var/lib/mongo/dbs
[root@localhost dbs]# mkdir shard1
[root@localhost dbs]# ls
config  master  shard1  slave
[root@localhost dbs]# mongod --dbpath /var/lib/mongo/dbs/shard1 --port 10000 --nojournal
[root@localhost ~]# mongo localhost:30000/admin
MongoDB shell version: 2.6.11
connecting to: localhost:30000/admin
mongos>
db.runCommand({addshard:"localhost",allowLocal:true})

mongos> db.runCommand({addshard:"localhost",allowLocal:true})
{
    "ok" : 0,
    "errmsg" : "couldn't connect to new shard socket exception [CONNECT_ERROR] for localhost:27017"
}
mongos> db.runCommand({enablesharding:"foo"})数据库foo
db.runCommand({"sharecollection":"foo.bar","key":{"_id":1}})库foo下面的bar

查看所有的片
useconfig
db.shards.find();
db.databases.find();
chunks集合
db.chunks.find();
删除片
db.runCommand({"removeshard":"localhost:10000"});

转载于:https://my.oschina.net/goudingcheng/blog/608334

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值