升级MongoDB到3.0.2并启用wiredTiger存储引擎 基于ubuntu 14.04

升级MongoDB到3.0.2并启用wiredTiger存储引擎

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

首先对mongodb 3.0之前的数据进行备份:

 

for (var i = 1; i <= 50000; i++) {
 db.dbdao.insert( { x : i , name: "dbdao.com" , name1:"dbdao.com", name2:"dbdao.com", name3:"dbdao.com"} )
}

root@dbdao-Inspiron-560s:~# mongodump --out dbdao
connected to: 127.0.0.1
Wed Apr 8 03:41:12.499 all dbs
Wed Apr 8 03:41:12.500 DATABASE: test to dbdao/test
Wed Apr 8 03:41:12.513 test.system.indexes to dbdao/test/system.indexes.bson
Wed Apr 8 03:41:12.514 1 objects
Wed Apr 8 03:41:12.514 test.dbdao to dbdao/test/dbdao.bson
Wed Apr 8 03:41:12.564 50000 objects
Wed Apr 8 03:41:12.564 Metadata for test.dbdao to dbdao/test/dbdao.metadata.json

以上dbdao是用户自己定义的一个备份目录。

 

之后安装mongodb 3.0.2

 

操作系统是Ubuntu 14.04.1 LTS \n \l

主要步骤如下:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start



安装详细步骤如下

root@dbdao-Inspiron-560s:~# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.08FbwQ9cDM --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

root@dbdao-Inspiron-560s:~# echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse


sudo apt-get update
sudo apt-get install -y mongodb-org

 

之后创建wiredTiger使用的存储目录并修改必要的参数

 

 

sudo mkdir -p /m01/mondata
 sudo chown mongodb:mongodb /m01/mondata
 sudo echo "storageEngine = wiredTiger" >> /etc/mongod.conf 

 修改 sudo vi /etc/mongod.conf 

 dbpath=/var/lib/mongodb

 修改为

 dbpath=/m01/mondata

root@dbdao-Inspiron-560s:~# mongo
MongoDB shell version: 3.0.2
connecting to: test
Server has startup warnings: 
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] 
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] 
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-04-08T04:02:11.903-0400 I CONTROL [initandlisten] 
> db.dbdao.count();
50000


修改/etc/security/limits.conf 加入如下内容 : sudo vi /etc/security/limits.conf

* soft nproc 1024
root soft nproc unlimited

* soft nofile 64000 # 加入的内容
* hard nofile 64000 # 加入的内容

修改/etc/rc.local 如下sudo vi /etc/rc.local


touch /var/lock/subsys/local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then # ↑加入的内容
 echo never > /sys/kernel/mm/transparent_hugepage/enabled # │
fi # │
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then # │
 echo never > /sys/kernel/mm/transparent_hugepage/defrag # │
fi 


修改 /etc/init/mongod.conf , 加入 vi /etc/init/mongod.conf

在pre-start script 这一行下面加入下面的内容

 if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
 echo never > /sys/kernel/mm/transparent_hugepage/enabled
 fi
 if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]; then
 echo never > /sys/kernel/mm/transparent_hugepage/defrag
 fi


 

之后导入先前的数据,并启动mongodb @wiredTiger

dfsds

root@dbdao-Inspiron-560s:/var/lib/mongodb# sudo service mongod restart
mongod start/running, process 6983
root@dbdao-Inspiron-560s:/var/lib/mongodb# sudo service mongod status
mongod start/running, process 6983



root@dbdao-Inspiron-560s:/m01/mondata# cd /m01/mondata/


root@dbdao-Inspiron-560s:/m01/mondata# ls -l
total 132
-rw-r--r-- 1 mongodb nogroup 16384 Apr 8 04:03 collection-0-1898341878753293233.wt
-rw-r--r-- 1 mongodb nogroup 16384 Apr 8 04:03 index-1-1898341878753293233.wt
drwxr-xr-x 2 mongodb nogroup 4096 Apr 8 04:02 journal
-rw-r--r-- 1 mongodb nogroup 16384 Apr 8 04:03 _mdb_catalog.wt
-rwxr-xr-x 1 mongodb nogroup 5 Apr 8 04:02 mongod.lock
-rw-r--r-- 1 mongodb nogroup 16384 Apr 8 04:04 sizeStorer.wt
-rw-r--r-- 1 mongodb nogroup 95 Apr 8 04:02 storage.bson
-rw-r--r-- 1 mongodb nogroup 46 Apr 8 04:02 WiredTiger
-rw-r--r-- 1 mongodb nogroup 495 Apr 8 04:02 WiredTiger.basecfg
-rw-r--r-- 1 mongodb nogroup 21 Apr 8 04:02 WiredTiger.lock
-rw-r--r-- 1 mongodb nogroup 874 Apr 8 04:04 WiredTiger.turtle
-rw-r--r-- 1 mongodb nogroup 40960 Apr 8 04:04 WiredTiger.wt

通过命令 echo "db.serverStatus()"| mongo|grep wiredTiger 可以确认是否启用了wiredTiger

root@dbdao-Inspiron-560s:/m01/mondata# echo "db.serverStatus()"| mongo|grep wiredTiger
 "name" : "wiredTiger"
 "wiredTiger" : {


使用mongorestore 导入之前导出的数据

root@dbdao-Inspiron-560s:~# mongorestore dbdao/
2015-04-08T04:12:18.779-0400 building a list of dbs and collections to restore from dbdao/ dir
2015-04-08T04:12:18.779-0400 reading metadata file from dbdao/test/dbdao.metadata.json
2015-04-08T04:12:18.780-0400 restoring test.dbdao from file dbdao/test/dbdao.bson
2015-04-08T04:12:19.904-0400 restoring indexes for collection test.dbdao from metadata
2015-04-08T04:12:19.905-0400 finished restoring test.dbdao
2015-04-08T04:12:19.905-0400 done

root@dbdao-Inspiron-560s:~# mongo
MongoDB shell version: 3.0.2
connecting to: test

> db.dbdao.count();
50000

以上完成了mongodb单个节点下的升级,升级后启用了mongodb 3.0最新的wiredTiger存储引擎。
总的来说mongodb的升级要比oracle这类传统RDBMS要简单得多。

此条目发表在 未分类 分类目录。将固定链接加入收藏夹。

评论功能已关闭。