본문 바로가기
Back Side/DBMS > MongoDB

[MongoDB] Error: couldn't connect to server 127.0.0.1:27017 오류해결

by developerBeluga 2022. 7. 8.
728x90
반응형

 

 

 

트랜잭션을 위해 로컬에서 리플리카셋을 구성하면서 이거저거 건들다가 어느순간 mongo가 안되기 시작했다 🤯

mongo

터미널에 mongo로 치니깐

(혹시 서버를 운영 중이었다면 터미널에서 err 나오거나 robo3t에도 접속 ㄴㄴ)

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 :: Connection refused :

라는 오류 메세지가 나왔다.

 

mongod

다시 터미널에 mongod를 쳐봤다.

어마어마한 글들이 나왔는데 잘 찾아보면

"msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"

라는 메시지가 보인다.

 

 

1) 서비스 목록 확인하기

brew services list

현재 서비스의 상태를 확인하기 위해 위 코드를 터미널에 쳐보자.

 

mongodb-community status error 3584가 나왔다.

오케.. 우선 에러가 나왔다는 것을 알겠다.

(혹시 mongodb-community status가 stopped라면 바로 3번으로 가시길 )

 

 

2) 소유권 확인 및 파일 제거

// 소유권 확인
ls -l /tmp/mongodb-27017.sock
// 잘되면 srwx------  1 root  wheel  0  7  7 18:22 /tmp/mongodb-27017.sock 이런 형식이 나옴

// 파일 삭제
sudo rm -rf /tmp/mongodb-27017.sock

 

차례대로 터미널에 쳐주면 된다.

 

 

3) 서비스 다시 시작해주기

// 다시 서비스 시작
brew services restart mongodb-community

서비스 다시 시작해준다.

 

 

Bootstrap failed: 5: Input/output error

라는 에러를 만나게 되었다.

(거즘 에러란 에러는 다 만나고 있는 중 😇 )

 

brew services restart mongodb/brew/mongodb-community

이럴 경우 이렇게 똑바로 경로를 적어주면 된다.

그러면 이렇게 성공하였다는 메시지를 보게 될 것이다.

 

 

4) 마지막 확인

brew services list

터미널에 위 코드를 쪄서 mongodb-communtiy가 잘 돌아가고 있는지 확인한다.

오~ 처음과 달리 status가 started이고 연결도 잘되서 mongo라고 쳐도 잘 나온다.

 

 

 

 

참고

https://www.mongodb.com/community/forums/t/help-brew-mongodb-community-5-0-error-macos/125648/3

 

HELP: Brew mongodb-community@5.0 error [MacOS]

@Stennie Thank you for the quick reply. This is what I for opt/homebrew: {"t":{"$date":"2021-09-27T13:37:42.239+09:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDon

www.mongodb.com

 

 

 

 

728x90
반응형

댓글