Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

node.js - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...