小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Mongodb集群配置(sharding with replica set)

 昵稱597197 2011-09-20
 

長(zhǎng)期以來(lái)我就對(duì)分布式系統(tǒng)原理與實(shí)踐非常感興趣,對(duì)于Mongodb我一直很好奇,最近終于有時(shí)間能動(dòng)手實(shí)驗(yàn)一把!

我在一臺(tái)Windows機(jī)器下搭建了一個(gè) Replica Sets + Sharding 測(cè)試集群環(huán)境,以此作為我后續(xù)對(duì)于Mongodb更進(jìn)一步學(xué)習(xí)的實(shí)驗(yàn)平臺(tái)。

只有一臺(tái)windows機(jī)器,配置方案:
1、3個(gè)分片sharding
2、每一個(gè)分片由3個(gè)節(jié)點(diǎn)構(gòu)成1主2備的Replica Sets
3、3個(gè)配置節(jié)點(diǎn)Configsever
4、1個(gè)路由節(jié)點(diǎn)Mongos

分片復(fù)制集A(三個(gè)分片節(jié)點(diǎn)構(gòu)成一個(gè)復(fù)制集):

127.0.0.1:10000   127.0.0.1:10001  127.0.0.1:10002

分片復(fù)制集B(三個(gè)分片節(jié)點(diǎn)構(gòu)成一個(gè)復(fù)制集):

127.0.0.1:20000   127.0.0.1:20001  127.0.0.1:20002 

分片復(fù)制集C(三個(gè)分片節(jié)點(diǎn)構(gòu)成一個(gè)復(fù)制集):

127.0.0.1:30000   127.0.0.1:30001  127.0.0.1:30002

Configsvc(三個(gè)配置服務(wù)器節(jié)點(diǎn)):

127.0.0.1:40000   127.0.0.1:40001  127.0.0.1:4002

mongos(一個(gè)路由節(jié)點(diǎn)):

127.0.0.1:50000

詳細(xì)操作步驟如下:

(1)下載mongodb-win32-i386-1.8.0

下載mongodb-win32-i386-1.8.0版本的Mongodb,放置在d:/mongodb-win32-i386-1.8.0目錄下。

(2)創(chuàng)建數(shù)據(jù)和日志文件目錄

進(jìn)入d:/mongodb-win32-i386-1.8.0目錄下創(chuàng)建如下目錄

創(chuàng)建數(shù)據(jù)文件目錄:

data/a/r0
data/a/r1
data/a/r2
data/b/r0
data/b/r1
data/b/r2
data/c/r0
data/c/r1
data/c/r2
data/configsvr/r0
data/configsvr/r1
data/configsvr/r2

創(chuàng)建日志文件目錄:

logs/a
logs/b
logs/c
logs/configsvr

(3)創(chuàng)建分片和復(fù)制集

配置第一組:

從命令行進(jìn)入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執(zhí)行如下命令!

mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/a/r0.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/a/r0 --port 10000 --shardsvr --replSet setA --rest  --oplogSize 64
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/a/r1.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/a/r1 --port 10001 --shardsvr --replSet setA --rest  --oplogSize 64
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/a/r2.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/a/r2 --port 10002 --shardsvr --replSet setA --rest  --oplogSize 64

啟動(dòng)上述分片節(jié)點(diǎn)之后,再使用mongo的命令行來(lái)初始化復(fù)制集

