SocketException: 地址已经在使用 MONGODB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47975929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SocketException: Address already in use MONGODB
提问by Agung Maha
i found this error when trying to run mongodb. I install it via homebrew. Please assist
我在尝试运行 mongodb 时发现了这个错误。我通过自制软件安装它。请协助
Agungs-MacBook-Pro:~ agungmahaputra$ mongod
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] MongoDB starting : pid=5189 port=27017 dbpath=/data/db 64-bit host=Agungs-MacBook-Pro.local
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] db version v3.6.0
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] allocator: system
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] modules: none
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] build environment:
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] distarch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] target_arch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] options: {}
2017-12-26T15:31:15.911+0700 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] now exiting
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] shutting down with code:48
Agungs-MacBook-Pro:~ agungmahaputra$
回答by Balasubramani M
You can kill the previous mongodinstance and start the new one.
您可以杀死前一个mongod实例并启动新的实例。
To kill the previous mongod instance, first search for a list of tasks running on your machine by typing,
要杀死之前的 mongod 实例,首先通过键入以下命令搜索在您的机器上运行的任务列表,
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMANDand its PIDand type,
搜索 mongod COMMAND及其PID和类型,
sudo kill <mongo_command_pid>
Now start your mongod instance by typing,
现在输入以下命令启动您的 mongod 实例,
mongod
You can see MongoDB running successfully.
可以看到MongoDB运行成功。
回答by Tony Roczz
You already have a process running in the port 27017
which is used by mongodb
. So either you need to stop the process in that port or try with different port number.
你已经在该端口运行的进程27017
,其使用mongodb
。因此,您要么需要停止该端口中的进程,要么尝试使用不同的端口号。
Try mongod --port 27018
尝试 mongod --port 27018
You can change the port number of your choice.
您可以更改您选择的端口号。
EDIT:
编辑:
You can also just stop all the running instances of mongo server using
sudo killall mongod
as mentioned by @Dassi Orleando in the comments.
And run mongod
您也可以使用sudo killall mongod
@Dassi Orleando 在评论中提到的方式停止所有正在运行的 mongo 服务器实例
。并运行mongod
回答by sh6210
if you're using mongodb version 4.*
如果您使用的是 mongodb 版本 4.*
in default settings, there should be a "db" folder "/data/db" having the necessary permission.
在默认设置中,应该有一个具有必要权限的“db”文件夹“/data/db”。
to check it the MongoDB service started
检查它 MongoDB 服务已启动
brew services list
if not then run
如果没有然后运行
brew services start mongodb
run mongoinstead of mongod
运行mongo而不是mongod
回答by bisma
First, shutdown the running server using:
首先,使用以下命令关闭正在运行的服务器:
mongod --shutdown
Then run:
然后运行:
sudo mongod
回答by crifan
Summary other(@Tony Roczz
, @Balasubramani M
) answer to here:
总结 other( @Tony Roczz
, @Balasubramani M
) 对这里的回答:
Root Cause
根本原因
error: Failed to set up listener: SocketException: Address already in use
错误: Failed to set up listener: SocketException: Address already in use
means:
方法:
- previously have run mongodb
- probablyuse default port
27017
- probablyuse default port
- 以前运行过mongodb
- 可能使用默认端口
27017
- 可能使用默认端口
Solution
解决方案
(most case) kill and restart mongod
(大多数情况下)杀死并重新启动 mongod
kill mongod
杀死蒙戈
two method:
两种方法:
- use killall
killall mongod
- kill by PID
- find mongod PID
- method 1:
ps aux | grep mongod
- output can see like this:
limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
- method 2:
lsof -iTCP -sTCP:LISTEN -n -P
- output can see like this:
mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
- method 1:
- kill by PID:
kill -9 425
- find mongod PID
- 使用killall
killall mongod
- 通过PID杀死
- 找到mongod PID
- 方法一:
ps aux | grep mongod
- 输出可以是这样的:
limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
- 方法二:
lsof -iTCP -sTCP:LISTEN -n -P
- 输出可以是这样的:
mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
- 方法一:
- 通过PID杀死:
kill -9 425
- 找到mongod PID
re-start mongod
重新启动mongod
- most case:
mongod
- some special case
brew services start mongodb-community
- for install community version in Mac by:
brew install mongodb-community
- for install community version in Mac by:
- 大多数情况:
mongod
- 一些特殊情况
brew services start mongodb-community
- 通过以下方式在 Mac 中安装社区版本:
brew install mongodb-community
- 通过以下方式在 Mac 中安装社区版本:
(for some people) run with another port
(对于某些人)与另一个端口一起运行
- run with another port:
mongod --port 27018
- onlyfor those want to run multiple mongod server same time
- 使用另一个端口运行:
mongod --port 27018
- 仅适用于那些想要同时运行多个 mongod 服务器的人
Additional Note
附加说明
which port the running mongodb is using?
正在运行的 mongodb 正在使用哪个端口?
lsof -iTCP -sTCP:LISTEN -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 425 limao 10u IPv4 0xab744305e75263cf 0t0 TCP 127.0.0.1:27017 (LISTEN)
can see 27017
is current running mongodb port.
可以看到27017
当前正在运行的 mongodb 端口。
how to check / make sure mongod is running
如何检查/确保 mongod 正在运行
- check mongod status:
ps aux | grep mongod
- output can see
mongod
service
- output can see
brew services list
- if installed by
brew
and start bybrew
- if installed by
- 检查 mongod 状态:
ps aux | grep mongod
- 输出可以看到
mongod
服务
- 输出可以看到
brew services list
- 如果安装
brew
并启动brew
- 如果安装
回答by jtvdw
After running this commands below:
运行以下命令后:
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
搜索 mongod COMMAND 及其 PID 和类型,
sudo kill <mongo_command_pid>
And restarting mongod, it still fails with the same error "SocketException: Address already in use MONGODB".
并重新启动 mongod,它仍然失败并显示相同的错误“SocketException:地址已经在使用 MONGODB”。
Server was restarted yesterday and then this happened.
服务器昨天重新启动,然后发生了这种情况。
回答by Agustín Marí
I solved it pasting the command below into the command line in order to close mongo's server.
我解决了它,将下面的命令粘贴到命令行中以关闭 mongo 的服务器。
sudo pkill -f mongod
"sudo" (Super User Do) runs the command admin permissions, so it will ask you for your user password
“sudo”(超级用户 Do)运行命令管理员权限,所以它会询问你的用户密码
回答by Jasmeet Singh Chhabra
Make Sure the error is of the port , if using macos catalina there is a reported issue for ~/data/db which also causes this.
确保错误出在端口上,如果使用 macos catalina,则会报告 ~/data/db 的问题,这也会导致此问题。
回答by Khushwant kodecha
Just this single command
只是这个单一的命令
sudo pkill -f mongod
sudo pkill -f mongod
回答by AD Rai
This may sound obvious but you should check if mongodb is already running. So instead of first starting the the DB by running:
这听起来很明显,但您应该检查 mongodb 是否已经在运行。因此,而不是首先通过运行启动数据库:
sudo mongod
Try directly running:
直接运行试试:
mongo