MongoDB存储问题(9001已经在使用中)



在尝试运行该命令时出现此错误mongod --dbpath=/var/lib/mongodb

{"t":{"$date":"2021-01-23T11:23:41.733-07:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2021-01-23T11:23:41.733-07:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"/var/lib/mongodb"}}}}
{"t":{"$date":"2021-01-23T11:23:41.734-07:00"},"s":"E",  "c":"STORAGE",  "id":20568,   "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}

我知道问题是"attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}

但是我不知道如何解决这个问题?

我尝试了另一个SO帖子的其他建议,说要杀死进程并重新启动。我这样做了,但它对我不起作用。

我还尝试在不同的端口上运行mongod

mongod --dbpath=/var/lib/mongodb --port 27019

给出了这个错误

{"t":{"$date":"2021-01-23T11:27:29.535-07:00"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongodb"}}

这是一个只读目录所以我输入

sudo chmod -R 777 /var/lib/mongodb

然后我在日志

中得到这个错误
"ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"DBPathInUse: Unable to lock the lock file: /var/lib/mongodb/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /var/lib/mongodb directory"}}

所以我试着找出哪个其他进程正在运行

ps -eaf | grep mongod
mongodb   722732       1  0 11:09 ?        00:00:10 /usr/bin/mongod --config /etc/mongod.conf
srt       725772  720106  0 11:34 pts/2    00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mongod

但我不知道接下来该怎么办。

您已经使用默认的/etc/mongod.conf文件运行了默认的自动启动mongod实例您可以通过以下命令停止此实例:

service mongod stop

kill -2 722732

mongo --port 27017
>use admin
>db.shutdownServer()

systemctl stop mongod

你可以根据需要修改/etc/mongod.conf文件,然后用

重新启动它
service mongod start

或:

systemctl start mongod   

我使用sudo mongod然后我得到这个错误,现在我输入**sudo pkill -f mongod **来消除这个错误,它工作了,

现在又可以使用sudo mongod来工作了。

sudo pkill -f mongod 
sudo mongod

这解决了我的问题在我的ubuntu 22.04系统

最新更新