D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:10000/admin
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:10000/admin
> config={_id: 'setA', members:[{_id: 0,host:'127.0.0.1:10000'},{_id:1,host:'127.0.0.1:10001'},{_id:2,host:'
127.0.0.1:10002'}]}
{
        "_id" : "setA",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "127.0.0.1:10000"
                },
                {
                        "_id" : 1,
                        "host" : "127.0.0.1:10001"
                },
                {
                        "_id" : 2,
                        "host" : "127.0.0.1:10002"
                }
        ]
}
setA> rs.initiate(config);

配置第二組:

從命令行進(jìn)入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執(zhí)行如下命令!

mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/b/r0.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/b/r0 --port 20000 --shardsvr --replSet setB --rest  --oplogSize 64 
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/b/r1.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/b/r1 --port 20001 --shardsvr --replSet setB --rest  --oplogSize 64
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/b/r2.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/b/r2 --port 20002 --shardsvr --replSet setB --rest  --oplogSize 64

啟動(dòng)上述分片節(jié)點(diǎn)之后,再使用mongo的命令行來(lái)初始化復(fù)制集

D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:20000/admin
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:20000/admin
> config={_id: 'setB', members:[{_id: 0,host:'127.0.0.1:20000'},{_id:1,host:'127.0.0.1:20001'},{_id:2,host:'
127.0.0.1:20002'}]}
{
        "_id" : "setB",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "127.0.0.1:20000"
                },
                {
                        "_id" : 1,
                        "host" : "127.0.0.1:20001"
                },
                {
                        "_id" : 2,
                        "host" : "127.0.0.1:20002"
                }
        ]
}
> rs.initiate(config);

配置第三組:

從命令行進(jìn)入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執(zhí)行如下命令!
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/c/r0.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/c/r0 --port 30000 --shardsvr --replSet setC --rest  --oplogSize 64 
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/c/r1.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/c/r1 --port 30001 --shardsvr --replSet setC --rest  --oplogSize 64
mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/c/r2.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/c/r2 --port 30002 --shardsvr --replSet setC --rest  --oplogSize 64
D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:30000/admin
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:30000/admin
> config={_id: 'setC', members:[{_id: 0,host:'127.0.0.1:30000'},{_id:1,host:'127.0.0.1:30001'},{_id:2,host:'
127.0.0.1:30002'}]}
{
        "_id" : "setC",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "127.0.0.1:30000"
                },
                {
                        "_id" : 1,
                        "host" : "127.0.0.1:30001"
                },
                {
                        "_id" : 2,
                        "host" : "127.0.0.1:30002"
                }
        ]
}
> rs.initiate(config);

(4)啟動(dòng)三個(gè)配置服務(wù)節(jié)點(diǎn)Configsvr

從命令行分別執(zhí)行如下命令,配置三個(gè)Configsvr

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --configsvr --logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r0.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/configsvr/r0 --port 40000 --shardsvr

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --configsvr --logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r1.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/configsvr/r1 --port 40001 --shardsvr

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --configsvr --logpath d:/mongodb-win32-i386-1.8.0/logs/configsvr/r2.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/configsvr/r2 --port 40002 --shardsvr

(5)啟動(dòng)一個(gè)路由節(jié)點(diǎn)mongos

cd d:/mongodb-win32-i386-1.8.0/bin
call mongos.exe --configdb 127.0.0.1:40000,127.0.0.1:40001,127.0.0.1:40002 --logpath d:/mongodb-win32-i386-1.8.0/logs/mongos.log --logappend --port 50000

(6)配置分片

D:/mongodb-win32-i386-1.8.0/cmd>cd d:/mongodb-win32-i386-1.8.0/bin
D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:50000
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:50000/test
> use admin
switched to db admin
> db.runCommand({addshard:"setA/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002",name:"ShardSetA"})
{ "shardAdded" : "ShardSetA", "ok" : 1 }
> db.runCommand({addshard:"setB/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002",name:"ShardSetB"})
{ "shardAdded" : "ShardSetB", "ok" : 1 }
> db.runCommand({addshard:"setC/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002",name:"ShardSetC"})
{ "shardAdded" : "ShardSetC", "ok" : 1 }
> printShardingStatus()
--- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      {
        "_id" : "ShardSetA",
        "host" : "setA/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002"
}
      {
        "_id" : "ShardSetB",
        "host" : "setB/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002"
}
      {
        "_id" : "ShardSetC",
        "host" : "setC/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
}
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }

配置到這里,集群搭建完畢了!

在完成了集群的搭建工作之后,需要做的就是建立一個(gè)數(shù)據(jù)庫(kù),建立表,設(shè)置分片主鍵來(lái)初始化數(shù)據(jù)了!

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多