mongod 启动报错:Failed to set up listener: SocketException: Address already in use

2,612 阅读1分钟

mongod启动报错

$ mongod -dbpath .
2020-03-15T20:41:17.048+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] MongoDB starting : pid=41378 port=27017 dbpath=. 64-bit host=YIQIWANG-MB1
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] db version v4.0.3
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] allocator: system
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] modules: none
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] build environment:
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten]     distarch: x86_64
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2020-03-15T20:41:17.058+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "." } }
2020-03-15T20:41:17.059+0800 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-03-15T20:41:17.059+0800 I CONTROL  [initandlisten] now exiting
2020-03-15T20:41:17.059+0800 I CONTROL  [initandlisten] shutting down with code:48

解决方案:

$ lsof -i:27017
COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  39218 melody   10u  IPv4 0xedc9a298711e1655      0t0  TCP localhost:27017 (LISTEN)

$ kill -9 39218

$ lsof -i:27017
// nothing