Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

前端 未结 27 2523
孤街浪徒
孤街浪徒 2020-12-12 15:06

while trying this mongo command in ubuntu I am getting this error.

    ritzysystem@ritzysystem-Satellite-L55-A:~$ mongo
    MongoDB shell version: 2.6.1
             


        
相关标签:
27条回答
  • 2020-12-12 15:16

    Issue was with the connection to the database, it could be due to several reasons. For me it was low disk space on my server machine, and when mongo tries to connect it refuse because of low disk, check your server machine local storage with du -sh if you have low storage space, check your logs size and take step accordingly, issue may exist because of dbpath contradict in /etc/mongod.conf and server actually running dbpath with mongod If you are facing such type of issue, please check my answer in the given link below. https://stackoverflow.com/a/53057695/8247133

    0 讨论(0)
  • 2020-12-12 15:17

    is very simple, only delete a file /var/lib/mongodb/mongodb.lock. after only execute: mongo. finished

    0 讨论(0)
  • 2020-12-12 15:17

    There are changes in mongod.conf file in the latest MongoDB v 3.6.5 +

    Here is how I fixed this issue on mac os High Sierra v 10.12.3

    Note: I assume that you have installed/upgrade MongoDB using homebrew

    mongo --version

    MongoDB shell version v3.6.5 
    git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 
    OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018 
    allocator: system modules: none build environment:
    distarch: x86_64
    target_arch: x86_64
    
    1. find mongod.conf file

       sudo find / -name mongod.conf` 
      

      /usr/local/etc/mongod.conf > first result .

    2. open mongod.conf file

      sudo vi /usr/local/etc/mongod.conf
      
    3. edit in the file for remote access under net: section

       port: 27017  
       bindIpAll: true 
       #bindIp: 127.0.0.1 // comment this out
      
    4. restart mongodb

      if you have installed using brew than

      brew services stop mongodb
      
      brew services start mongodb
      

    otherwise, kill the process.

       sudo kill -9 <procssID>
    
    0 讨论(0)
  • 2020-12-12 15:18

    Do this:

    sudo rm /var/lib/mongodb/mongod.lock
    sudo service mongod restart
    

    If you are on Ubuntu 16.04 which you can figure out by runnign this:

    lsb_release -a
    

    You need to Create a new file at /lib/systemd/system/mongod.service with the following contents:

    [Unit]
    Description=High-performance, schema-free document-oriented database
    After=network.target
    Documentation=https://docs.mongodb.org/manual
    
    [Service]
    User=mongodb
    Group=mongodb
    ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
    
    [Install]
    WantedBy=multi-user.target
    
    0 讨论(0)
  • 2020-12-12 15:18

    Just some thoughts on my case.

    If you have changed the dbPath and logPath dirs to your custom values (say /data/mongodb/data, /data/mongodb/log), you must chown them to mongodb user, otherwise, the non-existent /data/db/ dir will be used.

    sudo chown -R mongodb:mongodb /data/mongodb/
    
    sudo service mongod restart
    
    0 讨论(0)
  • 2020-12-12 15:21

    I had the same problem on Mac OS Try to run sudo mongod and in a new terminal tab run mongo

    0 讨论(0)
提交回复
热议问题