如何重启/删除mongod的实例?

时间:2016-01-24 14:54:30

标签: mongodb

其他SO帖子已经涵盖了这一点,但不幸的是,这些解决方案无效。

如何重启/删除mongod实例?

输入

$ mongod

我收到以下错误:

2016-01-24T09:49:19.557-0500 I CONTROL  [initandlisten] MongoDB starting : pid=43675 port=27017 dbpath=/data/db 64-bit host=NAME-MacBook-Pro.local
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] db version v3.0.8
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] build info: Darwin NAME-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] allocator: system
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] options: {}
2016-01-24T09:49:19.558-0500 E NETWORK  [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2016-01-24T09:49:19.558-0500 E NETWORK  [initandlisten]   addr already in use
2016-01-24T09:49:19.558-0500 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-01-24T09:49:19.558-0500 I CONTROL  [initandlisten] dbexit:  rc: 100

我明确地给了自己

的权限
sudo chown -R <USERNAME> /data/db

这没有用。

我试图完全删除目录

sudo rm -rf /data/db

并重新创建

mkdir -p /data/db

但不幸的是,这不起作用。

我认为解决方案是删除文件/data/db/mongod.lock,但它不存在:

rm /data/db/mongod.lock

还有什么我应该尝试的吗?

编辑:使用mongod --port 12345运行不同的端口后,当我使用use admin然后使用db.shutdownServer()时,我收到以下错误:

2016-01-24T10:32:25.039-0500 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-01-24T10:32:25.039-0500 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok
2016-01-24T10:32:25.040-0500 I NETWORK  DBClientCursor::init call() failed
server should be down...

编辑2:

重新启动机器什么都不做。我尝试使用mongod --port 27017访问默认端口,然后

> use admin
> db.shutdownServer() 

我得到了输出:

2016-01-25T12:05:32.163-0500 I NETWORK  DBClientCursor::init call() failed
server should be down...
2016-01-25T12:05:32.166-0500 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-01-25T12:05:32.166-0500 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2016-01-25T12:05:32.166-0500 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed

1 个答案:

答案 0 :(得分:0)

在日志中说:

2016-01-24T09:49:19.558-0500 E NETWORK  [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2016-01-24T09:49:19.558-0500 E NETWORK  [initandlisten]   addr already in use

这意味着该端口已被另一个进程或另一个mongo实例使用。

您应该为此实例使用另一个端口。

Refer to this link