话说在虚拟机中会报各种错误。在真实的环境中就不会那么痛苦了。

想了一下虚拟机中报错的原因有。

机器卡,处理的时间长就会抛出错误

还有虚拟机假设给的空间太小。也会报异常。

此处讲讲我的大致思路。

第一,选择三台server,最好不是虚拟的

第二,设计三台server的IP。port。和各自的角色

第三,检查防火墙有没有关闭,时间是不是同步

假设上面都能够了。那你就能够操作了。

当然,mongodb版本号和mongodb前提搭建就建在前面吧



wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.4.tgz

解压mongodb文件

主机1 版本不一样。我的是2.0.4

[root@mongodb40 ~]# tar zxvfmongodb-linux-x86_64-2.4.7.tgz

[root@mongodb40 ~]# mvmongodb-linux-x86_64-2.4.7 /home/mongodb

主机

[root@mongodb41~]# tar zxvfmongodb-linux-x86_64-2.4.7.tgz

[root@mongodb41~]# mvmongodb-linux-x86_64-2.4.7 /home/mongodb

主机

[root@mongodb250 ~]# tar zxvfmongodb-linux-x86_64-2.4.7.tgz

[root@mongodb250~]# mvmongodb-linux-x86_64-2.4.7 /home/mongodb

mongo集群分片实战

server三台

主机1(172.16.0.40)                主机2(172.16.0.41)                               主机3(172.16.0.250)

第一片(11731)                    主                                               副本                                                                             仲裁

第二片(11732)                 仲裁                                              主                                                                                 副本

第三片(11733)                    副本                                       仲裁                                                                                   主

30000                    configServer                                configServer                                                           config
Server

60000                          RouteProcess                        RouteProcess                                                        Route
Process

创建数据库文件夹

主机(172.16.0.40)配置文件

[root@mongodb115 ~]# mkdir -p/home/data/shard1_1

[root@mongodb115 ~]# mkdir -p/home/data/shard2_1

[root@mongodb115 ~]# mkdir -p/home/data/shard3_1

[root@mongodb115 ~]# mkdir -p/home/data/config                            #config
server文件夹

[root@mongodb115 ~]# mkdir -p/home/config                                       #放配置文件

[root@mongodb115 ~]# mkdir -p/home/data/logs

这个地方的全部配置文件夹都放在/home/config文件夹下,切记切记啊。由于我在这里吃过亏。不知一次。

分片

[root@mongodb40 config]# catshard1_1.conf

port=11731

dbpath=/home/data/shard1_1

logpath=/home/data/logs/shard1_1.log

directoryperdb=true

logappend=true

replSet=shard1

#bind_ip=172.16.0.40

shardsvr=true

fork=true

pidfilepath=/home/data/shard1_1.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb40 config]# catshard2_1.conf

port=11732

dbpath=/home/data/shard2_1

logpath=/home/data/logs/shard2_1.log

directoryperdb=true

logappend=true

replSet=shard2

#bind_ip=172.16.0.40

shardsvr=true

fork=true

pidfilepath=/home/data/shard2_1.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb40 config]# catshard3_1.conf

port=11733

dbpath=/home/data/shard3_1

logpath=/home/data/logs/shard3_1.log

directoryperdb=true

logappend=true

replSet=shard3

#bind_ip=172.16.0.40

shardsvr=true

fork=true

pidfilepath=/home/data/shard3_1.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

config server
配置文件

[root@mongodb40 config]# catconfig.conf

port=30000

dbpath=/home/data/config

logpath=/home/data/logs/config.log

directoryperdb=true

configsvr=true

logappend=true

#bind_ip=172.16.0.40

fork=true

pidfilepath=/home/data/config.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

RouteProces
配置文件

[root@mongodb40 config]# catmongos.conf

port=60000

logpath=/home/data/logs/mongos.log

logappend=true

configdb=172.16.0.40:30000,172.16.0.41:30000,172.16.0.250:30000

#bind_ip=172.16.0.40

fork=true

pidfilepath=/home/data/mongos.pid

chunkSize=5

maxConns=20000

nohttpinterface=true

主机(172.16.0.41)配置文件

[root@mongodb114 ~]# mkdir -p/home/data/shard1_2

[root@mongodb114 ~]# mkdir -p/home/data/shard2_2

[root@mongodb114 ~]# mkdir -p/home/data/shard3_2

[root@mongodb114 ~]# mkdir -p/home/data/config                      #config server文件夹

