2011/9/16 制作人:酷酷   http://weibo.com/lidaohangMongo 之架构部署 (Replica Sets+Sharding)1、环境要构建一个 MongoDB Sharding Cluster,需要三种角色:...
2011/9/16 制作人:酷酷       http://weibo.com/lidaohangS1: 10.168.0.103,10.168.0.107,10.168.0.109,10.168.0.108(arbiter)S2: 10.16...
2011/9/16 制作人:酷酷       http://weibo.com/lidaohang tar zxvf mongodb-linux-x86_64-2.0.0.tgz3.重命名 mongodb-linux-x86_64-2.0.0....
2011/9/16 制作人:酷酷       http://weibo.com/lidaohang4.初始化 replica sets/testadmin/mongodb/bin/mongo --port 27017              ...
2011/9/16 制作人:酷酷       http://weibo.com/lidaohangps aux | grep mongodb | grep -v grep4.初始化 replica sets/testadmin/mongodb/...
2011/9/16 制作人:酷酷       http://weibo.com/lidaohang--dbpath                                               /home/testadmin/mo...
2011/9/16 制作人:酷酷       http://weibo.com/lidaohanglogpath/home/testadmin/mongodb/logs/shard3/log.log --logappend --replSet ...
2011/9/16 制作人:酷酷      http://weibo.com/lidaohangdb.runCommand({ listshards:1 })db.runCommand({                enableshardi...
2011/9/16 制作人:酷酷   http://weibo.com/lidaohang4、鸭梨大了怎么办?添加服务器,怎么样添加呢?添加 slave 节点1、利用另外一台 secondary 机器传送数据2、在新机器上中配置文件中添加 fa...
Upcoming SlideShare
Loading in...5
×

Mongo db部署架构之优先方案

1,025

Published on

