简体   繁体   中英

Mongodb in linux server

Using SSH I installed Mongodb in linux server by the following steps.

  1. Download and extract latest Mongodb release to the /bin folder in serer

  2. Edit the .bash_profile and add

    PATH=$PATH:$HOME/bin/mongodb-linux-x86_64-2.6.0/bin

     export PATH 
  3. Directory created for db saving using mkdir -p /data/db

  4. Run mongod --dbpath /data/db
  5. Run mongo

After running mongo command, it shows the error like this :

MongoDB shell version: 2.6.0
connecting to: test
2014-04-24T10:07:58.831+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-04-24T10:07:58.832+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

How it can solve?

First of all, make sure your dbpath exists.

mkdir -p ~/data/db

Then start mongod with:

mongod --dbpath ~/data/db

Finally:

mongo

EDIT : I saw some people vote this answer up. To make it clear, this solution is for you to start mongod with command line. Most of the time if you installed MongoDB package from source, you can just start the daemon with:

sudo systemctl start mongodb # Arch linux
sudo service mongod start # CentOS/Redhat

Configuration file can be found in:

vim /etc/mongod.conf

And if you want daemon to be auto started from boot,

sudo systemctl enable mongodb # Arch Linux
sudo chkconfig mongod on # CentOS/Redhat

I was having this error message after a clean install of mongodb.

What worked for me was removing the lock file and starting mongodb again.

Maybe see if that helps?

Source:

https://wiki.archlinux.org/index.php/MongoDB

I had similar issue after copying all mongodb files form one server to another in

/var/lib/mongodb/

directory. Solution in my case was to change permission group to all files and folders in

/var/lib/mongodb/

to

mongodb:nogroup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM