mongodb3.x版本后就是要yaml語法格式的配置文件,下面是yaml配置文件格式如下:
官方yaml配置文件選項參考:https://docs.mongodb.org/manual/ ...
#configuration-file
只能使用空格,不支持tab鍵,切記
shard 的配置文件范例
storage:
dbPath: /data/mongodb/shard1/data
journal:
enabled: true
directoryPerDB: true
#syncPeriodSecs: 60
engine: wiredTiger
processManagement:
fork: true
pidFilePath: /data/mongodb/shard1/mongod.pid
net:
port: 27017
ipv6: true
http:
enabled: false
systemLog:
destination: file
path: /data/logs/mongodb/27017/log.txt
logAppend: true
#security:
#keyFile: /data/mongodb/keyfile
# authorization: enabled
operationProfiling:
slowOpThresholdMs: 100
mode: slowOp
replication:
oplogSizeMB: 20000
replSetName: shard1
啟動服務:
/data/app/mongodb/bin/mongod --shardsvr -f /data/app/conf/shard1.conf
<ignore_js_op>
1 2 3 4 5 6 |
systemLog: destination: file//指定是一個文件 path: /data/logs/mongod.log//日志存放位置 logAppend: true//產生日志內容追加到文件 # quiet: true//在quite模式下會限制輸出信息 # timeStampFormat: iso8601-utc //默認是iso8601-local,日志信息中還有其他時間戳格式:ctime,iso8601-utc,iso8601-local |
1 2 3 4 5 6 7 8 9 10 |
processManagement: fork: true//以守護進程的方式運行MongoDB,創建服務器進程 pidFilePath: "/data/mongo-data/mongod.pid"//pid文件路徑 net: # bindIp: 192.168.33.131//綁定ip地址訪問mongodb,多個ip逗號分隔 port: 27017//端口 maxIncomingConnections:10000//默認65535,mongodb實例接受的最多連接數,如果高於操作系統接受的最大線程數,設置無效。 # http: # enabled: true//http端口最好關閉 #RESTInterfaceEnabled: false//即使http接口選項關閉,如果這個選項打開后會有更多的不安全因素 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
storage: dbPath: "/data/mongo-data"//數據文件存放路徑 engine: wiredTiger//數據引擎 wiredTiger: engineConfig://wt引擎配置 cacheSizeGB: 1//看服務器情況來進行設置 directoryForIndexes: true//索引是否按數據庫名進行單獨存儲 collectionConfig: blockCompressor: zlib//壓縮配置 indexConfig: prefixCompression: true//索引配置 journal: enabled: true//記錄操作日志,防止數據丟失。 directoryPerDB: true//指定存儲每個數據庫文件到單獨的數據目錄。如果在一個已存在的系統使用該選項,需要事先把存在的數據文件移動到目錄。 operationProfiling: slowOpThresholdMs: 100 //指定慢查詢時間,單位毫秒,如果打開功能,則向system.profile集合寫入數據 mode: "slowOp"//off、slowOp、all,分別對應關閉,僅打開慢查詢,記錄所有操作。 security: keyFile: "/data/mongodb-keyfile"//指定分片集或副本集成員之間身份驗證的key文件存儲位置 clusterAuthMode: "keyFile"//集群認證模式,默認是keyFile authorization: "disabled"//訪問數據庫和進行操作的用戶角色認證 |
復制集相關配置,根據以上配置文件進行如下配置。
1 2 3 4 |
replication: oplogSizeMB: 50//默認為磁盤的5%,指定oplog的最大尺寸。對於已經建立過oplog.rs的數據庫,指定無效 replSetName: "rs_zxl"//指定副本集的名稱 secondaryIndexPrefetch: "all"//指定副本集成員在接受oplog之前是否加載索引到內存。默認會加載所有的索引到內存。none不加載;all加載所有;_id_only僅加載_id |
分片集群配置,分片復制集配置(單實例節點的基礎上)
1 2 3 4 5 |
replication: oplogSizeMB:50 replSetName: "rs_zxl" sharding: clusterRole: shardsvr |
config server配置(單實例節點的基礎上)
1 2 |
sharding: clusterRole: configsvr |
mongos配置,(與單實例不同)
1 2 3 4 5 6 7 8 |
systemLog: destination: file path: /data/logs/mongos.log logAppend: true net: port: 27019 sharding: configDB: 192.168.33.131:30000 |