mongodb - 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
推荐阅读
- c++ - QT - 将 QPushButtons 与 QCheckBoxes 连接
- php - PHP OAuth 错误处理
- ios - 如何修复 AWSCore (AWS-sdk-ios) 中的 [AWSTask 异常] 崩溃
- php - 无法在指定的语言环境中显示验证错误
- mysql - mysql查询某天fk不存在的地方
- flutter - 颤振构建错误。Flutter webview插件的问题
- ubuntu - 安装 OpenMPI:C C++ 编译器不兼容链接
- r - 闪亮的传单地图在切换输入时呈现两次
- android - IntentService 在执行程序中丢失了工作
- javascript - JQuery, $(...).sortable 不是函数