[root@mongodb114 ~]# mkdir -p/home/config          #放配置文件

[root@mongodb114 ~]# mkdir -p/home/data/logs

分片

[root@mongodb41 config]# catshard1_2.conf

port=11731

dbpath=/home/data/shard1_2

logpath=/home/data/logs/shard1_2.log

directoryperdb=true

logappend=true

replSet=shard1

#bind_ip=172.16.0.41

shardsvr=true

fork=true

pidfilepath=/home/data/shard1_2.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb41 config]# catshard2_2.conf

port=11732

dbpath=/home/data/shard2_2

logpath=/home/data/logs/shard2_2.log

directoryperdb=true

logappend=true

replSet=shard2

#bind_ip=172.16.0.41

shardsvr=true

fork=true

pidfilepath=/home/data/shard2_2.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb41 config]# catshard3_2.conf

port=11733

dbpath=/home/data/shard3_2

logpath=/home/data/logs/shard3_2.log

directoryperdb=true

logappend=true

replSet=shard3

#bind_ip=172.16.0.41

shardsvr=true

fork=true

pidfilepath=/home/data/shard3_2.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

config server
配置文件

[root@mongodb41 config]# catconfig.conf

port=30000

dbpath=/home/data/config

logpath=/home/data/logs/config.log

directoryperdb=true

configsvr=true

logappend=true

#bind_ip=172.16.0.41

fork=true

pidfilepath=/home/data/config.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

RouteProces
配置文件

[root@mongodb41 config]# catmongos.conf

port=60000

logpath=/home/data/logs/mongos.log

logappend=true

configdb=172.16.0.40:30000,172.16.0.41:30000,172.16.0.250:30000

#bind_ip=172.16.0.41

fork=true

pidfilepath=/home/data/mongos.pid

chunkSize=5

maxConns=20000

nohttpinterface=true

主机(172.16.0.250)配置文件

[root@mongodb103 ~]# mkdir -p/home/data/shard1_3

[root@mongodb103 ~]# mkdir -p/home/data/shard2_3

[root@mongodb103 ~]# mkdir -p/home/data/shard3_3

[root@mongodb103 ~]# mkdir -p/home/data/config                      #config server文件夹

[root@mongodb103 ~]# mkdir -p/home/config          #放配置文件

[root@mongodb103 ~]# mkdir -p/home/data/logs

分片

[root@mongodb250 config]# catshard1_3.conf

port=11731

dbpath=/home/data/shard1_3

logpath=/home/data/logs/shard1_3.log

directoryperdb=true

logappend=true

replSet=shard1

#bind_ip=172.16.0.250

shardsvr=true

fork=true

pidfilepath=/home/data/shard1_3.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb250 config]# catshard2_3.conf

port=11732

dbpath=/home/data/shard2_3

logpath=/home/data/logs/shard2_3.log

directoryperdb=true

logappend=true

replSet=shard2

#bind_ip=172.16.0.250

shardsvr=true

fork=true

pidfilepath=/home/data/shard2_3.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

分片

[root@mongodb250 config]# catshard3_3.conf

port=11733

dbpath=/home/data/shard3_3

logpath=/home/data/logs/shard3_3.log

directoryperdb=true

logappend=true

replSet=shard3

#bind_ip=172.16.0.250

shardsvr=true

fork=true

pidfilepath=/home/data/shard3_3.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

config server
配置文件

[root@mongodb250 config]# catconfig.conf

port=30000

dbpath=/home/data/config

logpath=/home/data/logs/config.log

directoryperdb=true

configsvr=true

logappend=true

#bind_ip=172.16.0.250

fork=true

pidfilepath=/home/data/config.pid

maxConns=20000

oplogSize=5000

noprealloc=true

nohttpinterface=true

RouteProces
配置文件

[root@mongodb250 config]# catmongos.conf

port=60000

logpath=/home/data/logs/mongos.log

logappend=true

configdb=172.16.0.40:30000,172.16.0.41:30000,172.16.0.250:30000

#bind_ip=172.16.0.250

fork=true

pidfilepath=/home/data/mongos.pid

chunkSize=5

maxConns=20000

nohttpinterface=true

启动shard1,shard2,shard3

主机

[root@mongodb115 ~]#/home/mongodb/bin/mongod -f /home/config/shard1_1.conf

[root@mongodb115 ~]#/home/mongodb/bin/mongod -f /home/config/shard2_1.conf

