天天看點

mongoDB的讀書筆記(via3.0)(00)_【概覽】(02)_mongoDB3.0中的mongod啟動方式小試牛刀mongod啟動Storage format的影響

mongod啟動

本來想寫Replica的非測試模式的叢集架構的,但是實在是手癢癢,把mongoDB的3.0給download下來了,看了一兩眼文檔後決定還是先大概寫一點點關于啟動的話題,之後寫Replica的時候基本上就用mongoDB 3.0的方式+YAML的 配置方式來做了。

mongod利用mmapv1啟動

這個是default的啟動方式。mongod的啟動參數多如牛毛,本來想有空總結一下的,我勒個去的,有些估計這輩子也用不到的場景也不知道如何寫,等我再考慮一下再說吧。

準備配置檔案

storage:
   dbPath: C:\datam\db
   engine: mmapv1
           

注意,engine這個地方可以不寫哦,預設就是mmapv1。其餘那幾十個參數先不寫了太多了。

啟動

C:\MongoDB3\Server\3.0\bin>mongod -f C:\MongoDB3\Server\3.0\etc\conf\config.conf
           

執行上面的指令後:

2015-03-06T23:50:20.794+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1
4116 port=27017 dbpath=C:\datam\db 64-bit host=yanglu
2015-03-06T23:50:20.798+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2015-03-06T23:50:20.799+0800 I CONTROL  [initandlisten] db version v3.0.0
2015-03-06T23:50:20.800+0800 I CONTROL  [initandlisten] git version: a841fd63943
65954886924a35076691b4d149168
2015-03-06T23:50:20.802+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL
 1.0.1j-fips 15 Oct 2014
2015-03-06T23:50:20.803+0800 I CONTROL  [initandlisten] build info: windows sys.
getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Servic
e Pack 1') BOOST_LIB_VERSION=1_49
2015-03-06T23:50:20.804+0800 I CONTROL  [initandlisten] allocator: system
2015-03-06T23:50:20.805+0800 I CONTROL  [initandlisten] options: { config: "C:\M
ongoDB3\Server\3.0\etc\conf\config.conf", storage: { dbPath: "C:\datam\db", engi
ne: "mmapv1" } }
2015-03-06T23:50:20.916+0800 I JOURNAL  [initandlisten] journal dir=C:\datam\db\
journal
2015-03-06T23:50:20.918+0800 I JOURNAL  [initandlisten] recover : no journal fil
es present, no recovery needed
2015-03-06T23:50:20.953+0800 I JOURNAL  [durability] Durability thread started
2015-03-06T23:50:20.954+0800 I JOURNAL  [journal writer] Journal writer thread s
tarted
2015-03-06T23:50:21.167+0800 I INDEX    [initandlisten] allocating new ns file C
:\datam\db\local.ns, filling with zeroes...
2015-03-06T23:50:21.564+0800 I STORAGE  [FileAllocator] allocating new datafile
C:\datam\db\local.0, filling with zeroes...
2015-03-06T23:50:21.565+0800 I STORAGE  [FileAllocator] creating directory C:\da
tam\db\_tmp
2015-03-06T23:50:21.570+0800 I STORAGE  [FileAllocator] done allocating datafile
 C:\datam\db\local.0, size: 64MB,  took 0.002 secs
2015-03-06T23:50:21.590+0800 I NETWORK  [initandlisten] waiting for connections
on port 27017
           

哇啦啦,跑起來了。這個在3.0以前也這樣,沒啥特殊的。

mongod利用WiredTiger啟動

這個是需要指定的啟動方式。

準備配置檔案

storage:
   dbPath: C:\dataw\db
   engine: wiredTiger
           

注意,engine這個地方設定的是wiredTiger哦。

啟動

C:\MongoDB3\Server\3.0\bin>mongod -f C:\MongoDB3\Server\3.0\etc\conf\config.conf
           

執行上面的指令後:

C:\MongoDB3\Server\3.0\bin>mongod -f C:\MongoDB3\Server\3.0\etc\conf\config.conf

2015-03-06T23:59:56.445+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1
4076 port=27017 dbpath=C:\dataw\db 64-bit host=yanglu
2015-03-06T23:59:56.449+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2015-03-06T23:59:56.449+0800 I CONTROL  [initandlisten] db version v3.0.0
2015-03-06T23:59:56.449+0800 I CONTROL  [initandlisten] git version: a841fd63943
65954886924a35076691b4d149168
2015-03-06T23:59:56.450+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL
 1.0.1j-fips 15 Oct 2014
2015-03-06T23:59:56.450+0800 I CONTROL  [initandlisten] build info: windows sys.
getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Servic
e Pack 1') BOOST_LIB_VERSION=1_49
2015-03-06T23:59:56.451+0800 I CONTROL  [initandlisten] allocator: system
2015-03-06T23:59:56.453+0800 I CONTROL  [initandlisten] options: { config: "C:\M
ongoDB3\Server\3.0\etc\conf\config.conf", storage: { dbPath: "C:\dataw\db", engi
ne: "wiredTiger" } }
2015-03-06T23:59:56.457+0800 I STORAGE  [initandlisten] wiredtiger_open config:
create,cache_size=3G,session_max=20000,eviction=(threads_max=4),statistics=(fast
),log=(enabled=true,archive=true,path=journal,compressor=snappy),checkpoint=(wai
t=60,log_size=2GB),statistics_log=(wait=0),
2015-03-06T23:59:56.942+0800 I NETWORK  [initandlisten] waiting for connections
on port 27017
           

