IT

mongo-서버 127.0.0.1:27017에 연결할 수 없습니다

lottoking 2020. 7. 3. 18:05
반응형

mongo-서버 127.0.0.1:27017에 연결할 수 없습니다


이 서비스를 시작하거나 상호 작용하는 데 전혀 문제가 없었던 riak 및 redis에서 왔습니다.

이것은 몽고에 대한 광범위한 문제이며 다소 실마리가 없습니다. 다시 시작해도 도움이되지 않습니다. mongo를 처음 사용합니다.

mongo
MongoDB shell version: 2.2.1
connecting to: test
Fri Nov  9 16:44:06 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed

이것이 내가 로그에서 보는 것입니다.

 now open)
Fri Nov  9 16:44:34 [conn47] end connection 10.29.16.208:5306 (1 connection now open)
Fri Nov  9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5307 #48 (2 connections now open)
Fri Nov  9 16:45:04 [conn48] end connection 10.29.16.208:5307 (1 connection now open)
Fri Nov  9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5308 #49 (2 connections now open)
Fri Nov  9 16:45:04 [conn49] end connection 10.29.16.208:5308 (1 connection now open)
Fri Nov  9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5316 #50 (2 connections now open)
Fri Nov  9 16:45:34 [conn50] end connection 10.29.16.208:5316 (1 connection now open)
Fri Nov  9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5317 #51 (2 connections now open)
Fri Nov  9 16:45:34 [conn51] end connection 10.29.16.208:5317 (1 connection now open)
Fri Nov  9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5320 #52 (2 connections now open)
Fri Nov  9 16:46:04 [conn52] end connection 10.29.16.208:5320 (1 connection now open)
Fri Nov  9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5321 #53 (2 connections now open)
Fri Nov  9 16:46:04 [conn53] end connection 10.29.16.208:5321 (1 conn

이 오류는 mongo 쉘이 mongod 서버와 통신 할 수없는 경우에 표시됩니다.

주소가 잘못되었거나 (호스트 또는 IP) 실행되지 않았기 때문일 수 있습니다. 참고로 제공되는 로그 추적은 귀하의 "11 월 9 일 금요일 16:44:06"을 포함하지 않습니다 mongo timestamp.

너는 할수 있니:

  1. mongod 프로세스를 시작하는 데 사용되는 명령 행 인수 (있는 경우)를 제공하십시오.
  2. mongo 쉘 시작 시도 중 로그뿐만 아니라 mongod 시작의 로그 파일 활동을 제공합니까?
  3. mongod 프로세스가 mongo 쉘과 동일한 시스템에서 시작되고 있는지 확인하십시오.

일반적으로 mongo shell을 시작하기 전에 mongod 프로세스를 시작하지 않았기 때문에 발생했습니다.

mongod 서버 시작

mongod

다른 터미널 창을 엽니 다

몽고 껍질 시작

mongo

해결되었습니다.

이 문제는 아래 언급 된 4 단계로 해결할 수 있습니다.

1) .lock 파일 제거

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

2) mongodb를 수리하십시오

mongod –repair

3) mongod 서버를 시작하십시오

sudo service mongod start 

4) 몽고 클라이언트 시작

mongo

자세한 내용은 http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/참조하십시오.

http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/


이 방법 은 원본 파일을 보존하지 않고 데이터 파일복구 하려는 경우에만 작동 합니다

dbpath가 상주하는 위치를 찾으려면 -vim /etc/mongodb.conf

옵션 dbpath = 확인

(dbpath = / var / lib / mongodb가 있습니다)

기본값 : / data / db /

일반적인 위치는 / srv / mongodb, / var / lib / mongodb 또는 / opt / mongodb입니다.

바꾸기 는 / var / lib 디렉토리 / MongoDB를을 당신과 함께 DBPATH

sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb/ --repair
sudo mongod --dbpath /var/lib/mongodb/ --journal

(위의 줄을 실행 한 터미널을 그대로 두어야합니다. 'Ctrl + c'를 누르거나 종료하지 마십시오.) 이제 다른 창에서 mongo를 시작하는 명령을 입력하십시오.

이것이 당신을 위해 작동하기를 바랍니다! 몽고 복구 원본 파일을 유지하면서 데이터 파일 복구 하려는 사람들을 위해


맥 OS

상태 확인

brew services list

다음과 같은 것 :

Name    Status  User Plist
mongodb stopped  

시작해

brew services start mongodb

다시 해봐

mongo 또는 mongo --port 27017


몽고가 실행 중인지 확인하십시오. mongodb를 복구 하여이 문제를 해결했는데 db를 실행하는 데 필요한 디렉토리가 생성되지 않았습니다. 이 오류를 보여줍니다

