MongoDB叢集搭建步驟

來源:互聯網
上載者:User

MongoDB叢集搭建步驟

搭建mongodb叢集很多次,每次都會或多、或少出現一些見鬼的問題,寫這篇文章供以後參考。本次是基於mongodb3.0進行叢集的搭建;搭建步驟如下:

1、設定作業系統的環境
echo "never">"/sys/kernel/mm/transparent_hugepage/enabled"
echo "never">"/sys/kernel/mm/transparent_hugepage/defrag"
ulimit -n 64000

2、設定檔的修改[mongod.conf]
shards配置:port=27018、directoryperdb=true 、bind_ip=0.0.0.0
 config配置:port=27019、bind_ip=0.0.0.0
 monogs配置:mongos --configdb 192.168.12.150:27019 --logpath /var/log/mongodb/mongos.log  --pidfilepath /var/run/mongodb/mongos.pid --logappend --logRotate reopen --fo
 hosts配置:{shardone.mongodb.local,shardtwo.mongodb.local,shardthree.mongodb.local}添加上每台分區伺服器對應的IP地址的網域名稱解析

3、添加分區
>>mongo admin
>>db.runCommand({addshard:"shardone.mongodb.local:27018",name:"shardone"})          --添加分區
>>db.runCommand({addshard:"shardtwo.mongodb.local:27018",name:"shardtwo"})
>>db.runCommand({addshard:"shardthree.mongodb.local:27018",name:"shardthree"})

分區伺服器盡量以網域名稱解析的方式,避免以後伺服器的ip地址變更

4、對資料庫啟動分區和添加片鍵
>>db.runCommand({"enablesharding":"mc_visit"})
>>db.runCommand({"shardcollection":"mc_visit.mc_visit","key":{"visitdate":-1,"virus":1}})

5、沒有資料情況下修改片鍵
>>use config
>>db.collections.find() --查看所有的片鍵
>>db.chunks.find()      --查看已有分區的塊

MongoDB 3.0 正式版發布下載 

CentOS編譯安裝MongoDB

CentOS 編譯安裝 MongoDB與mongoDB的php擴充

CentOS 6 使用 yum 安裝MongoDB及伺服器端配置

Ubuntu 13.04下安裝MongoDB2.4.3

MongoDB入門必讀(概念與實戰並重)

Ubunu 14.04下MongoDB的安裝指南

《MongoDB 權威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

Nagios監控MongoDB分區叢集服務實戰

基於CentOS 6.5作業系統搭建MongoDB服務

MongoDB 的詳細介紹:請點這裡
MongoDB 的:請點這裡

本文永久更新連結地址:

相關文章

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.