Storage format的影響

上面我啟動兩個mongod使用的是:

C:\datam\db : mmapv1模式

C:\dataw\db : wiredTiger模式

兩個不同的檔案夾,使用的兩個不同的存儲模式,mongoDB的3.0中強調,當指定的dbpath使用的存儲引擎和你的engine不一緻的時候,mongoDB是拒絕啟動的哦。

–storageEngine string

Default: mmapv1

New in version 3.0.0.

Specifies the storage engine for the mongod database. Valid options include mmapv1 and wiredTiger.

If you attempt to start a mongod with a storage.dbPath that contains data files produced by a storage engine other than the one specified by –storageEngine, mongod will refuse to start.

mmapv1上面啟動wiredTiger

我們試試對C:\datam\db 使用wiredTiger的引擎:

storage:
   dbPath: C:\datam\db
   engine: wiredTiger
           

結果:

C:\MongoDB3\Server\3.0\bin>mongod -f C:\MongoDB3\Server\3.0\etc\conf\config.conf

2015-03-07T00:07:04.052+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1
1576 port=27017 dbpath=C:\datam\db 64-bit host=yanglu
2015-03-07T00:07:04.056+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2015-03-07T00:07:04.056+0800 I CONTROL  [initandlisten] db version v3.0.0
2015-03-07T00:07:04.056+0800 I CONTROL  [initandlisten] git version: a841fd63943
65954886924a35076691b4d149168
2015-03-07T00:07:04.057+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL
 1.0.1j-fips 15 Oct 2014
2015-03-07T00:07:04.057+0800 I CONTROL  [initandlisten] build info: windows sys.
getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Servic
e Pack 1') BOOST_LIB_VERSION=1_49
2015-03-07T00:07:04.058+0800 I CONTROL  [initandlisten] allocator: system
2015-03-07T00:07:04.059+0800 I CONTROL  [initandlisten] options: { config: "C:\M
ongoDB3\Server\3.0\etc\conf\config.conf", storage: { dbPath: "C:\datam\db", engi
ne: "wiredTiger" } }
2015-03-07T00:07:04.062+0800 I STORAGE  [initandlisten] exception in initAndList
en: 28574 Cannot start server. Detected data files in C:\datam\db created by sto
rage engine 'mmapv1'. The configured storage engine is 'wiredTiger'., terminatin
g
2015-03-07T00:07:04.063+0800 I CONTROL  [initandlisten] dbexit:  rc: 100
           

2015-03-07T00:07:04.062+0800 I STORAGE [initandlisten] exception in initAndList

en: 28574 Cannot start server. Detected data files in C:\datam\db created by sto

rage engine ‘mmapv1’. The configured storage engine is ‘wiredTiger’., terminatin

g

上面已經很明确寫出了我們錯誤地在mmapv1的上面使用wiredTiger的引擎,無法啟動。

wiredTiger上面啟動mmapv1

我們試試對C:\dataw\db 使用mmapv1的引擎:

storage:
   dbPath: C:\dataw\db
   engine: mmapv1
           
C:\MongoDB3\Server\3.0\bin>mongod -f C:\MongoDB3\Server\3.0\etc\conf\config.conf

2015-03-07T00:10:09.777+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1
5152 port=27017 dbpath=C:\dataw\db 64-bit host=yanglu
2015-03-07T00:10:09.781+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2015-03-07T00:10:09.784+0800 I CONTROL  [initandlisten] db version v3.0.0
2015-03-07T00:10:09.784+0800 I CONTROL  [initandlisten] git version: a841fd63943
65954886924a35076691b4d149168
2015-03-07T00:10:09.789+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL
 1.0.1j-fips 15 Oct 2014
2015-03-07T00:10:09.790+0800 I CONTROL  [initandlisten] build info: windows sys.
getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Servic
e Pack 1') BOOST_LIB_VERSION=1_49
2015-03-07T00:10:09.792+0800 I CONTROL  [initandlisten] allocator: system
2015-03-07T00:10:09.793+0800 I CONTROL  [initandlisten] options: { config: "C:\M
ongoDB3\Server\3.0\etc\conf\config.conf", storage: { dbPath: "C:\dataw\db", engi
ne: "mmapv1" } }
2015-03-07T00:10:09.796+0800 I STORAGE  [initandlisten] exception in initAndList
en: 28574 Cannot start server. Detected data files in C:\dataw\db created by sto
rage engine 'wiredTiger'. The configured storage engine is 'mmapv1'., terminatin
g
2015-03-07T00:10:09.798+0800 I CONTROL  [initandlisten] dbexit:  rc: 100
           

結果可想而知,真的是不可以。

つづく・・・

繼續閱讀