mongodb 4.4 單機安裝

軟件下載

社區版下載地址:https://www.mongodb.com/try/download/community
如下內容以二進制解壓包爲例介紹,官方文檔地址:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/linux

安裝前配置

1、系統準備mongodb

  1. redhat或cnetos6.2以上系統
  2. 系統開發包完整
  3. ip地址和hosts文件解析正常
  4. iptables防火牆&SElinux關閉
  5. 關閉大頁內存機制
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    echo never > /sys/kernel/mm/transparent_hugepage/defrag數據庫

    永久關閉大頁內存root用戶下
    在vi /etc/rc.local最後添加以下代碼
    if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    fi
    if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
    echo never > /sys/kernel/mm/transparent_hugepage/defrag
    fi
    其餘系統關閉參照官方文檔:https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
  6. 修改 vim /etc/security/limits.conf
*               -       nofile          65535
*               -       nproc           65536

7.建立所需用戶和組vim

useradd mongod
passwd mongod

8.上傳並解壓軟件到指定位置,設置權限安全

mkdir /app
cd /app
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.4.tgz 
ln -s mongodb mongodb-linux-x86_64-rhel70-4.4.4
chown -R mongod:mongod -R mongodb*

9.設置用戶環境變量bash

su - mongod
vi .bash_profile
export PATH=/app/mongodb/bin:$PATH
source .bash_profile

單機安裝

  1. 建立目錄並賦權
    mkdir -p /mongodb/conf
    mkdir -p /mongodb/log
    mkdir -p /mongodb/data
    chown -R mongod:mongod /mongodb
  2. 編輯配置文件
    vim /mongodb/conf/mongodb.conf
    logpath=/mongodb/log/mongodb.log
    dbpath=/mongodb/data 
    port=27017
    logappend=true
    fork=true
  3. 啓動數據庫
    mongod -f /mongodb/conf/mongodb.conf
  4. 鏈接數據庫
    mongo
  5. 中止數據庫
    mongod -f /mongodb/log/mongodb.log --shutdown
  6. systemd管理mongodb
    root用戶
    cat > /etc/systemd/system/mongod.service <<EOF
    [Unit]
    Description=mongodb 
    After=network.target remote-fs.target nss-lookup.target
    [Service]
    LimitNOFILE=65536
    LimitNPROC=65536
    User=mongod
    Type=forking
    ExecStart=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/mongodb/bin/mongod --config /mongodb/conf/mongo.conf --shutdown
    PrivateTmp=true  
    [Install]
    WantedBy=multi-user.target
    EOF
    #重啓
    systemctl restart mongod
    #中止
    systemctl stop mongod
    #啓動
    systemctl start mongod
  7. 配置文件(YMAL模式)
    https://docs.mongodb.com/manual/administration/configuration/
    --
    NOTE:
    YAML does not support tab characters for indentation: use spaces instead.
    --系統日誌有關  
    systemLog:
    destination: file        
    path: "/mongodb/log/mongodb.log"    --日誌位置
    logAppend: true                     --日誌以追加模式記錄
    --數據存儲有關   
    storage:
    journal:
      enabled: true
    dbPath: "/mongodb/data"            --數據路徑的位置
    -- 進程控制  
    processManagement:
    fork: true                         --後臺守護進程
    pidFilePath: <string>              --pid文件的位置,通常不用配置,能夠去掉這行,自動生成到data中
    --網絡配置有關   
    net:            
    bindIp: <ip>                       -- 監聽地址,若是不配置這行是監聽在0.0.0.0
    port: <port>                       -- 端口號,默認不配置端口號,是27017
    -- 安全驗證有關配置      
    security:
    authorization: enabled              --是否打開用戶名密碼驗證
    ------------------如下是複製集與分片集羣有關----------------------  
    replication:
    oplogSizeMB: <NUM>
    replSetName: "<REPSETNAME>"
    secondaryIndexPrefetch: "all"
    sharding:
    clusterRole: <string>
    archiveMovedChunks: <boolean>
    ---for mongos only
    replication:
    localPingThresholdMs: <int>
    sharding:
    configDB: <string>
    --
    ++++++++++++++++++++++
    YAML例子
    cat > /mongodb/conf/mongo.conf <<EOF
    systemLog:
    destination: file
    path: "/mongodb/log/mongodb.log"
    logAppend: true
    storage:
    journal:
      enabled: true
    dbPath: "/mongodb/data/"
    processManagement:
    fork: true
    net:
    port: 27017
    bindIp: 11.111.24.4,127.0.0.1
    EOF
相關文章
相關標籤/搜索