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

前端 未结 27 2585
孤街浪徒
孤街浪徒 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:27

    I have the same error with you, this is my case:

    ~# mongod
    2018-07-15T05:27:08.265+0000 I JOURNAL  [initandlisten] journal dir=/data/db/journal
    2018-07-15T05:27:08.265+0000 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
    2018-07-15T05:27:08.301+0000 I JOURNAL  [durability] Durability thread started
    2018-07-15T05:27:08.301+0000 I JOURNAL  [journal writer] Journal writer thread started
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] MongoDB starting : pid=26796 port=27017 dbpath=/data/db 64-bit host=ubuntu-s-2vcpu-4gb-sfo2-01
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] 
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] 
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] 
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] db version v3.0.6
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] build info: Linux build6.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] allocator: tcmalloc
    2018-07-15T05:27:08.302+0000 I CONTROL  [initandlisten] options: {}
    2018-07-15T05:27:08.308+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
    

    I type mongod to start the server, and I type control + c to exit to shell

    then I type mongo and I got

    ~# mongo
    MongoDB shell version: 3.0.6
    connecting to: test
    2018-07-15T05:05:02.738+0000 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
    2018-07-15T05:05:02.739+0000 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
        at connect (src/mongo/shell/mongo.js:179:14)
        at (connect):1:6 at src/mongo/shell/mongo.js:179
    

    As you can see, my error info is same with you.

    This is case mongod doesn't start with backend process, when I type control + c I quit mongod.

    We can add --fork args to make the process daemon process.

    #  mongod --logpath /usr/local/mongodb/log.txt --fork
    

    you have to set --logpath if you want to use --fork

    then you will success to connect to mongo

提交回复
热议问题