• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

mongodb Asio socket.set_option error

23.02.07 02:07 작성 23.02.07 02:10 수정 조회수 596

0

안녕하세요.

개정 3판 Node.js 교과서 8-6 몽구스 실전 프로젝트에서 처음 프로젝트를 시작할 시, cd ch8/8.6/learn-mongoose 하여 폴더에 들어간 이후 npm start 에서 막혔습니다. terminal 상으로는 돌아가지만, localhost:3002로 접속했을때, 제대로 접속되지 않고 로딩창만 뜹니다.

저는 현재, intel MAC, Vertura 13.1 버전 쓰고 있으며, 노드 JS는 v18.12.1, mongodb는 6.0.4버전 쓰고있습니다.

에러 메세지는 다음과 같습니다.

몽고디비 연결 에러 MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at Connection.openUri (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/connection.js:825:32)
at /Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:409:10
at promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/helpers/promiseOrCallback.js:11:14)
at Mongoose._promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:1262:10)
at Mongoose.connect (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:408:20)
at connect (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/schemas/index.js:7:12)
at Object.<anonymous> (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/app.js:18:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}

 

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 를 구글링하여 몇가지를 시도해봤는데,

1번째, MONGO_URI=mongodb://localhost:27017/blog 를 MONGO_URI=mongodb://127.0.0.1:27017/blog 로 바꾸어 해결한 사례가 있어 ch8/8.6/learn-mongoose/schemas 폴더의 index.js에서mongoose.connect('mongodb://root:1234@localhost:27017/admin' 를 mongoose.connect('mongodb://root:1234@127.0.0.1:27017/admin', 로 바꾸었지만, → 해결되지 않았습니다.

2번째, terminal에 mongod를 쳐서 error가 난 부분을 살펴보니,

{"t":{"$date":"2023-02-07T00:55:42.260+09:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-02-07T00:55:42.263+09:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2023-02-07T00:55:42.280+09:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2023-02-07T00:55:42.285+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":64400,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"iMac.local"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.4","gitVersion":"44ff59461c1353638a71e710f385a566bcd2f547","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.2.0"}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":1126}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F",  "c":"ASSERT",   "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

이 부분에서, 에러인 부분인

{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}

이 부분이 에러일 것같다는 생각에, 구글링을 하던 중

/tmp/mongodb-27017.sock 파일의 접근권한을 변경하거나 파일 삭제 후 서비스를 재시작하면 정상적으로 mongodb가 부팅된다.

는 글을 보고, sudo rm -rf /tmp/mongodb-27017.sock로 sock 파일을 삭제해봤지만, 똑같은 결과였습니다.

ls -l /tmp/mongodb-27017.sock로 확인했을때, 삭제된 것도 확인했습니다.

3번째, terminal에 brew services list 로 mongodb상태를 확인해보려고 하였습니다.

Name              Status     User File
mongodb-community error  512 jisu ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql             none            
postgresql@14     none    

로 나오는 것을 보아 mongodb가 제대로 작동되지 않고 있어서 에러가 발생하는 것으로 추측했습니다.

 brew services start mongodb-community

의 결과로,

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/jisu/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.

가 나와서, 이를 해결하기 위해 mongodb-community를 완전히 지우고, brew cleanup까지 한 다음 다시 깔아봤지만 달라진 바는 없었습니다. 이전 강좌까지 mongodb에서 데이터베이스 생성하는 CRUD 실습할때까지만 해도 문제없었는데, 갑자기 에러를 벹어내네요.. 3일동안 이 문제를 해결하려 힘써봤는데 도저히 감이 안잡혀서 질문드립니다.

 

답변 1

답변을 작성해보세요.

0

sudo mongod로 실행하시면 permission 문제 안 나지 않나요?