1. 下载mongodb源码,并解压:

    wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.11.tgz
    
    tar -zxvf mongodb-linux-x86_64-ubuntu1604-4.0.11.tgz
    
  2. 创建mongo专属目录,拷贝bin下文件到mongodb目录下bin中:

    mkdir /usr/local/mongodb
    
    cd /usr/local/mongodb
    
    mkdir bin
    
    cp .../mongodb-linux-x86_64-ubuntu1604-4.0.11/bin/* ./bin/
    
  3. 创建数据库文件目录、日志目录、配置文件:

    mkdir data
    
    touch mongodb.log
    
    touch mongodb.conf
    
  4. 配置文件内容:

    dbpath=/usr/local/mongodb/data
    logpath=/usr/local/mongodb/mongodb.log
    
    logappend=true
    journal=true
    fork=true
    
    bind_ip = 127.0.0.1
    port = 27017
    
    noauth = true
    #auth = true
    
  5. 将mongo添加path:

    #打开profile
    vi /etc/profile
    
    #输入下面内容:
    MONGO_DB="/usr/local/mongodb"
    PATH=$MONGO_DB/bin:$PATH:
    export PATH
    
    #加载配置
    source /etc/profile
    
  6. 启动mongodb:

    /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
    
    #启动后会看到:
    
    about to fork child process, waiting until server is ready for connections.
    forked process: 1361
    child process started successfully, parent exiting