MongoDB running but can't connect using shell

前端 未结 17 1704
甜味超标
甜味超标 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:20

    This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.

    For Fedora Linux (wich is the Distro I use) You have to run these commands:

    1 sudo service mongod start
    2 mongo
    

    And there you have it! the server is going to run. Now, If you want Mongo service to Start when the system boots then you have to run:

    sudo chkconfig --levels 235 mongod on
    

    And that's all! If you do that, now in the shell you just have to type mongo in order to start the server but that's pretty much it, the problem is you have to start the SERVICE first and then the SERVER :)

    P.S. The commands I posted might work on other linux distros as well, not just in fedora... In case not maybe you have to tweak some words depending on the distro you're using ;)

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

    By default, mongodb is configured to listen only to localhost. Excerpt from mongodb default config file :

    # Listen to local interface only. Comment out to listen on all interfaces.
    bind_ip=127.0.0.1
    

    One needs to comment the bind_ip to listen from external entities.

    You wont be able to add shards unless you start listening on non-local interfaces.

    HTH,

    Abhay Dandekar

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

    Delete /var/lib/mongodb/mongod.lock, then issue sudo service mongodb start, then mongo.

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

    Facing the same issue with the error described by Garrett above. 1. MongoDB Server with journaling enabled is running as seen using ps command 2. Mongo client or Mongoose driver are unable to connect to the database.

    Solution : 1. Deleting the Mongo.lock file seems to bring life back to normal on the CentOS server. 2. We are fairly new in running MongoDB in production and have been seeing the same issue cropping up a couple of times a week. 3. We've setup a cron schedule to regularly cleanup the lock file and intimate the admin that an incident has occurred.

    Searching for a bug fix to this issue or any other more permanent way to resolve it.

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

    I don't see this having an accepted answer yet, so I'll just add my 2 cents.

    I had the exact same issue just now. After a while I realized I've locked localhost out in my iptables rules. So, check your firewall.

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