Mongodb Windows 叢集

來源:互聯網
上載者:User

標籤:使用   os   io   strong   檔案   資料   ar   art   

我在一台Windows機器下搭建了一個 Replica Sets + Sharding 測試叢集環境,以此作為我後續對於Mongodb更進一步學習的實驗平台。

只有一台windows機器,配置方案:
1、3個分區sharding
2、每一個分區由3個節點構成1主2備的Replica Sets
3、3個配置節點Configsever
4、1個路由節點Mongos

分區複製集A(三個分區節點構成一個複製集):

127.0.0.1:10000   127.0.0.1:10001  127.0.0.1:10002

分區複製集B(三個分區節點構成一個複製集):

127.0.0.1:20000   127.0.0.1:20001  127.0.0.1:20002 

分區複製集C(三個分區節點構成一個複製集):

127.0.0.1:30000   127.0.0.1:30001  127.0.0.1:30002

Configsvc(三個設定管理員節點):

127.0.0.1:40000   127.0.0.1:40001  127.0.0.1:4002

mongos(一個路由節點):

127.0.0.1:50000

 

詳細操作步驟如下:

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

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

(2)建立資料和記錄檔目錄

進入d:/mongodb-win32-i386-1.8.0目錄下建立如下目錄

建立資料檔案目錄:

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

建立記錄檔目錄:

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

(3)建立分區和複製集

配置第一組:

從命令列進入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執行如下命令!

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

啟動上述分區節點之後,再使用mongo的命令列來初始化複製集

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);

配置第二組:

從命令列進入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執行如下命令!

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

啟動上述分區節點之後,再使用mongo的命令列來初始化複製集

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);

配置第三組:

從命令列進入d:/mongodb-win32-i386-1.8.0/bin目錄,分別執行如下命令!
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)啟動三個佈建服務節點Configsvr

從命令列分別執行如下命令,配置三個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)啟動一個路由節點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" }

配置到這裡,叢集搭建完畢了!

在完成了叢集的搭建工作之後,需要做的就是建立一個資料庫,建立表,設定分區主鍵來初始化資料了!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.