码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB分片实战

时间:2019-04-16 14:46:48      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:create   wal   zone   radmin   ber   append   position   sha   mongodb分片   

准备目录

/home/mongodb/shard/s0
/home/mongodb/shard/s1
/home/mongodb/config0
/home/mongodb/config1
/home/mongodb/log

 启动shard

/usr/local/mongodb/bin/mongod --port 3000 --dbpath=/home/mongodb/shard/s0 --logpath=/home/mongodb/log/s0.log --logappend --fork --shardsvr
/usr/local/mongodb/bin/mongod --port 3001 --dbpath=/home/mongodb/shard/s1 --logpath=/home/mongodb/log/s1.log --logappend --fork --shardsvr

 启动config

/usr/local/mongodb/bin/mongod --port 3999 --dbpath=/home/mongodb/config/c0 --logpath=/home/mongodb/log/config0.log --logappend --fork --configsvr --replSet=config
/usr/local/mongodb/bin/mongod --port 39990 --dbpath=/home/mongodb/config/c1 --logpath=/home/mongodb/log/config1.log --logappend --fork --configsvr --replSet=config

 复制集conf配置

/usr/local/mongodb/bin/mongo localhost:3999
rs.initiate({_id: ‘config‘, members: [{_id: 0, host: ‘localhost:3999‘}, {_id: 1, host: ‘localhost:39990‘}]})
rs.isMaster() #查看主从关系

 创建Route

/usr/local/mongodb/bin/mongos --port 40000 --bind_ip 0.0.0.0 --configdb config/localhost:3999,localhost:39990 --logpath=/home/mongodb/log/route.log --fork --logappend

 设置分片

/usr/local/mongodb/bin/mongo admin --port 40000
use admin
db.runCommand({ addshard: ‘localhost:3000‘})
db.runCommand({ addshard: ‘localhost:3001‘})
db.runCommand({ enablesharding: ‘ship_position‘})
db.runCommand({ shardcollection: ‘ship_position.ais‘, key: {receiveTimeLong: 1}})
db.runCommand({ shardcollection: ‘ship_position.gps‘, key: {receiveTimeLong: 1}})
db.runCommand({ shardcollection: ‘ship_position.rfid‘, key: {receiveTimeLong: 1}})

 创建用户

use admin
db.createUser(
   {
     user: "root",
     pwd: "QWERpoiu1234",
     roles:
       [
         { role: "readWrite", db: "config" },
         "clusterAdmin"
       ]
   }
)

 打开端口

firewall-cmd --zone=public --add-port=40000/tcp --permanent

 


 

第二次启动服务

/usr/local/mongodb/bin/mongod --port 3000 --dbpath=/home/mongodb/shard/s0 --logpath=/home/mongodb/log/s0.log --logappend --fork --shardsvr
/usr/local/mongodb/bin/mongod --port 3001 --dbpath=/home/mongodb/shard/s1 --logpath=/home/mongodb/log/s1.log --logappend --fork --shardsvr
/usr/local/mongodb/bin/mongod --port 3999 --dbpath=/home/mongodb/config/c0 --logpath=/home/mongodb/log/config0.log --logappend --fork --configsvr --replSet=config
/usr/local/mongodb/bin/mongod --port 39990 --dbpath=/home/mongodb/config/c1 --logpath=/home/mongodb/log/config1.log --logappend --fork --configsvr --replSet=config
/usr/local/mongodb/bin/mongos --port 40000 --bind_ip 0.0.0.0 --configdb config/localhost:3999,localhost:39990 --logpath=/home/mongodb/log/route.log --fork --logappend

 

MongoDB分片实战

标签:create   wal   zone   radmin   ber   append   position   sha   mongodb分片   

原文地址:https://www.cnblogs.com/song-wentao/p/10716571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!