MongoDB2.0路由集群配置

 

 

 

参考

http://www.javabloger.com/article/mongodb-cluster.html

 


MongoDB2.0路由集群配置

我们实验有shard1,shard2,configserver,mongosRoute 

 

 

Shard1启动脚本
mkdir  database\shared1 

title: MongoDB shared1  Start by xiaofancn

cls
REM shard1服务端口是8001
bin\mongod.exe --shardsvr --dbpath database\shared1 --port 8001 --rest
 

 

 

Shard2启动脚本
mkdir  database\shared2 

title: MongoDB shared2 Start by xiaofancn

cls
REM shard2服务端口是8002
bin\mongod.exe --shardsvr --dbpath database\shared2 --port 8002 --rest

 

 

configServer启动脚本
mkdir  database\config 

title: MongoDB Config Start by xiaofancn

Cls
REM configServer服务端口是8000
bin\mongod.exe --configsvr --dbpath database\config --port 8000 --rest

 

 

mongoDB路由器启动脚本。
title: MongoDB Route Start by xiaofancn
REM 路由器连接configServer
bin\mongos --configdb localhost:8000

 

配置自动分片(Auto-sharding)

 

 

D:\Program Files\mongodb>bin\mongo
MongoDB shell version: 2.0.0
connecting to: test
mongos> use admin
switched to db admin
mongos> db.runCommand({addshard:"localhost:8001"});
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> db.runCommand({addshard:"localhost:8002"});
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> db.runCommand({enableSharding:"test"});
{ "ok" : 1 }
mongos> db.runCommand({shardcollection:"test.person",key:{_id:1}});
{ "collectionsharded" : "test.person", "ok" : 1 }
mongos> db.runCommand({listshards:1})
{
        "shards" : [
                {
                        "_id" : "shard0000",
                        "host" : "localhost:8001"
                },
                {
                        "_id" : "shard0001",
                        "host" : "localhost:8002"
                }
        ],
        "ok" : 1
}

 

 

 

 

    扩展          shard节点的master/slave配置

 

 

mkdir  database\shared3 

title: MongoDB shared3 Start by xiaofancn

cls
rem 默认
bin\mongod.exe --shardsvr --master --dbpath database\shared3 --port 8003 --rest

 

 

mkdir  database\shared3Slave 

title: MongoDB shared3 Start by xiaofancn

cls
rem 默认
bin\mongod.exe --slave --source localhost:8003 --dbpath database\shared3Slave --rest

你可能感兴趣的:(mongodb)