[root@mongodb115 ~]#/home/mongodb/bin/mongod -f /home/config/shard3_1.conf

主机

[root@mongodb114 ~]#/home/mongodb/bin/mongod -f /home/config/shard1_2.conf

[root@mongodb114 ~]#/home/mongodb/bin/mongod -f /home/config/shard2_2.conf

[root@mongodb114 ~]#/home/mongodb/bin/mongod -f /home/config/shard3_2.conf

主机

[root@mongodb103 ~]#/home/mongodb/bin/mongod -f /home/config/shard1_3.conf

[root@mongodb103 ~]#/home/mongodb/bin/mongod -f /home/config/shard2_3.conf

[root@mongodb103 ~]#/home/mongodb/bin/mongod -f /home/config/shard3_3.conf

配置ReplicaSets

配置分片1 在172.16.0.40上配置

[root@mongodb115 ~]# /home/mongodb/bin/mongo--port 11731

MongoDB shell version: 2.0.4

connecting to:127.0.0.1:11731/test

>config={_id:'shard1',members:[{_id:0,host:'172.16.0.40:11731',priority:2},{_id:1,host:'172.16.0.41:11731'},{_id:2,host:'172.16.0.250:11731',arbiterOnly:true}]}

rs.initiate(config)

配置分片2 在172.16.0.41上配置

[root@mongodb114 ~]# /home/mongodb/bin/mongo--port 11732

MongoDB shell version: 2.0.4

connecting to:127.0.0.1:11732/test

>config={_id:'shard2',members:[{_id:0,host:'172.16.0.40:11732',arbiterOnly:true},{_id:1,host:'172.16.0.41:11732',priority:2},{_id:2,host:'172.16.0.250:11732'}]}

rs.initiate(config)

配置分片3 在172.16.0.250上配置members里面的优先级priority值高的为主节点。对于仲裁点一定要加上arbiterOnly:true

[root@mongodb103 ~]# /home/mongodb/bin/mongo--port 11733

MongoDB shell version: 2.0.4

connecting to:127.0.0.1:11733/test

>config={_id:'shard3',members:[{_id:0,host:'172.16.0.40:11733'},{_id:1,host:'172.16.0.41:11733',arbiterOnly:true},{_id:2,host:'172.16.0.25:11733',priority:2}]}

rs.initiate(config)

启动台configserver

主机

[root@mongodb40 ~]#/home/mongodb/bin/mongod  -f/home/config/config.conf

主机

[root@mongodb41 ~]#/home/mongodb/bin/mongod  -f/home/config/config.conf

主机

[root@mongodb250 ~]#/home/mongodb/bin/mongod  -f/home/config/config.conf

启动台Route
Process

主机

[root@mongodb40 ~]# /home/mongodb/bin/mongos-f /home/config/mongos.conf

主机

[root@mongodb41 ~]# /home/mongodb/bin/mongos-f /home/config/mongos.conf

主机

[root@mongodb250 ~]#/home/mongodb/bin/mongos -f /home/config/mongos.conf

配置shardCluser

[root@mongodb115 ~]# /home/mongodb/bin/mongo--port 60000

MongoDB shell version: 2.0.4

connecting to:127.0.0.1:60000/test

mongos> use admin

switched to db admin

mongos>db.runCommand({addshard:"shard1/172.16.0.40:11731,172.16.0.41:11731, 172.16.0.250:11731"})

mongos>db.runCommand({addshard:"shard2/172.16.0.40:11732,172.16.0.41:11732, 172.16.0.250:11732"})

mongos>
db.runCommand({addshard:"shard3/172.16.0.40:11733,172.16.0.41:11733, 172.16.0.250:11733"})

接下来激活分片,如以下的代码所看到的:   採用hash分片

db.runCommand({enablesharding:"test"})

db.runCommand({shardcollection:"test.users",key:{id:"hashed"}})

上面这个会报错,我这边版本号不支持hashed分片,要把id:1

