MongoDB Sharding 分片配置全过程记录

配置参数设置:

//sharding

Shard Server1 192.168.0.5:20000
    dbpath  /data/liumongodb/data/shard1/data/
    logpath dbpath  /data/liumongodb/data/shard1/data/log/log.log
Shard Server2 192.168.0.5:20001
    dbpath  /data/liumongodb/data/shard2/data/
    logpath dbpath  /data/liumongodb/data/shard2/data/log/log.log
Config Server 192.168.0.8:30000
    dbpath  /data/liumongodb/data/config/
    logpath  /data/liumongodb/data/config/log/log.log
Route Process 192.168.0.8:40000
    dbpath  /data/liumongodb/data/route/
    logpath  /data/liumongodb/data/route/log/log.log

 

2:对应配置文件

sharding1:

Shard Server1 192.168.0.5:20000

 /usr/local/mongodb2.2/bin/mongod -f /usr/local/mongodb2.2/config/shard1.conf 

#sharding 192.168.0.5 shard1.conf
logpath=/data/liumongodb/data/shard1/log/log.log
logappend=true
port = 20000
fork = true
dbpath=/data/liumongodb/data/shard1/data/
directoryperdb = true
rest = true
noauth = true
nohttpinterface = ture
shardsvr=true
quiet = true
maxConns = 100

 

 

 

sharding2:

Shard Server1 192.168.0.5:20001

 /usr/local/mongodb2.2/bin/mongod -f /usr/local/mongodb2.2/config/shard2.conf 

 

 

 

#sharding2 192.168.0.5 shard2.conf
logpath=/data/liumongodb/data/shard2/log/log.log
logappend=true
port = 20001                                        
fork = true
dbpath=/data/liumongodb/data/shard2/data/
directoryperdb = true
rest = true
noauth = true
nohttpinterface = ture
shardsvr=true
quiet = true
maxConns = 100

 

Config Server 192.168.0.8:30000
启动Config Server服务:

/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/config.conf

#Config Server 192.168.0.8
dbpath=/data/liumongodb/data/config/
logpath=/data/liumongodb/data/config/log/log.log
logappend=true
port = 30000 
fork = true
configsvr=true
directoryperdb=true

 

Route Process 192.168.0.8:40000

启动Route Process服务:

 /usr/local/mongodb/bin/mongos -f /usr/local/mongodb/conf/route.conf

#Route Server 192.168.0.8
logpath=/data/liumongodb/data/route/log/log.log
logappend=true
port = 40000 
fork = true
chunkSize=100
configdb=192.168.0.8:30000

 

 运行一下:

 

/usr/local/mongodb/bin/mongo --port 40000
MongoDB shell version: 2.2.0
connecting to: 127.0.0.1:40000/test
mongos> use admin
switched to db admin
mongos> db.runCommand({addshard:"192.168.0.5:20000"})
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> db.runCommand({addshard:"192.168.0.5:20001"})
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> db.runCommand({enablesharding:"gcproduct"})
{ "ok" : 1 }
mongos> db.runCommand({shardcollection:"gcproduct.gc_postsfield",key:{_id:1}})
{ "collectionsharded" : "gcproduct.gc_postsfield", "ok" : 1 }
mongos> exit
bye
You have mail in /var/spool/mail/root
[root@app conf]# /usr/local/mongodb/bin/mongo --port 40000
MongoDB shell version: 2.2.0
connecting to: 127.0.0.1:40000/test
mongos> exit
bye

 

做个备忘!!!

 

命令备忘:

use admin
db.runCommand({"listshards":1})
//开始分片
db.runCommand({"shardcollection":"test.tablename","key":{_id:1}})
//新增 Shard Server
db.runCommand({addshard:"localhost:20001")
//移除Shard Server
db.runCommand({removeshard:"localhost:20001")

 

posted @ 2012-11-20 16:55  Linux、Mongo、Php、Shell、Python、C  阅读(346)  评论(0)    收藏  举报