developer tip

서버 127.0.0.1 shell / mongo.js에 연결할 수 없습니다.

optionbox 2020. 9. 11. 07:53
반응형

서버 127.0.0.1 shell / mongo.js에 연결할 수 없습니다.


내 우분투에서 mongodb를 설정할 때 시도합니다. ./mongo이 오류가 표시됩니다.

 couldn't connect to server 127.0.0.1 shell/mongo.js

그래서 내가 무엇을 할 수 있니 ,

감사


  • 잠금 파일을 수동으로 제거하십시오. sudo rm /var/lib/mongodb/mongod.lock
  • 복구 스크립트를 실행합니다. sudo -u mongodb mongod -f /etc/mongodb.conf --repair

다음 사항에 유의하십시오.

  • mongodb 사용자로이 명령을 실행해야합니다. 루트로 실행하면 루트는 mongodb 데몬을 실행하는 데 필요한 / var / lib / mongodb /에있는 파일을 소유하므로 데몬이 나중에 mongodb 사용자로 실행하려고 할 때 시작할 권한이 없습니다. . 이 경우 다음 오류가 표시됩니다. 잠금 파일 경로 : /var/lib/mongodb/mongod.lock에 대한 잠금 파일을 생성 / 열 수 없습니다. errno : 13 권한이 거부되어 종료됩니다.
  • Ubuntu에서는 -f 플래그를 사용하여 구성 파일 /etc/mongodb.conf를 지정해야합니다. 그렇지 않으면 잘못된 위치에서 데이터 파일을 찾고 다음 오류가 표시됩니다. dbpath (/ data / db /)가 존재하지 않아 종료됩니다.

sudo rm /var/lib/mongodb/mongod.lock   
sudo -u mongodb mongod -f /etc/mongodb.conf --repair 
sudo service mongodb start

때때로 이러한 작업을 수행 한 후 mongo를 시작하는 데 약간의 시간이 걸립니다.


$ mongod 실행 시도

다음과 같은 오류가 발생하면

MongoDB shell version: 2.0.5
connecting to: test
Fri Jun  1 11:20:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed

hisham-agil:~ hisham$ mongod
mongod --help for help and startup options
Fri Jun  1 11:24:47 [initandlisten] MongoDB starting : pid=53452 port=27017 dbpath=/data/db/ 64-bit host=hisham-agil.local
Fri Jun  1 11:24:47 [initandlisten] db version v2.0.5, pdfile version 4.5
Fri Jun  1 11:24:47 [initandlisten] git version: nogitversion
Fri Jun  1 11:24:47 [initandlisten] build info: Darwin gamma.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:48:32 PST 2012; root:xnu-1699.24.23~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Jun  1 11:24:47 [initandlisten] options: {}
Fri Jun  1 11:24:47 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Fri Jun  1 11:24:47 dbexit: 
Fri Jun  1 11:24:47 [initandlisten] shutdown: going to close listening sockets...
Fri Jun  1 11:24:47 [initandlisten] shutdown: going to flush diaglog...
Fri Jun  1 11:24:47 [initandlisten] shutdown: going to close sockets...
Fri Jun  1 11:24:47 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jun  1 11:24:47 [initandlisten] shutdown: lock for final commit...
Fri Jun  1 11:24:47 [initandlisten] shutdown: final commit...
Fri Jun  1 11:24:47 [initandlisten] shutdown: closing all files...
Fri Jun  1 11:24:47 [initandlisten] closeAllFiles() finished
Fri Jun  1 11:24:47 dbexit: really exiting now

그런 다음 매우 일반적인 기본 시작 오류가 발생했습니다.

기본적으로 mongod는 데이터베이스 파일에 / data / db를 사용하려고 시도합니다.이 경우 존재하지 않는 파일입니다.

시작할 수 없습니다

mongo 

당신이 처리 할 때까지

mongod.

해당 디렉토리를 생성하고 mongod 프로세스를 실행하는 동일한 사용자가 쓸 수 있는지 확인하십시오.

**See similar question-- Getting an error, "Error: couldn't connect to server 127.0.0.1 shell/mongo.js" & when trying to run mongodb on mac osx lion


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 ;)


I got the same problem when I tried to install mongo. I got Error as,

Error

"Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84"

Solution:

First install mongod by using:

sudo apt-get install mongodb-server

Then type

mongod --dbpath /mongo/db

Then

sudo rm /var/lib/mongodb/mongod.lock

Then

sudo -u mongodb mongod -f /etc/mongodb.conf  --repair

Thank You


You need to delete the lockfile mongod.lock or /var/lib/mongodb/mongod.lock on ubuntu, then you need to run mongod.exe or service mongodb start on ubuntu first, then run mongo.exe or mongo on ubuntu.


