MongoDB從3.0.7升級到MongoDB3.2

來源:互聯網
上載者:User

MongoDB從3.0.7升級到MongoDB3.2

mongodb3.2版本於前天2015-12-08日剛剛發布,為:https://www.mongodb.org/downloads#production

Starting in 3.2, MongoDB uses the WiredTiger as the default storageengine.

從3.2版本開始,mongodb使用WiredTiger作為預設的儲存引擎。

原3.0.7的啟動命令為:

# /mnt/local/mongodb/bin/mongod --storageEngine wiredTiger --config /mnt/local/mongodb/bin/mongodb.conf

其中mongodb.conf設定檔的內容為:

port=27017 #連接埠
dbpath= /mnt/data/mongodb #資料檔案存放目錄
logpath= /mnt/logs/mongodb/mongodb.log #記錄檔存放目錄
logappend=true #使用追加的方式寫日誌
fork=true #以精靈的方式啟用,即在後台運行
maxConns=500 #最大同時串連數
bind_ip=127.0.0.1 #只允許通過本機訪問
noauth=true #不啟用驗證

備份現有資料庫(資料庫名為ddc,備份到/mnt/wwwroot目錄下)

# /mnt/local/mongodb/bin/mongodump -h 127.0.0.1 -d ddc -o /mnt/wwwroot/ddc.dmp

下載3.2.0版本(我的作業系統為CentOS6.6)

# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.0.tgz

# tar zxvf mongodb-linux-x86_64-rhel62-3.2.0.tgz

# ps aux | grep mongod

# kill -2 進程號

# mv /mnt/local/mongo /mnt/local/mongo_bak

# mv mongodb-linux-x86_64-rhel62-3.2.0 /mnt/local/mongodb

# cp /mnt/local/mongo_bak/bin/mongodb.conf /mnt/local/mongodb/bin/

刪除原先的資料庫檔案(由於3.0.7當初安裝時沒有啟用wiredTiger儲存引擎,而3.2預設的為wiredTiger,不相容3.0.7的預設的mmapv1儲存引擎,故先備份原先的資料後再刪除原先的資料目錄下的檔案)

# rm -rf /mnt/data/mongodb/*
# echo >/mnt/logs/mongodb/mongodb.log

啟動3.2,注意:加上--storageEngine wiredTiger參數,mongodb.conf與3.0.7一樣。

# /mnt/local/mongodb/bin/mongod --storageEngine wiredTiger --config /mnt/local/mongodb/bin/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 7737
child process started successfully, parent exiting

檢查當前mongodb是否啟用了WiredTiger儲存引擎

# WIREDTIGER_CONFIGURED=`ps -ef|grep mongod|grep -i storageengine|grep -ic wiredtiger`
# echo ${WIREDTIGER_CONFIGURED}

如果返回為1則說明當前系統中運行著一個以WiredTiger為儲存引擎的mongod

匯入原資料庫

# /mnt/local/mongodb/bin/mongo
MongoDB shell version: 3.2.0
connecting to: test
Server has startup warnings:
2015-12-10T02:06:21.286+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is
not recommended.
2015-12-10T02:06:21.286+0800 I CONTROL  [initandlisten]
> use ddc

> exit

# /mnt/local/mongodb/bin/mongorestore -h 127.0.0.1 -d ddc /mnt/wwwroot/ddc.dmp/ddc

更多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.