MongoDB作為最流行的NoSQL數(shù)據(jù)庫已經(jīng)火了好幾年了,可是一直沒有時(shí)間嘗試,正好我的項(xiàng)目里剛好有類似公告配置掰吕、幫助中心配置的需求版保,類似這樣的關(guān)系性不強(qiáng)的呜笑、對事務(wù)要求不高的數(shù)據(jù)存儲(chǔ)應(yīng)該比較適合NoSQL,所以趁此機(jī)會(huì)嘗試一下MongoDB彻犁。目前看到配置文件叫胁,網(wǎng)上搜到的都不是很全或者比較舊,所以我看著官方文檔配置的汞幢,順便做下簡單的翻譯注釋驼鹅。如有不對的地方,請?jiān)谠u論告知森篷,謝謝输钩。
啟動(dòng)MongoDB的方式有兩種:
1.直接啟動(dòng),配置參數(shù)寫在命令中:
mongod --dbpath=data/db --logpath=log/log.txt --fork
2.以配置文件啟動(dòng):
mongod -f /etc/mongod.conf
或
mongod --config /etc/mongod.conf
一般大多數(shù)情況下都是用第二種吧仲智。
配置文件及簡單注釋(參考官方3.2文檔):
systemLog:
# verbosity: 0 #日志等級买乃,0-5,默認(rèn)0
# quiet: false #限制日志輸出钓辆,
# traceAllExceptions: true #詳細(xì)錯(cuò)誤日志
# syslogFacility: user #記錄到操作系統(tǒng)的日志級別剪验,指定的值必須是操作系統(tǒng)支持的,并且要以--syslog啟動(dòng)
path: /Users/mhq/projects/db/mongo/logs/log.txt #日志路徑前联。
logAppend: false #啟動(dòng)時(shí)功戚,日志追加在已有日志文件內(nèi)還是備份舊日志后,創(chuàng)建新文件記錄日志, 默認(rèn)false
logRotate: rename #rename/reopen蛀恩。rename疫铜,重命名舊日志文件,創(chuàng)建新文件記錄双谆;reopen壳咕,重新打開舊日志記錄,需logAppend為true
destination: file #日志輸出方式顽馋。file/syslog,如果是file谓厘,需指定path,默認(rèn)是輸出到標(biāo)準(zhǔn)輸出流中
timeStampFormat: iso8601-local #日志日期格式寸谜。ctime/iso8601-utc/iso8601-local, 默認(rèn)iso8601-local
# component: #各組件的日志級別
# accessControl:
# verbosity: <int>
# command:
# verbosity: <int>
processManagement:
fork: true #以守護(hù)進(jìn)程運(yùn)行 默認(rèn)false
# pidFilePath: <string> #PID 文件位置
net:
port: 27017 #監(jiān)聽端口竟稳,默認(rèn)27017
bindIp: 127.0.0.1 #綁定監(jiān)聽的ip,deb和rpm包里有默認(rèn)的配置文件(/etc/mongod.conf)里面默認(rèn)配置為127.0.0.1,若不限制IP,務(wù)必確保認(rèn)證安全他爸,多個(gè)Ip用逗號(hào)分隔
maxIncomingConnections: 65536 #最大連接數(shù)聂宾,可接受的連接數(shù)還受限于操作系統(tǒng)配置的最大連接數(shù)
wireObjectCheck: true #校驗(yàn)客戶端的請求,防止錯(cuò)誤的或無效BSON插入,多層文檔嵌套的對象會(huì)有輕微性能影響,默認(rèn)true
ipv6: false #是否啟用ipv6,3.0以上版本始終開啟
unixDomainSocket: #unix socket監(jiān)聽诊笤,僅適用于基于unix的系統(tǒng)
enabled: false #默認(rèn)true
pathPrefix: /tmp #路徑前綴系谐,默認(rèn)/temp
filePermissions: 0700 #文件權(quán)限 默認(rèn)0700
http: #警告 確保生產(chǎn)環(huán)境禁用HTTP status接口、REST API以及JSON API以防止數(shù)據(jù)暴露和漏洞攻擊
enabled: false #是否啟用HTTP接口讨跟、啟用會(huì)增加網(wǎng)絡(luò)暴露纪他。3.2版本后停止使用HTTP interface
JSONPEnabled: false #JSONP的HTTP接口
RESTInterfaceEnabled: false #REST API接口
# ssl: #估計(jì)用不到,所以沒有自己看
# sslOnNormalPorts: <boolean> # deprecated since 2.6
# mode: <string>
# PEMKeyFile: <string>
# PEMKeyPassword: <string>
# clusterFile: <string>
# clusterPassword: <string>
# CAFile: <string>
# CRLFile: <string>
# allowConnectionsWithoutCertificates: <boolean>
# allowInvalidCertificates: <boolean>
# allowInvalidHostnames: <boolean>
# disabledProtocols: <string>
# FIPSMode: <boolean>
security:
authorization: enabled # enabled/disabled #開啟客戶端認(rèn)證
javascriptEnabled: true #啟用或禁用服務(wù)器端JavaScript執(zhí)行
# keyFile: <string> #密鑰路徑
# clusterAuthMode: <string> #集群認(rèn)證方式
# enableEncryption: <boolean>
# encryptionCipherMode: <string>
# encryptionKeyFile: <string>
# kmip:
# keyIdentifier: <string>
# rotateMasterKey: <boolean>
# serverName: <string>
# port: <string>
# clientCertificateFile: <string>
# clientCertificatePassword: <string>
# serverCAFile: <string>
# sasl:
# hostName: <string>
# serviceName: <string>
# saslauthdSocketPath: <string>
# setParameter: #設(shè)置參數(shù)
# <parameter1>: <value1>
# <parameter2>: <value2>
storage:
dbPath: /Users/mhq/projects/db/mongo/test/ #數(shù)據(jù)庫晾匠,默認(rèn)/data/db,如果使用軟件包管理安裝的查看/etc/mongod.conf
indexBuildRetry: true #重啟時(shí)茶袒,重建不完整的索引
# repairPath: <string> #--repair操作時(shí)的臨時(shí)工作目錄,默認(rèn)為dbPath下的一個(gè)_tmp_repairDatabase_<num>的目錄
journal:
enabled: true #啟動(dòng)journal,64位系統(tǒng)默認(rèn)開啟凉馆,32位默認(rèn)關(guān)閉
# commitIntervalMs: <num> #journal操作的最大時(shí)間間隔薪寓,默認(rèn)100或30
directoryPerDB: false #使用單獨(dú)的目錄來存儲(chǔ)每個(gè)數(shù)據(jù)庫的數(shù)據(jù),默認(rèn)false,如果需要更改,要備份數(shù)據(jù)句喜,刪除掉dbPath下的文件预愤,重建后導(dǎo)入數(shù)據(jù)
# syncPeriodSecs: 60 #使用fsync來將數(shù)據(jù)寫入磁盤的延遲時(shí)間量,建議使用默認(rèn)值
engine: wiredTiger #存儲(chǔ)引擎沟于,mmapv1/wiredTiger/inMemory 默認(rèn)wiredTiger
# mmapv1:
# preallocDataFiles: <boolean>
# nsSize: <int>
# quota:
# enforced: <boolean>
# maxFilesPerDB: <int>
# smallFiles: <boolean>
# journal:
# debugFlags: <int>
# commitIntervalMs: <num>
# wiredTiger:
# engineConfig:
# cacheSizeGB: <number> #緩存大小
# journalCompressor: <string> #數(shù)據(jù)壓縮格式 none/snappy/zlib
# directoryForIndexes: <boolean> #將索引和集合存儲(chǔ)在單獨(dú)的子目錄下咳胃,默認(rèn)false
# collectionConfig:
# blockCompressor: <string> #集合數(shù)據(jù)壓縮格式
# indexConfig:
# prefixCompression: <boolean> #啟用索引的前綴壓縮
# inMemory:
# engineConfig:
# inMemorySizeGB: <number>
operationProfiling: #性能分析
slowOpThresholdMs: 100 #認(rèn)定為查詢速度緩慢的時(shí)間閾值,超過該時(shí)間的查詢即為緩慢查詢旷太,會(huì)被記錄到日志中, 默認(rèn)100
mode: off #operationProfiling模式 off/slowOp/all 默認(rèn)off
# replication: #復(fù)制集相關(guān)
# oplogSizeMB: <int>
# replSetName: <string>
# secondaryIndexPrefetch: <string>
# enableMajorityReadConcern: <boolean>
# sharding: #集群分片相關(guān)
# clusterRole: <string>
# archiveMovedChunks: <boolean>
# auditLog:
# destination: <string>
# format: <string>
# path: <string>
# filter: <string>
# snmp:
# subagent: <boolean> #當(dāng)設(shè)置為true展懈,SNMP作為代理運(yùn)行
# master: <boolean> #當(dāng)設(shè)置為true,SNMP作為主服務(wù)器運(yùn)行
# basisTech:
# rootDirectory: <string>
參考自MongoDB官方3.2文檔-Reference-Configuration File Options
歡迎來我的個(gè)人博客逛逛: https://blog.52xtg.com