ubuntu18 安装mongodb4.x(单机版本)

Ubuntu18安装mongodb4.x

  1. 离线安装

    英文好的同学可以直接通过官网手册安装 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/

    下载安装包

    https://www.mongodb.com/try/download/community

    https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.4.6.tgz

    安装依赖

    默认这些依赖应该有了,没有了重新安装下
    
    sudo apt-get install libcurl4 openssl liblzma5
    
    

    上传安装包到linux服务器,这里我上传到了

    /usr/local/soft
    
    解压
    
    tar -zxvf mongodb-linux-*-4.4.6.tgz
    对目录重命名
    mongodb
    切换到解压后的目录我这里是 /usr/local/soft/mongodb
    创建文件存储目录data,配置文件夹conf,日志目录log
    root@ubuntubase:/usr/local/soft/mongodb# ls -l
    total 140
    drwxr-xr-x 2 root    root       70 Jun 24 14:19 bin
    drwxrwxr-x 2 vpsuser vpsuser    25 Jun 24 16:21 conf
    drwxrwxr-x 4 vpsuser vpsuser  4096 Jun 24 16:22 data
    -rw-r--r-- 1 vpsuser vpsuser 30608 May  8 00:04 LICENSE-Community.txt
    drwxrwxr-x 2 vpsuser vpsuser    41 Jun 24 14:26 log
    -rw-r--r-- 1 root    root        5 Jun 24 16:21 mongod.pid
    -rw-r--r-- 1 vpsuser vpsuser 16726 May  8 00:04 MPL-2
    -rw-r--r-- 1 vpsuser vpsuser  1977 May  8 00:04 README
    -rw-r--r-- 1 vpsuser vpsuser 75685 May  8 00:04 THIRD-PARTY-NOTICES
    
    创建日志文件
    cd /usr/local/soft/mongodb/log
    touch mongo.log 
    
    添加配置文件
    cd /usr/local/soft/mongodb/conf
    touch mongod.conf
    
    我这里的mongodb的配置信息如下
    root@ubuntubase:/usr/local/soft/mongodb/conf# cat mongod.conf 
    # mongod.conf
    
    # for documentation of all options, see:
    #   http://docs.mongodb.org/manual/reference/configuration-options/
    
    # Where and how to store data.
    storage:
      dbPath: /usr/local/soft/mongodb/data
      journal:
        enabled: true
    #  engine:
    #  mmapv1:
    #  wiredTiger:
    
    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      path: /usr/local/soft/mongodb/log/mongod.log
    
    # network interfaces
    net:
      port: 27017
      bindIp: 0.0.0.0
    
    
    # how the process runs
    processManagement:
      fork: true
      pidFilePath: /usr/local/soft/mongodb/mongod.pid
      timeZoneInfo: /usr/share/zoneinfo
    
    #security:
    
    #operationProfiling:
    
    #replication:
    
    #sharding:
    
    ## Enterprise-Only Options:
    
    #auditLog:
    
    #snmp:
    
    
    启动服务
    切换到bin目录 
    cd /usr/local/soft/mongodb/bin
    
    ./mongod -f ../conf/mongod.conf 
    显示信息如下,代表成功
    root@ubuntubase:/usr/local/soft/mongodb/bin# ./mongod -f ../conf/mongod.conf 
    about to fork child process, waiting until server is ready for connections.
    forked process: 1299
    child process started successfully, parent exiting
    
    可以用远程工具连接测试下
    
    

    image

原文地址:https://www.cnblogs.com/syzjzmh/p/14927495.html