搭建MongoDB叢集

來源:互聯網
上載者:User

叢集由以下3個服務組成:

  1. Shards Server: 每個shard由一個或多個mongod進程組成,用於儲存資料
  2. Config Server: 用於儲存叢集的Metadata資訊,包括每個Shard的資訊和chunks資訊
  3. Route Server: 用於提供路由服務,由Client串連,使整個Cluster看起來像單個DB伺服器

另外,Chunks是指MongoDB中一段連續的資料區塊,預設大小是200M,一個Chunk位於其中一台Shard伺服器上

下面,搭建一個Cluster,它由4台伺服器組成,包括2個Shard,3個Config,1個Route

其中每個Shard由一個Replica Set組成,每個Replica Set由2個Mongod節點,1個vote節點群組成

需要分別建立目錄/opt/soft/mongodb/data/data ,/opt/soft/mongodb/log

192.168.11.229
/opt/soft/mongodb/bin/mongod –fork –shardsvr –port 10000 –replSet set1 –dbpath /opt/soft/mongodb/data/data  –logpath /opt/soft/mongodb/log/log.log
/opt/soft/mongodb/bin/mongod –fork –shardsvr –port 10001 –replSet set2 –dbpath /opt/soft/mongodb/data/data1  –logpath /opt/soft/mongodb/log/log1.log
192.168.11.17
/usr/local/mongodb/bin/mongod –fork –shardsvr –port 10000 –replSet set1 –dbpath /opt/soft/mongodb/data/data   –logpath /pvdata/mongodb_log/mongod.log
192.168.11.227
/usr/local/mongodb/bin/mongod –fork –shardsvr –port 10000 –replSet set2 –dbpath /opt/soft/mongodb/data/data  –logpath /opt/soft/mongodb/log/mongod.log
/usr/local/mongodb/bin/mongod –fork –shardsvr –port 10001 –replSet set1 –dbpath /opt/soft/mongodb/data/data1  –logpath /opt/soft/mongodb/log/mongod1.log

192.168.11.228
/usr/local/mongodb/bin/mongod –fork –shardsvr –port 10000 –replSet set2 –dbpath /opt/soft/mongodb/data/data  –logpath /opt/soft/mongodb/log/mongod.log

 

192.168.11.229上mongo –port 10000串連mongo

    config = {_id: 'set1', members: [
        {_id: 0, host: '192.168.11.229:10000'},
        {_id: 1, host: '192.168.11.17:10000'},
        {_id: 2, host: '192.168.11.227:10001', arbiterOnly: true}
    ]}
    rs.initiate(config)
    rs.status()

192.168.11.227上mongo –port 10000串連mongo
    config = {_id: 'set2', members: [
        {_id: 0, host: '192.168.11.227:10000'},
        {_id: 1, host: '192.168.11.228:10000'},
        {_id: 2, host: '192.168.11.229:10001', arbiterOnly: true}
    ]}
    rs.initiate(config)
    rs.status()

 

192.168.11.229:;192.168.11.17;192.168.11.228上啟動進程
mongod --configsvr --fork --logpath /opt/soft/mongodb/log/config.log --logappend --dbpath /opt/soft/mongodb/data/configdata --port 20000

 

192.168.11.227上啟動進程

mongos --fork --configdb "192.168.11.229:20000,192.168.11.17:20000,192.168.11.228:20000" --logpath /opt/soft/mongodb/log/mongos.log

 

192.168.11.227

mongos>  use admin
mongos> db.adminCommand({ addShard : "set1/192.168.11229:10000,192.168.11.17:10000"})
mongos> db.adminCommand({ addShard :"set2/192.168.11.227:10000,192.168.11.228:10000"})
mongos> db.adminCommand({enablesharding:'test'})
mongos>  db.adminCommand({listshards:1})
mongos> printShardingStatus()
mongos> db.adminCommand({shardcollection:'test.test2', key:{_id:1}, unique : true})

 

匯入文本資料(資料以,號隔開)

mongoimport -h  192.168.11.227 -d test -c test --type csv -f ip,sid,uid,cateid,type  --file /opt/dm/meta/uidip_20111017

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.