Linux環(huán)境下MongoDB 4搭建(單機模式)

前言

本篇文章主要描述了Linux環(huán)境下mongoDB 4搭建的搭建筆記,方便以后快速查閱。

環(huán)境

  • Ubuntu 5.4.0-6ubuntu1~16.04.12
  • mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz

步驟

  1. 下載
    wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz
  2. 解壓
    tar -zxvf mongodb-linux-x86_64-ubuntu1604-4.2.8.tgz
  3. 移動解壓后的文件夾到指定的目錄中
    mv mongodb-linux-x86_64-ubuntu1604-4.2.8 /usr/local/mongodb
  4. 建兩個目錄用來存儲數(shù)據(jù)和日志
    mkdir -p /mongodb/single/data/db //數(shù)據(jù)存儲目錄
    mkdir -p /mongodb/single/data/log //日志存儲目錄
  5. 新建并修改配置文件
    vi /mongodb/single/mongod.conf
    內(nèi)容如下:
systemLog:
    # MongoDB發(fā)送所有日志輸出的目標指定為文件
    destination: file
    # mongod或mongos應(yīng)向其發(fā)送所有診斷日志記錄信息的日志文件的路徑
    path: "/mongodb/single/log/mongod.log"
    #當mongos或mongod實例重新啟動時,mongos或mongod會將新條目附加到現(xiàn)有日志文件的末尾。
    logAppend: true
storage:
    #mongod實例存儲其數(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:
    #啟用在后臺運行mongos或mongod進程的守護進程模式。
    fork: true
net:
    #服務(wù)實例綁定的IP,默認是localhost
    bindIp: localhost,192.168.30.129
    #bindIp #綁定的端口,默認是27017
    port: 27017
  1. 啟動MongoDB服務(wù)
    /usr/local/mongodb/bin/mongod -f /mongodb/single/mongod.conf
    顯示 started successfully則啟動成功
  2. 查看Mongo進程啟動情況: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
  1. 連接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()
---
>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容