MongoDB Sharding+Replica Set

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,025
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mongo db部署架构之优先方案

  1. 1. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohangMongo 之架构部署 (Replica Sets+Sharding)1、环境要构建一个 MongoDB Sharding Cluster,需要三种角色:•Shard Server: mongod 实例,用于存储实际的数据块。•Config Server: mongod 实例,存储了整个 Cluster Metadata,其中包括 chunk 信息。•Route Server: mongos 实例,前端路由,客户端由此接入,且让整个集群看上去像单一进程数据库。10.168.0.103 10.168.0.107 10.168.0.108 10.168.0.109Shard1 Shard2 Shard3 Shard1Shard2 Shard1 Shard2 Shard3Shard3 Shard3 Shard1 Shard21.节点:2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  2. 2. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohangS1: 10.168.0.103,10.168.0.107,10.168.0.109,10.168.0.108(arbiter)S2: 10.168.0.107,10.168.0.103,10.168.0.108,10.168.0.109(arbiter)S3: 10.168.0.108,10.168.0.103,10.168.0.109,10.168.0.107(arbiter)主机 端口信息10.168.0.103 mongod shard1:27017 mongod shard2:27018 mongod shard3:27019 mongod config:30000 mongs:4000010.168.0.107 mongod shard1:27017 mongod shard2:27018 mongod shard3:27019 mongod config:30000 mongs:4000010.168.0.108 mongod shard1:27017 mongod shard2:27018 mongod shard3:27019 mongod config:30000 mongs:4000010.168.0.109 mongod shard1:27017 mongod shard2:27018 mongod shard3:27019 mongod config:30000 mongs:400002、安装部署软件准备及目录1.下载 mongodb 程序 curl -O http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.0.tgz2.解压 mongodb-linux-x86_64-2.0.0.tgz2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  3. 3. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohang tar zxvf mongodb-linux-x86_64-2.0.0.tgz3.重命名 mongodb-linux-x86_64-2.0.0.tgz 为 mongodb mv mongodb-linux-x86_64-2.0.0 mongodb4.进入 mongodb 目录 cd mongodb5.新建文件夹 data mkdir data配置 Replica Sets,Config Server10.168.0.1031.创建相应的文件夹(注意此处的 testadmin 是客户端登陆名)mkdir -p /home/testadmin/mongodb/data/shard1mkdir -p /home/testadmin/mongodb/data/shard2mkdir -p /home/testadmin/mongodb/data/shard3mkdir -p /home/testadmin/mongodb/data/configmkdir -p /home/testadmin/mongodb/logs/shard1mkdir -p /home/testadmin/mongodb/logs/shard2mkdir -p /home/testadmin/mongodb/logs/shard3mkdir -p /home/testadmin/mongodb/logs/configmkdir -p /home/testadmin/mongodb/logs/mongos2.配置 mongod/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27017 --dbpath/home/testadmin/mongodb/data/shard1/--logpath/home/testadmin/mongodb/logs/shard1/log.log--logappend --replSet s1 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27018--dbpath /home/testadmin/mongodb/data/shard2/--logpath/home/testadmin/mongodb/logs/shard2/log.log --logappend --replSet s2 --auth --rest/testadmin/mongodb/bin/mongod--fork--shardsvr--port 27019--dbpath /home/testadmin/mongodb/data/shard3/--logpath/home/testadmin/mongodb/logs/shard3/log.log --logappend --replSet s3 --auth --rest/testadmin/mongodb/bin/mongod --fork --configsvr --port 30000--dbpath /home/testadmin/mongodb/data/config/--logpath/home/testadmin/mongodb/logs/config/log.log --logappend --auth --rest3.查看 mongod 的进程是否启动ps aux | grep mongodb | grep -v grep2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  4. 4. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohang4.初始化 replica sets/testadmin/mongodb/bin/mongo --port 27017 config = {_id: s1, members: [ {_id: 0, host: 10.168.0.103:27017}, {_id: 1, host: 10.168.0.107:27017}, {_id: 2, host: 10.168.0.109:27017}, {_id: 3, host: 10.168.0.108:27017, arbiterOnly: true} ]} rs.initiate(config) rs.status()10.168.0.1071.创建相应的文件夹(注意此处的 testadmin 是客户端登陆名)mkdir -p /home/testadmin/mongodb/data/shard1mkdir -p /home/testadmin/mongodb/data/shard2mkdir -p /home/testadmin/mongodb/data/shard3mkdir -p /home/testadmin/mongodb/data/configmkdir -p /home/testadmin/mongodb/logs/shard1mkdir -p /home/testadmin/mongodb/logs/shard2mkdir -p /home/testadmin/mongodb/logs/shard3mkdir -p /home/testadmin/mongodb/logs/configmkdir -p /home/testadmin/mongodb/logs/mongos2.配置 mongod/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27017--dbpath /home/testadmin/mongodb/data/shard1/--logpath/home/testadmin/mongodb/logs/shard1/log.log --logappend --replSet s1 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27018--dbpath /home/testadmin/mongodb/data/shard2/--logpath/home/testadmin/mongodb/logs/shard2/log.log --logappend --replSet shard2 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27019--dbpath /home/testadmin/mongodb/data/shard3/--logpath/home/testadmin/mongodb/logs/shard3/log.log --logappend --replSet s3 --auth --rest/testadmin/mongodb/bin/mongod --fork --configsvr --port 30000--dbpath /home/testadmin/mongodb/data/config/--logpath/home/testadmin/mongodb/logs/config/log.log --logappend --auth --rest3.查看 mongod 的进程是否启动2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  5. 5. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohangps aux | grep mongodb | grep -v grep4.初始化 replica sets/testadmin/mongodb/bin/mongo --port 27018 config = {_id: s2, members: [ {_id: 0, host: 10.168.0.107:27018}, {_id: 1, host: 10.168.0.103:27018}, {_id: 1, host: 10.168.0.108:27018}, {_id: 2, host: 10.168.0.109:27018, arbiterOnly: true} ]} rs.initiate(config) rs.status()10.168.0.1081.创建相应的文件夹(注意此处的 testadmin 是客户端登陆名)mkdir -p /home/testadmin/mongodb/data/shard1mkdir -p /home/testadmin/mongodb/data/shard2mkdir -p /home/testadmin/mongodb/data/shard3mkdir -p /home/testadmin/mongodb/data/configmkdir -p /home/testadmin/mongodb/logs/shard1mkdir -p /home/testadmin/mongodb/logs/shard2mkdir -p /home/testadmin/mongodb/logs/shard3mkdir -p /home/testadmin/mongodb/logs/configmkdir -p /home/testadmin/mongodb/logs/mongos2.配置 mongod/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27017--dbpath /home/testadmin/mongodb/data/shard1/--logpath/home/testadmin/mongodb/logs/shard1/log.log --logappend --replSet s1 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27018--dbpath /home/testadmin/mongodb/data/shard2/--logpath/home/testadmin/mongodb/logs/shard2/log.log --logappend --replSet shard2 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27019--dbpath /home/testadmin/mongodb/data/shard3/--logpath/home/testadmin/mongodb/logs/shard3/log.log --logappend --replSet s3 --auth --rest/testadmin/mongodb/bin/mongod --fork --configsvr --port 300002011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  6. 6. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohang--dbpath /home/testadmin/mongodb/data/config/--logpath/home/testadmin/mongodb/logs/config/log.log --logappend --auth --rest3.查看 mongod 的进程是否启动ps aux | grep mongodb | grep -v grep4.初始化 replica sets/testadmin/mongodb/bin/mongo --port 27018 config = {_id: s2, members: [ {_id: 0, host: 10.168.0.108:27019}, {_id: 1, host: 10.168.0.103:27019}, {_id: 1, host: 10.168.0.109:27019}, {_id: 2, host: 10.168.0.107:27019, arbiterOnly: true} ]} rs.initiate(config) rs.status()10.168.0.1091.创建相应的文件夹(注意此处的 testadmin 是客户端登陆名)mkdir -p /home/testadmin/mongodb/data/shard1mkdir -p /home/testadmin/mongodb/data/shard2mkdir -p /home/testadmin/mongodb/data/shard3mkdir -p /home/testadmin/mongodb/data/configmkdir -p /home/testadmin/mongodb/logs/shard1mkdir -p /home/testadmin/mongodb/logs/shard2mkdir -p /home/testadmin/mongodb/logs/shard3mkdir -p /home/testadmin/mongodb/logs/configmkdir -p /home/testadmin/mongodb/logs/mongos2.配置 mongod/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27017--dbpath /home/testadmin/mongodb/data/shard1/--logpath/home/testadmin/mongodb/logs/shard1/log.log --logappend --replSet s1 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27018--dbpath /home/testadmin/mongodb/data/shard2/--logpath/home/testadmin/mongodb/logs/shard2/log.log --logappend --replSet shard2 --auth --rest/testadmin/mongodb/bin/mongod --fork --shardsvr --port 27019--dbpath /home/testadmin/mongodb/data/shard3/--2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  7. 7. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohanglogpath/home/testadmin/mongodb/logs/shard3/log.log --logappend --replSet s3 --auth --rest/testadmin/mongodb/bin/mongod --fork --configsvr --port 30000--dbpath /home/testadmin/mongodb/data/config/--logpath/home/testadmin/mongodb/logs/config/log.log --logappend --auth --rest3.查看 mongod 的进程是否启动ps aux | grep mongodb | grep -v grep配置 Mongos(在每一台机子上建立路由)/testadmin/mongodb/bin/mongos --fork --port 40000--logpath/home/testadmin/logs/mongos/log.log --configdb10.168.0.103:30000,10.168.0.107:30000,10.168.0.108:30000,10.168.0.109添加分片1 连接任意一台,其他无需这样操作:/home/testadmin/bin/mongo --port 40000use admindb.runCommand({addshard:s1/10.168.0.103:27017,10.168.0.107:27017,10.168.0.109:27017})db.runCommand({addshard:s2/10.168.0.107:27018,10.168.0.103:27018,10.168.0.108:27018 })db.runCommand({addshard:s3/10.168.0.108:27019,10.168.0.103:27017,10.168.0.109:27019 })2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  8. 8. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohangdb.runCommand({ listshards:1 })db.runCommand({ enablesharding:weibo })db.runCommand({ shardcollection:weibo.test, key:{_id:1} , unique : true })printShardingStatus()db.data.stats();3、用户认证1.注意 1.9.1 之前复制集不支持用户认证,只能通过 keyFile 密匙文件,幸好这几天 2.0 正式版出来了,很多功能问题都已解决。呵呵注意:用户验证,启动 mongod 必须添加--auth#设置用户名和密码>use test>db.addUser(mongo,456123);>db.auth(mongo,456123)>db.system.users.find() --查看该用户是否添加成功>db.system.users.remove(mongo,456123)>mongo 数据库 -u mongo -p注意:启动时必须添加--auth 用户权限才会生效,第一次配置完成后,没效果就重启下。2011/9/16 制作人:酷酷 http://weibo.com/lidaohang
  9. 9. 2011/9/16 制作人:酷酷 http://weibo.com/lidaohang4、鸭梨大了怎么办?添加服务器,怎么样添加呢?添加 slave 节点1、利用另外一台 secondary 机器传送数据2、在新机器上中配置文件中添加 fastsync=true 配置(当需要从有数据中启动节点,那么必须加上 fastsync=true ,否则启动会报错,如果是从主库直接同步所有数据,那么就不需要添加这个参数)3、启动后,在 primary 节点中添加节点如:rs.add("10.73.24.171:9005") 当我们看到变为 secondary 后,就一切正常,可以正常提供线上服务了4、通过 rs.conf()命令查看现在的节点信息(需要 admin 库密码权限)5、rs.remove()删除节点6、添加 arbiter 节点:rs.addArb("10.73.24.171:19003")7、添加延时备份机器:rs.add({_id:4,host:"10.55.22.176:9004",priority:0,slaveDelay:3600});8、当出现这个错误时:replSet error RS102 too stale to catch up,我们可以db.printReplicationInfo()查看主库、从库的 oplog 信息;添加 sharding 节点1.重复上面的操作添加 sharding2011/9/16 制作人:酷酷 http://weibo.com/lidaohang

×