Mongo啟動說明

來源:互聯網
上載者:User

啟動MongoDB

         昨天根據官方的例子來做的,沒有指定任何自己的參數,完全採用Mongo預設的路徑和參數來進行安裝的,如果沒有root的情況下,是不能把資料庫的預設路徑建立在根目錄的/data/db下的,因此,我想自己定義一個目錄來存放資料檔案,如何進行呢。

    mongod還有很多的啟動選擇項,運行mongod --help就可以查看所有的選擇項。

[mongodb@localhost bin]$ ./mongod --help
Sat Oct 15 14:17:11 
Sat Oct 15 14:17:11 ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Sat Oct 15 14:17:11 **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Sat Oct 15 14:17:11 **       with --journal, the limit is lower
Sat Oct 15 14:17:11 
Allowed options:
General options:
  -h [ --help ]             show this usage information
  --version                  show version information
  -f [ --config ] arg       configuration file specifying additional options
  -v [ --verbose ]         be more verbose (include multiple times for more verbosity e.g. -vvvvv)
  --quiet                     quieter output
  --port arg                  specify port number
  --bind_ip arg              comma separated list of ip addresses to listen on   - all local ips by default

  --dbpath arg              directory for datafiles

  --maxConns arg          max number of simultaneous connections

 --logpath arg               log file to send write to instead of stdout - has to be a file, not directory

    其中,啟動選擇項可以直接寫在在mongod後面,也可以指定設定檔,用檔案來載入各種啟動項,如,如指定mongodb的檔案存放路徑來說,./mongod --dbpath=/home/mongodb/data/db     MongoDB 服務端的預設串連連接埠是 27017  同時也可以指定連接埠啟動,啟動連接埠使用 --port參數選項

主要參數說如下:

dbpath = /home/mongodb/data
    指定資料庫的儲存目錄,如果不設定則以mongodb的根目錄為目錄,當MongoDB啟動之後,在資料庫的儲存目錄下會建立一個mongod.lock檔案,它是用來記錄當前的mongod的進程號,同時也用於區分各個mongod的進程執行個體,所以不同的mongod進程執行個體是不能用相同的dbpath。
logpath = /home/mongodb/mongodb.log
    指定日誌輸出的路徑,如果沒有設定logappend = true,系統會清除原來的日誌記錄,把已有的檔案進行覆蓋。
logappend = true
    日誌以追加的方式進行記錄
bind_ip = 192.168.86.111
    指定對外服務的綁定ip,這裡指定內網的ip方式,如果外網無特殊的處理方式是無法進行串連。
port = 27017
    指定伺服器的監聽連接埠號碼,預設是27017,如果單個機器要運行多個mongod進程,則需要給每個進程指定不同的連接埠號碼。
fork = true
    指定以守護進程的方式來啟動MongoDB,如果不指定,在啟動mongod命令是加“&”也是可以的。
auth = true
    啟動mongodb用戶端登入的認證機制。
master = true
    指定該機器為主從模式下的主機器。


     一般來說,使用參數設定檔啟動,以便記憶和查看,注意:沒有預設的啟動參數檔案,-f 選項可以指定設定檔的位置,

首先建立設定檔:

[mongodb@localhost bin]$ vi /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf
# This is an example config file for MongoDB.
dbpath = /data/db/mongodb
logpath =
/data/db/mongodb/mongod.log
bind_ip = 127.0.0.1
noauth = true
verbose = false
fork = true
nohttpinterface = true
~
</mongodb-linux-i686-2.0.0/mongodb.conf" [新] 8L, 273C 已寫入 

 手動啟動使用設定檔:
[mongodb@localhost bin]$ /home/mongodb/mongodb-linux-i686-2.0.0/bin/mongod -f /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf 
all output going to: /data/db/mongod.log

如果將mongoDB服務加入隨機啟動

vi /etc/rc.local

使用vi編輯器開啟設定檔,並在其中加入下面一行代碼

/home/mongodb/mongodb-linux-i686-2.0.0/bin/mongod -f /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf -

-logappend

開機記錄資訊查看:

[root@localhost ~]# tail -100f /data/db/mongod.log

Thu Oct 20 09:59:18 
Thu Oct 20 09:59:18 [initandlisten] MongoDB starting : pid=5612 port=27017 dbpath=/data/db 32-bit host=localhost --這裡是配置的路徑和主機,連接埠
Thu Oct 20 09:59:18 [initandlisten] 
Thu Oct 20 09:59:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data--使用記憶體大小
Thu Oct 20 09:59:18 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 20 09:59:18 [initandlisten] **       with --journal, the limit is lower
Thu Oct 20 09:59:18 [initandlisten] 
Thu Oct 20 09:59:18 [initandlisten] db version v2.0.0, pdfile version 4.5  --版本號碼
Thu Oct 20 09:59:18 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 20 09:59:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Oct 20 09:59:18 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf", dbpath: "/data/db", logpath: "/data/db/mongod.log", noauth: "true" } --啟動參數
Thu Oct 20 09:59:18 [initandlisten] waiting for connections on port 27017 --監聽連接埠
Thu Oct 20 09:59:18 [websvr] admin web console waiting for connections on port 28017 --web控制台連接埠

這些資訊是很有用的,對於管理和維護是很重要的。


停止MongoDB 千萬要強調的是千萬不要使用kill -9去關閉mongod。這樣資料庫會不理一切直接殺死該進程,會使得資料檔案損壞。
穩妥的方法是使用kill -2 pid去關閉mongod,也就是當mongod進程接受到關閉指令後會等待當前運行操作或檔案分配等操作完畢後,關閉所有開啟的串連,並將緩衝的資料重新整理到磁碟後才正式關閉。
最穩妥的方式是使用shutdown命令來結束
>  use admin
switched to db admin
>  db.shutdownServer();

附:WINDOWS的安裝和配置參考

http://tech.it168.com/a2011/0417/1179/000001179081_1.shtml

聯繫我們

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