启动 mongo db 时出现此错误:无法设置侦听器:SocketException:地址已在使用中

Var*_*hal 4 mongodb

我最近开始使用 mongoDB,并一次又一次地遇到这个问题。我想我错过了一些东西,但不知道问题出在哪里。我正在开发最新的 mongo db 版本 4.0.1。

iron@iron-System-Product-Name:/media/iron/1d6c195f-2350-423c-a3f0-0500c92e580a/codesnippets$ sudo mongod --dbpath db
2018-08-24T09:30:26.351+0530 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] MongoDB starting : pid=5994 port=27017 dbpath=db 64-bit host=iron-System-Product-Name
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] db version v4.0.1
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] modules: none
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] build environment:
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten]     distarch: x86_64
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] options: { storage: { dbPath: "db" } }
2018-08-24T09:30:26.354+0530 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] now exiting
2018-08-24T09:30:26.354+0530 I CONTROL  [initandlisten] shutting down with code:48
Run Code Online (Sandbox Code Playgroud)

小智 8

  • sudo lsof -iTCP -sTCP:LISTEN -n -P
  • sudo kill <mongo_command_pid>
  • mongod

尝试这三个命令,你一定会摆脱困境。