유형 : mongod오류가 표시됩니다

exception in initAndListen: 29 Data directory /data/db not found., terminating

dbpath /data/db/(기본 구성)가 없기 때문에 오류가 발생 합니다. 데이터 폴더를 생성하고 권한을 설정해야합니다.

그런 다음 명령으로 시스템에 폴더를 만듭니다.

sudo mkdir -p / data / db /sudo chown id -u/ data / db

그런 다음 몽고를 다시 실행하면 효과가있었습니다.


나의 경우에는:

먼저 설정 파일을 엽니 다

sudo vi /etc/mongodb.conf

코멘트 IP와 포트

#bind_ip = 127.0.0.1
#port = 27017

그런 다음 mongodb를 다시 시작하십시오.

sudo service mongodb restart
sudo service mongod restart

마지막으로 작동합니다 : D

finn@Finn ~ $ mongo
MongoDB shell version: 2.4.9
connecting to: test
> exit

대답이 조금 늦었지만 같은 문제가 발생했습니다.

다음은 나를 도와 준 단계입니다.

  1. C : \로 이동
  2. "데이터"폴더 생성
  3. "data"에서 "db"폴더를 만듭니다.
  4. 터미널 열기 (CMD)-> EX로 이동 : " c:\MongoDB\Server\3.4\bin"
  5. mongod를 입력하십시오 => 이것은 mongo 서버를 시작합니다 (열린 채로 둡니다)

GUI를 사용하여 실행, EX "robomongo"

또는

새 터미널 (CMD) 열기-> c:\MongoDB\Server\3.4\bin"mongo"명령에서 EX : " "유형으로 이동


위의 모든 해결책이 작동하지 않으면 : 서비스 ( start>search>services) 로 이동하여 mongodb 서비스를 시작하십시오. 그런 다음 cmd 프롬프트에서 bin으로 이동 한 후:/>mongo


Windows 사용자이며 2018 년 11 월에 MongoDB를 설치했으며 data / db 디렉토리를 설정하고 싶지 않았습니다. 그러나 며칠 후 열 때 오류 메시지가 나타납니다.

MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
2018-12-05T20:42:40.108+0530 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed

그런 다음 위의 모든 답변을 사용하여 수정하려고했지만 작동하지 않았습니다. 내가 mongod를 실행하려고 할 때 그것은 말했다

MongoDB starting : pid=12220 port=27017 dbpath=C:\data\db\ 64-bit host=bla

I tried to change the db path(to program files) through file system and also using cmd but those didnot worked.

Solution that worked for me is:

Opened the Task Manager (ctrl + shift + esc) -> Services tab and there was a MongoDB row with the status stopped. Then I right clicked and clicked start and everything working perfectly :).


To connect with mongo we have to first start 'mongod' services. following output you can see :

$ mongod
2017-03-05T00:31:39.055+0530 I CONTROL  [initandlisten] MongoDB starting : pid=1481 port=27017 dbpath=/data/db 64-bit host=Prabhu-Nandans-Mac.local
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] db version v3.4.2
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2k  26 Jan 2017
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] allocator: system
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] modules: none
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] build environment:
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten]     distarch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL  [initandlisten] options: {}
2017-03-05T00:31:39.056+0530 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2017-03-05T00:31:39.057+0530 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-03-05T00:31:39.057+0530 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
2017-03-05T00:31:39.057+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] 
2017-03-05T00:31:39.620+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-03-05T00:31:39.643+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-03-05T00:31:39.643+0530 I NETWORK  [thread1] waiting for connections on port 27017
2017-03-05T00:31:40.008+0530 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2017-03-05T00:32:03.832+0530 I NETWORK  [thread1] connection accepted from 127.0.0.1:49806 #1 (1 connection now open)
2017-03-05T00:32:03.833+0530 I NETWORK  [conn1] received client metadata from 127.0.0.1:49806 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.4.0" } }
2017-03-05T00:32:08.376+0530 I -        [conn1] end connection 127.0.0.1:49806 (1 connection now open)

After that open another terminal and just type 'mongo'.

Following is output you can see :

$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2

Your issue solved :)


I also have the same problem then I got fixed by these two lines of code. Hope, it helps

systemctl start mongod
systemctl enable mongod

