前言
本篇文章主要描述了Linux環(huán)境下mongoDB 4搭建的搭建筆記廓奕,方便以后快速查閱。
環(huán)境
- Ubuntu 5.4.0-6ubuntu1~16.04.12
- mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz
步驟
- 下載
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz - 解壓
tar -zxvf mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz - 移動(dòng)解壓后的文件夾到指定的目錄中
mv mongodb-linux-x86_64-ubuntu1604-4.2.8 /usr/local/mongodb - 建兩個(gè)目錄用來(lái)存儲(chǔ)數(shù)據(jù)和日志
mkdir -p /mongodb/single/data/db //數(shù)據(jù)存儲(chǔ)目錄
mkdir -p /mongodb/single/data/log //日志存儲(chǔ)目錄 - 新建并修改配置文件
vi /mongodb/single/mongod.conf
內(nèi)容如下:
systemLog:
# MongoDB發(fā)送所有日志輸出的目標(biāo)指定為文件
destination: file
# mongod或mongos應(yīng)向其發(fā)送所有診斷日志記錄信息的日志文件的路徑
path: "/mongodb/single/log/mongod.log"
#當(dāng)mongos或mongod實(shí)例重新啟動(dòng)時(shí),mongos或mongod會(huì)將新條目附加到現(xiàn)有日志文件的末尾。
logAppend: true
storage:
#mongod實(shí)例存儲(chǔ)其數(shù)據(jù)的目錄。storage.dbPath設(shè)置僅適用于mongod耸采。
##The directory where the mongod instance stores its data.Default Value is "/data/db".
dbPath: "/mongodb/single/data/db"
journal:
#啟用或禁用持久性日志以確保數(shù)據(jù)文件保持有效和可恢復(fù)。
enabled: true
processManagement:
#啟用在后臺(tái)運(yùn)行mongos或mongod進(jìn)程的守護(hù)進(jìn)程模式工育。
fork: true
net:
#服務(wù)實(shí)例綁定的IP虾宇,默認(rèn)是localhost
bindIp: localhost,192.168.30.129
#bindIp #綁定的端口,默認(rèn)是27017
port: 27017
- 啟動(dòng)MongoDB服務(wù)
/usr/local/mongodb/bin/mongod -f /mongodb/single/mongod.conf
顯示 started successfully則啟動(dòng)成功 - 查看Mongo進(jìn)程啟動(dòng)情況:ps -ef | grep mongo
root 7845 1 0 22:35 ? 00:00:15 /usr/local/mongodb/bin/mongod -f /mongodb/single/mongod.conf
root 8467 6829 0 23:49 pts/9 00:00:00 grep --color=auto mongo
- 連接Mongo
./mongo
顯示:
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f57259fc-9e08-4537-9f46-0d91d7e11538") }
MongoDB server version: 4.2.8
Server has startup warnings:
2020-09-16T22:35:04.845+0800 I STORAGE [initandlisten]
2020-09-16T22:35:04.845+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-09-16T22:35:04.845+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-09-16T22:35:05.549+0800 I CONTROL [initandlisten]
2020-09-16T22:35:05.549+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-09-16T22:35:05.549+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-09-16T22:35:05.549+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-09-16T22:35:05.549+0800 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>