Failed to set up listener: socketexception: address already in use

error log

2018-06-08T22:25:09.118+0800 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use
2018-06-08T22:25:09.118+0800 I CONTROL  [initandlisten] now exiting
2018-06-08T22:25:09.118+0800 I CONTROL  [initandlisten] shutting down with code:48

error cause

error, error log has been clear, ‘Address already in use’ has a process has been running in the port. So we’re going to find this process and turn it off.

PID(Process Identification) operating system refers to the Process Identification number. Each time the operating system opens a program, it creates a process ID, or PID. Each process has a unique PID number, which is assigned by the process runtime system and does not represent a dedicated process. The PID does not change the identifier at run time, but after the process terminates the PID identifier is retrieved by the system and may be assigned to the newly run program.

solution

find the PID number that was run before mongo, turn it off, and re-enter the start command

songrenqingdeMacBook-Pro:bin songrenqing$ lsof -i :27017
COMMAND   PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  61316 songrenqing   11u  IPv4 0xacda8b230bc07883      0t0  TCP localhost:27017 (LISTEN)
songrenqingdeMacBook-Pro:bin songrenqing$ kill -9 61316

or use another process ID, previously 27017, now specify 27018, so there will be no conflict

mongod --port 27018

Read More: