- MongoDB官網下載鏈接:https://www.mongodb.com/download-center/community
- MongoDB官網安裝教程:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
- MongoDB 3.6.11版本,官網下載:
綠色版(.zip):https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.11.zip
安裝版(.msi):https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.11-signed.msi
個人偏好“綠色版”安裝,其移植性、各系統識別性強,“一個zip裝天下” ^_^。Windows、Linux、Mac系統均識別.zip文件。可在磁盤路徑變化后,只需修改系統環境變量path路徑,即可恢復正常使用。適用於對系統環境熟悉的人員。
注意:在 MongoDB 2.2 版本后已經不再支持 Windows XP 系統。最新版本也已經沒有了 32 位系統的安裝文件。
1. 自定義安裝(解壓)到:
D:\Program Files\mongodb-win32-x86_64-2008plus-ssl-3.6.11
2. 配置系統環境變量path:
3. 在安裝路徑下創建文件夾和文件:
- "/data" 和 "/log" 兩個文件夾("/data"文件夾下,用於存放數據庫源數據;"/log"文件夾下,用於存放logger日志);
- 在data文件夾下創建"/db"空文件夾;
- 在log文件夾下創建"mongo.log"空文件。
注:其實data和log兩個文件夾,在何處創建都無所謂,依個人習慣。關鍵在於下一步驟,"mongo.config"配置內容中,"dbpath"和"logpath"所指向的路徑。
為將重要文件與非重要文件分離,以便數據移植,故data文件夾與log文件夾分開創建。
4. 在安裝路徑下創建配置文件“mongo.config”,並寫入以下內容:
-
#數據庫文件的存放位置
-
dbpath=D:\Program Files\mongodb-win32-x86_64-
2008plus-ssl-
3.6.
11\data\db
-
-
#日志文件存放的路徑
-
logpath=D:\Program Files\mongodb-win32-x86_64-
2008plus-ssl-
3.6.
11\
log\mongo.log
5. 以“超級管理員身份”運行"cmd",創建MongoDB管理服務,輸入以下命令:
mongod --config "D:\Program Files\mongodb-win32-x86_64-2008plus-ssl-3.6.11\mongo.config" --install --serviceName "MongoDB"
啟動MongoDB服務命令(同樣要使用“超級管理員身份運行”):
net start MongoDB
關閉MongoDB服務命令:
net stop MongoDB
6. 啟動服務完成后,win + R直接運行"cmd",輸入"mongo"即可運行。
顯示信息如下:
C:\Users\PC>mongo
MongoDB shell version v3.6.11
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.11
Server has startup warnings:
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten]
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten]
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-03-13T15:36:39.950+0800 I CONTROL [initandlisten]
>
-
# 端口號,默認27017
-
#port=27017
-
-
# 數據庫文件位置
-
dbpath=/data/db
-
-
#日志文件位置
-
logpath=/log/mongo.log
-
-
# 是否追加方式寫入日志,默認True
-
logappend=
true
-
-
# 設置綁定ip
-
bind_ip =
127.0
.0
.1
-
# 設置端口
-
port =
27017
-
-
# 是否以守護進程方式運行,默認false
-
fork =
true
-
-
#這個選項可以過濾掉一些無用的日志信息,若需要調試使用請設置為false
-
quiet=
false
-
-
# 啟用日志文件,默認啟用
-
journal=
true
-
-
# 啟用定期記錄CPU利用率和 I/O 等待,默認false
-
#cpu = true
-
-
# 是否以安全認證方式運行,默認是不認證的非安全方式
-
#noauth = true
-
#auth = true
-
-
# 詳細記錄輸出,默認false
-
#verbose = true
-
-
#用於開發驅動程序時驗證客戶端請求
-
#objcheck = true
-
-
# # 啟用數據庫配額管理,默認false
-
#quota = true
-
-
# 設置oplog日志記錄等級,默認0
-
# 0=off (default)
-
# 1=W
-
# 2=R
-
# 3=both
-
# 7=W+some reads
-
#oplog = 0
-
-
# 是否打開動態調試項,默認false
-
#nocursors = true
-
-
# 忽略查詢提示,默認false
-
#nohints = true
-
-
# 禁用http界面,默認為localhost:28017
-
#nohttpinterface = true
-
-
# 關閉服務器端腳本,這將極大的限制功能,默認false
-
#noscripting = true
-
-
# 關閉掃描表,任何查詢將會是掃描失敗
-
#notablescan = true
-
-
# 關閉數據文件預分配
-
#noprealloc = true
-
-
# 為新數據庫指定.ns文件的大小,單位:MB
-
# nssize = <size>
-
-
# 用於Mongo監控服務器的Accout token。
-
#mms-token = <token>
-
-
# Mongo監控服務器的服務器名稱。
-
#mms-name = <server-name>
-
-
# Mongo監控服務器的Ping間隔時間,即心跳
-
#mms-interval = <seconds>
-
-
# Replication Options
-
-
# 設置主從復制參數
-
#slave = true # 設置從節點
-
#source = master.example.com # 指定從節點的主節點
-
# Slave only: 指定要復制的單個數據庫
-
#only = master.example.com
-
# or
-
#master = true # 設置主節點
-
#source = slave.example.com
-
-
# 設置副本集的名字,所有的實例指定相同的名字屬於一個副本集
-
replSet = name
-
-
#pairwith = <server:port>
-
-
# 仲裁服務器地址
-
#arbiter = <server:port>
-
-
# 默認為false,用於從實例設置。是否自動重新同步
-
#autoresync = true
-
-
# 指定的復制操作日志(OPLOG)的最大大小
-
#oplogSize = <MB>
-
-
# 限制復制操作的內存使用
-
#opIdMem = <bytes>
-
-
# 設置ssl認證
-
# Enable SSL on normal ports
-
#sslOnNormalPorts = true
-
-
# SSL Key file and password
-
#sslPEMKeyFile = /etc/ssl/mongodb.pem
-
#sslPEMKeyPassword = pass
-
-
# path to a key file storing authentication info for connections
-
# between replica set members
-
#指定存儲身份驗證信息的密鑰文件的路徑
-
#keyFile=/path/to/keyfile
MongoDB集群基本配置:
-
# 集群配置文件
-
dbpath=/
var/lib/mongodb
-
logpath=/
var/log/mongodb/mongodb.log
-
pidfilepath=/
var/log/mongodb/master.pid
-
directoryperdb=
true
-
logappend=
true
-
replSet=name
-
bind_ip=
127.0
.0
.1
-
port=
27017
-
fork=
true
-
noprealloc=
true
原文地址:https://blog.csdn.net/HTouying/article/details/88428452