Either your mongod is not running (check using "ps" command) or it is listening on some outside IP address and not on localhost. So first check the process list if 'mongod' is running. If yes, check with "netstat -nap" for the related port.

Of course you can start mongod on the console manually or even look into the mongod logfile (if there is one configured...depending on how you installed mongod).


First you have to make sure that all the files and directories in your /var/lib/mongodb/ folder (or whichever folder dbpath points to) belong to the mongodb user and mongodb group.

cd /var/lib/mongodb/
sudo chown mongodb filename.*
sudo chgrp mongodb filename.*
sudo chown -R mongodb directory
sudo chgrp -R mongodb directory

(Replace filename and directory with their respective names)

Then you can remove the lock, repair the database and restart the daemon as other people already mentioned:

sudo rm /var/lib/mongodb/mongod.lock   
sudo -u mongodb mongod -f /etc/mongodb.conf --repair 
sudo service mongodb start

First start your mongo server by

Users-MacBook-Pro:csv1 Admin$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log

Then open another terminal window and open shell

Users-MacBook-Pro:csv1 Admin$ mongo

Also check that your root partition has enough space to start mongod.

df -h /

You'll see smth like this on mongod launch:

Mon Aug 12 17:02:59.159 [initandlisten] recover : no journal files present, no recovery needed
Mon Aug 12 17:02:59.159 [initandlisten] 
Mon Aug 12 17:02:59.159 [initandlisten] ERROR: Insufficient free space for journal files
Mon Aug 12 17:02:59.159 [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
Mon Aug 12 17:02:59.159 [initandlisten] 
Mon Aug 12 17:02:59.159 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
Mon Aug 12 17:02:59.159 dbexit: 
Mon Aug 12 17:02:59.159 [initandlisten] shutdown: going to close listening sockets...

On Ubuntu, try this:

sudo invoke-rc.d mongodb start

It could be combination of $PATH and Permission issue.

Try following steps given below:

Update your $PATH variable to point to your MongoDB bin file. In my case brew install MongoDB to this folder:

/usr/local/Cellar/mongodb/2.4.6/

In order to update your $PATH variable, do following:

$ sudo vi /etc/paths

Then, press ‘i’ to insert text in Vi and append the your MongoDB path to the end of the ‘paths’ file and restart the terminal.

/usr/local/Cellar/mongodb/2.4.6/bin

Use ‘Esc : w q’ to save and exit from Vi editor.

Use echo to display your path variable:

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin

Now try to check the Mongo version, if you get following, then you are on the right track!

$ mongo --version
MongoDB shell version: 2.4.6

Now we need to create the database directory. I used the default ‘/data/db’ location suggested in MongoDB docs. I also created a log directory to avoid any permission issues while Mongo tries to create any logs. Change ownership and that will do the job.

$ sudo mkdir /data/db
$ sudo mkdir /data/log
$ whoami
username
$ chown -R username /data

Now, we will create a default config file for MongoDB to be provided for the first time we run ‘mongod’ command. Now, I will also like to point out that ‘mongod’ will start a service, which will listen for incoming data connections. This is similar having ‘$service mysqld start’ executed.Let’s go ahead and create the config file. Please keep in mind that I have created very basic config file. However, you can add many other variables to configure MongoDB. This is the first time I am playing with MongoDB, so I just know as much as I read on MongoDB docs!I created ‘mongodb.conf’.

$ sudo vi /etc/mongodb.conf

Add following:

fork = true
port = 27017
quiet = true
dbpath = /data/db
logpath = /data/log/mongod.log
logappend = true
journal = true

Please note that the default port for MongoDB server is 27017. Use your own path for dbpath and logpath you created in Step – 5. Don’t forget to close and save the conf file.

Now we are all set to start our MongoDB service. Open two instances of Terminal.In Terminal 1, type in:

$ sudo mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3516
all output going to: /data/log/mongod.log
child process started successfully, parent exiting

If you get above message, then know that you have successfully started your Mongod service.

Now, to connect to it, in Terminal 2 type following:

$mongo test
MongoDB shell version: 2.4.6
connecting to: test
Server has startup warnings:
Tue Sep 3 16:55:43.527 [initandlisten]
Tue Sep 3 16:55:43.527 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>

Ignore the warnings, but you are successfully connected to the ‘test’ database! Cool!

That's all. I applied this solution, when I tried to install copy of MongoDB on my Mac for the first time. See if this help you too.

For detailed post you can go here - http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094.

I hope it helps!

Cheers, Chinmay


I solved this problem on ubuntu 12.04 by following steps:
1) sudo rm /var/log/mongodb
2) sudo rm /var/lib/mongodb
3) I removed mongo and then installed it again
4) sudo service mongodb restart

and All is Well

참고URL : https://stackoverflow.com/questions/5726032/couldnt-connect-to-server-127-0-0-1-shell-mongo-js

반응형