Another solution that resolved this same error for me, though this one might only be if you are accessing mongo (locally) via a SSH connection via a virtual machine (at least that's my setup), and may be a linux specific environment variable issue:

export LC_ALL=C

Also, I have had more success running mongo as a daemon service then with sudo service start, my understanding is this uses command line arguments rather then the config file so it likely is an issue with my config file:

mongod --fork --logpath /var/log/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb/admin

Create the folder C:data/db if it doesn't already exist on your computer. Turns out MongoDB requires the existence of this folder structure 'data/db' to run. I hope this helps someone.


The cause by me was the space - run this in the console:

df -h

or more specifically:

du -hs /var/lib/mongodb/ 

to check he disk usage. If it's ~ 99% - just clean up some space and try again!


First, go to c:\mongodb\bin> to turn on mongoDB, if you see in console that mongo is listening in port 27017, it is OK If not, close console and create folder c:\data\db and start mongod again


You can try with following command:

sudo service mongod start


This was happening with me today and I resolved it in following way.

Machine: I'm using Windows 10 machine and downloaded the latest MongoDB - Community edition.

So, the problem was, I did not have C:\data\db created.

Without creating C:\data\db, I opened CMD terminal and started the database using mongod command at terminal

C:\YourInstallationPath\bin>mongod

And when I fired mongo command then I was getting the problem.

Twist, I created the necessary folders but still was getting the problem. And this is because mongo server was already running. To fix it, I fired up mongod command again, and it automatically referenced to C:\data\db.

Other users have suggested to add C:\data\db but did not talk about executing mongod again, which exactly solved my problem.


if all the solution above doesn't work out perhaps then this might be one to help. Somewhere down the line you may have made connection to your local mongodb database via vagrant boxes.

  1. vagrant up and then ssh into your vagrant machine in which you've made connection with mongodb (vagrant ssh vagrant_box_name)
  2. comment out the bind_ip line from /etc/mongod.conf using # (sudo nano /etc/mongod.conf )
  3. restart your mongodb daemon service (sudo service mongod restart) voila...

@shakthydoss answer worked fine once, but after the second issue the .lock wasn't there, I just created a blank one, and it worked fine. So check if yours ain't there.

If you are using the command line:

cd /var/lib/mongodb

ls

"ls" will list all the files in the folder, if the mongod.lock isn't there, then:

sudo touch mongod.lock

Finally run command.

mongod –-repair

sudo service mongod start 

Mongo service should be working fine.


I had same problem to connect mongodb after install using brew on macOS.

The problem was also mongod.lock but before i had mongodb 3.6 installed and database directory was /usr/local/var/mongodb and it have old files and mongod.lock

Simple i moved my old database files to different folder and removed everything from /usr/local/var/mongodb

Then restarted :

brew services restart mongodb

And it's working fine now.


Remove mongod.lock file. And run "mongod -repair". uninstall/reinstall mongod service fixed that problem for me.

Thanks.


I had the same error when connecting to Mongo on AWS EC2 . This is what solved it https://serverfault.com/a/347159/62381 Remove the bind_ip from the config file


This work me:-

In Mongo 3.2 for window, you should start Mongodb service. So, run the Command Prompt as Administrator then net start MongoDB


Finally I got this is in a simple way..

open terminal and go to the mongodb location. In my case it is

e:\mongodb\bin> 

and type the following command and press enter..

mongod --config e:\mongodb\mongo.config

Open another terminal and start the mongodb using

mongo.exe

Thats it.. you can use mongo


This is an old question, but, as a newbie I figured I'd add that (using Webstorm) you need to click on Mongo Explorer (tab on far right hand side of your window). From there:

-Click settings. -Click browse button (looks like a button with "..." on it). -Go to Program Files > MongoDB > Server > 3.4 > bin > mongo.exe (your version maybe different than 3.4) -After that, click the green plus sign on the right. A window will open -Enter a name in "Label" slot. -Click apply.

You should now be connected. Entering "mongod" in the terminal isn't enough. You have to do the above steps also.

My apologies in advance to those of you who aren't using Webstorm! Not sure about the steps using other IDE's.


if u install by brew (on osx) first run sudo mkdir /data/db start mondoDB Daemon by typing mongod (leave it open) and then run mongo by typing mongo in new terminal tab


Simply create a folder named "data" in C drive and inside data folder create another folder named "db". Then execute mongod.exe :)


First, you have to start mongod server then after in another terminal you have to start mongo shell.

For starting, mongo server

1. If you path is Default path (data/db) simple fired mongod in terminal

2. If your path is not data/db then you command like as follow: mongod --dbpath 'here your path comes' .

For starting mongo shell, Simply fired mongo in another terminal

If you get this waiting for connections on port 27017, then your mongo successfully started.

Hope you can get my point


i had same problem, i have deleted E:\Mongo Data Files\db\mongod.lock file, so it started working. the problem is due to improper shutdown of server. so lock file is not clean.

참고URL : https://stackoverflow.com/questions/13312358/mongo-couldnt-connect-to-server-127-0-0-127017

반응형