MongoDB running but can't connect using shell

前端 未结 17 1703
甜味超标
甜味超标 2020-12-23 16:45

CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)

MongoDB is running:

root     31664  1.5  1.4  81848 11148 ?        Sl   18:40   0:         


        
相关标签:
17条回答
  • 2020-12-23 17:08

    You may want to check your config to see if the bind_ip is set

    bind_ip: 127.0.0.1

    If it is then this permits only local logins. Comment this out and restart mongo, this may help.

    0 讨论(0)
  • 2020-12-23 17:09

    If your bind_ip is set to anything other than 127.0.0.1 then you'll need to add the ip explicitly even from the local machine. So simply use the same method that you're using on the remote box on the local box. At least that's what did it for me.

    0 讨论(0)
  • 2020-12-23 17:09

    On Ubuntu:

    Wed Jan 27 10:21:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84 exception: connect failed

    Solution

    look for if mongodb is running by following command:

    ps -ef | grep mongo
    

    If mongo is not running you get:

     vimal     1806  1698  0 10:11 pts/0    00:00:00 grep --color=auto mongo
    

    You are seeing that the mongo daemon is not there.

    Then start it through configuration file(with root priev):

    root@vimal:/data# mongod --config /etc/mongodb.conf &
    [1] 2131
    root@vimal:/data# all output going to: /var/log/mongodb/mongodb.log
    

    you can see the other details:

    root@vimal:~# more /etc/mongodb.conf
    

    Open a new terminal to see the result of mongod --config /etc/mongodb.conf & then type mongo. It should be running or grep

    root@vimal:/data# ps -ef | grep mongo
    
    root      3153     1  2 11:39 ?        00:00:23 mongod --config /etc/mongodb.conf
    root      3772  3489  0 11:55 pts/1    00:00:00 grep --color=auto mongo 
    

    NOW

    root@vimal:/data# mongo
    
    MongoDB shell version: 2.0.4
    connecting to: test
    

    you get the mongoDB shell

    This is not the end of story. I will post the repair method so that it starts automatically every time, most development machine shutdowns every day and the VM must have mongo started automatically at next boot.

    0 讨论(0)
  • 2020-12-23 17:10

    Open the file /etc/mongod.conf and add the ip of the machine from where you are connecting, to bind_ip

    bind_ip = 127.0.0.1,your Remote Machine Ip Address Here

    Ex:-

    bind_ip = 127.0.0.1,192.168.1.5
    

    Restart mongodb service:

    sudo service mongod restart
    

    Make sure mongodb port is opened in the firewall.

    You can also comment the line, if you are not worried about security.

    0 讨论(0)
  • 2020-12-23 17:11

    Not so much an answer but more of an FYI:I've just hit this and found this question as a result of searching. Here is the details of my experience:

    Shell error

    markdsievers@ip-xx-xx-xx-xx:~$ mongo
    MongoDB shell version: 2.0.1
    connecting to: test
    Wed Dec 21 03:36:13 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
    Wed Dec 21 03:36:13 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017] 
    Wed Dec 21 03:36:13 DBClientCursor::init call() failed
    Wed Dec 21 03:36:13 Error: Error during mongo startup. :: caused by :: DBClientBase::findN: transport error: 127.0.0.1 query: { whatsmyuri: 1 } shell/mongo.js:84
    exception: connect failed
    

    Mongo logs reveal

    Wed Dec 21 03:35:04 [initandlisten] connection accepted from 127.0.0.1:50273 #6612
    Wed Dec 21 03:35:04 [initandlisten] connection refused because too many open connections: 819
    

    This perhaps indicates the other answer (JaKi) was experiencing the same thing, where some connections were purged and access made possible again for the shell (other clients)

    0 讨论(0)
  • 2020-12-23 17:13

    I think there is some default config what is missing in this version of mongoDb client. Try to run:

    mongo 127.0.0.1:27017
    

    It's strange, but then I've experienced the issue went away :) (so the simple command 'mongo' w/o any params started to work again for me)

    [Ubuntu Linux 11.10 x64 / MongoDB 2.0.1]
    
    0 讨论(0)
提交回复
热议问题