转载
This evening I tried to connect to my MongoDB instance using the command line mongo tool and got the following error message: Error: couldn't connect to server 127.0.0.1} (anon):1137
. It turns out that the server wasn't running due to an improper shutdown at some point in the past. Here's what you need to do to fix it.
Note: my instructions are specific to Ubuntu 10.04 (& probably other versions of Ubuntu).
Why Won't MongoDB Start?
One of the lame things about MongoDB is that it doesn't handle a crash on it's own very well. If the database crashes or otherwise doesn't shut down properly, then the next time you try to start it, you'll get a nice error saying that there is an old lockfile and that you probably need to remove it and run mongod --repair. However, on my laptop running Ubuntu 10.04, I ran into a few confusing things that I'd like to share, hopefully to save someone else out there some time.
Symptoms
Instructions To Get MongoDB Up Again
- Manually remove the lockfile:
sudo rm /var/lib/mongodb/mongod.lock
- Run the repair script:
sudo -u mongodb mongod -f /etc/mongodb.conf --repair.
|
- You must run this command as the mongodb user. If you run it as root, then root will own files in /var/lib/mongodb/ that are necessary to run the mongodb daemon and therefore when the daemon trys to run later as the mongodb user, it won't have permissions to start. In that case you'll get this error:
Unable to create / open lock file for lockfilepath: /var/lib/mongodb/mongod.lock errno:13 Permission denied, terminating
.
- On Ubuntu, you must specify the configuration file /etc/mongodb.conf using the -f flag. Otherwise it will look for the data files in the wrong place and you will see the following error:
dbpath (/data/db/) does not exist, terminating
.
- Now you can start your MongoDB server with
sudo start mongodb
and verify it is running with sudo status mongodb
and by trying to connect to it with mongo test
.
相关推荐
MongoDB权威指南:MongoDB:The Definitive Guide第一版 第二版 中、英文4本合集
课时1:MongoDB数据库入门.mp4 课时2:MongoDB数据数据查询与分析.mp4 课时3:MongoDB数据库核心知识.mp4 课时4:MongoDB数据库管理备份.mp4 课时5:MongoDB开发实战:开发博客应用.mp4 课时6:MongoDB数据库性能...
MongoDB on Kubernetes技术解决方案.pptx
MongoDB程序员认证: MongoDB Certified Developer Study Guide - Study Guide - Exam Preparation - Practise Questions
MongoDB应用设计模式:MongoDB Applied Design Patterns 中英文打包两本合集
day1:MongoDB数据库与其他数据库区别介绍及学习方法 day2:MongoDB运行环境搭建及运行 day3:MongoDB增删改查操作实践 day4:教你学会MongoDB聚合...day12:MongDB数据库常见故障及解决方案 day13:在以后工作中应用的注意点
M001: MongoDB Basics https://university.mongodb.com/courses/M001/2022_May_10/completion
MongoDB实战:MongoDB in Action第一、二版 中、英文合集
MongoDB的强事务解决方案.pdf
mongodb 复制集搭建实例 博客介绍https://blog.csdn.net/weixin_42749765/article/details/82143616
mongodb-windows安装包: mongodb-compass-1.31.2-win32-x64.msi 打开直接安装
赠送jar包:mongodb-driver-core-4.2.3.jar; 赠送原API文档:mongodb-driver-core-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-core-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-core-4.2.3....
赠送jar包:mongodb-driver-sync-4.2.3.jar; 赠送原API文档:mongodb-driver-sync-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-sync-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-sync-4.2.3....
MongoDB数据库
第二课:MongoDB企业级应用操作1
定向爬虫:MongoDB与Scrapy-v11源码
主流NoSQL数据库全方位评测:MongoDB
赠送jar包:mongodb-driver-core-4.2.3.jar; 赠送原API文档:mongodb-driver-core-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-core-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-core-4.2.3....
MEAN架构编程开发。全栈开发之道:MongoDB Express AngularJS Node.js
赠送jar包:mongodb-driver-sync-4.2.3.jar; 赠送原API文档:mongodb-driver-sync-4.2.3-javadoc.jar; 赠送源代码:mongodb-driver-sync-4.2.3-sources.jar; 赠送Maven依赖信息文件:mongodb-driver-sync-4.2.3....