• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

MongoDB分片实战-小小程序员的梦想

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
使用quicklz缩小程序体积发布时间:2022-07-18
下一篇:
微信小程序picker中range-key的坑发布时间:2022-07-18
热门推荐
    热门话题
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap