linux 安裝MongoDB

1、下載

下載 地址http://www.mongodb.org/downloads MongoDB-3.4mongodb

解壓到指定目錄/var/service/MongoDB-3.4shell

建立目錄:mkdir -p /var/service/mongodb-3.4/logs mkdir -p /var/service/mongodb-3.4/data數據庫

2、配置文件

# 日誌文件位置
logpath=/var/service/mongodb-3.4/logs/mongo.log

# 以追加方式寫入日誌
logappend=true

# 是否以守護進程方式運行
#fork = true WIN可能不支持

# 默認27017
port = 27017

# 數據庫文件位置
dbpath=/var/service/mongodb-3.4/data

# 啓用按期記錄CPU利用率和 I/O 等待
#cpu = true

# 是否以安全認證方式運行,默認是不認證的非安全方式
#noauth = true
auth = true

# 詳細記錄輸出
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)用於開發驅動程序時驗證客戶端請求
#objcheck = true

# Enable db quota management
# 啓用數據庫配額管理
#quota = true
# 設置oplog記錄等級
# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#diaglog=0

# Diagnostic/debugging option 動態調試項
#nocursors = true

# Ignore query hints 忽略查詢提示
#nohints = true
# 禁用http界面,默認爲localhost:28017
#nohttpinterface = true

# 關閉服務器端腳本,這將極大的限制功能
# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true
# 關閉掃描表,任何查詢將會是掃描失敗
# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true
# 關閉數據文件預分配
# Disable data file preallocation.
#noprealloc = true
# 爲新數據庫指定.ns文件的大小,單位:MB
# Specify .ns file size for new databases.
# nssize = 

# Replication Options 複製選項
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#指定存儲身份驗證信息的密鑰文件的路徑
#keyFile=/path/to/keyfile

3、啓動

[root@localhost mongodb-3.4]# ./bin/mongod -f mongodb.confvim

進入shell安全

[root@localhost service]# cd mongodb-3.4/
[root@localhost mongodb-3.4]# ./bin/mongo
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.4
>

4、設置用戶 在相應的數據庫下設置用戶

db.createUser({ user: "root",pwd: "root",customData:{name:"root"},roles:[{ role: "readWrite",db: "admin" }]})

5、設置開啓啓動

vim /etc/rc.local 加入下面服務器

/var/service/mongodb-3.4/bin/mongod -dbpath=/var/service/mongodb-3.4/data --fork  --logpath=/var/service/mongodb-3.4/logs/mongo.log  -logappend --auth -port=27017
相關文章
相關標籤/搜索