Replica Sets+Sharding方案之真枪实弹篇的更多相关文章

  1. MongoDB整理笔记のReplica Sets + Sharding

    MongoDB Auto-Sharding 解决了海量存储和动态扩容的问题,但离实际生产环境所需的高可靠.高可用还有些距离,所以有了"Replica Sets + Sharding" ...

  2. Mongo之架构部署(Replica Sets+Sharding)

    一.环境 要构建一个 MongoDB Sharding Cluster,需要三种角色: •Shard Server: mongod 实例,用于存储实际的数据块. •Config Server: mon ...

  3. 利用Mongodb的复制集搭建高可用分片,Replica Sets + Sharding的搭建过程

    参考资料 reference:  http://mongodb.blog.51cto.com/1071559/740131  http://docs.mongodb.org/manual/tutori ...

  4. MongoDB高可用架构:Replica Sets+Sharding

    MongoDB的sharding解决了海量存储和动态扩容的问题.但是遇到单点故障就显得无能为力了.MongoDB的副本集可以很好的解决单点故障的问题.所以就有了Sharding+Replica Set ...

  5. Mongodb集群搭建之 Sharding+ Replica Sets集群架构

    1.本例使用1台Linux主机,通过Docker 启动三个容器 IP地址如下: docker run -d -v `pwd`/data/master:/mongodb -p 27017:27017 d ...

  6. 转 Warning:MongoDB Replica Sets配置注意事项

    我们知道,MongoDB不提供单机的数据安全性,取而代之的是提供了Replica Sets的高可用方案.官方文档中提到的案例是三个节点组成的Replica Sets,这样在其中任何一个节点宕机后都会自 ...

  7. 管理维护Replica Sets

    1.读写分离 有一些第三方的工具,提供了一些可以让数据库进行读写分离的工具.我们现在是否有一个疑问,从库要是能进行查询就更好了,这样可以分担主库的大量的查询请求. 1. 先向主库中插入一条测试数据 2 ...

  8. 部署Replica Sets及查看相关配置

    MongoDB 支持在多个机器中通过异步复制达到故障转移和实现冗余.多机器中同一时刻只有一台是用于写操作.正是由于这个情况,为MongoDB 提供了数据一致性的保障.担当Primary 角色的机器能把 ...

  9. MongoDB整理笔记のReplica Sets

    MongoDB支持在多个机器中通过异步复制达到故障转移和实现冗余.多机器中同一时刻只有一台机器是用于写操作,正因为如此,MongoDB提供了数据一致性的保障.而担当primary角色的机器,可以把读的 ...

随机推荐

  1. 09CSS高级定位

    CSS高级定位 定位方式——position position:static|absolute|relative static表示为静态定位,是默认设置.  absolute表示绝对定位,与下位置属 ...

  2. Danfoss Motor - Automotive Motor: What Sensors Are There?

    The   Danfoss Motor     states that the motor sensor control system is the heart of the entire autom ...

  3. DHCP和PXE

    继续学习,Let's go!DHCP和PXE都是什么呢?如果非科班出身,可能一脸懵逼,好多东西需要去学习了,真的,继续学吧,付出不一定会有回报,不付出肯定就是等死了,呵呵! 一.DHCP 真正需要手动 ...

  4. C++11新特性之final override标识符

    final: final修饰符可用于修饰类,放在类名后面,被final修饰符修饰的类不能被继承.示例代码: // 正确的示范 #include <iostream> class A { p ...

  5. MySQL 日志初探

    目录 MySQL 日志初探 零.概述 一.Error Log(错误日志) 二.General Query Log(通用查询日志) 三.Slow Query Log (慢查询日志) 四.Binary L ...

  6. Python之面向对象继承和派生

    Python之面向对象继承和派生 什么是继承: 继承是一种创建新的类的方法.在Python中,新建的类可以继承自一个或多个父类.原始类称为基类或超类. 新建的类称为派生类或子类. Python中类的继 ...

  7. 89-Relative Vigor Index 相对活力指数指标.(2015.7.4)

    Relative Vigor Index 相对活力指数指标 ~计算: RVI = (CLOSE-OPEN)/(HIGH-LOW) RVIsig=SMA(RVI,N) ~思想: 牛市中,收盘>开盘 ...

  8. 集训第六周 古典概型 期望 D题 Discovering Gold 期望

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  9. JavaEE JDBC 可滚动和可更新的结果集ResultSet

    可滚动和可更新的结果集ResultSet @author ixenos 需求背景 1.对于一个只需要分析数据的程序来说,普通的ResultSet已够用 2.但如果ResultSet用于显示一张表或查询 ...

  10. Android二级缓存之物理存储介质上的缓存DiskLruCache

     Android二级缓存之物理存储介质上的缓存DiskLruCache Android DiskLruCache属于物理性质的缓存,相较于LruCache缓存,则DiskLruCache属于And ...