Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
sudo mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
Step 4: Check status of mongodb.
sudo status mongodb
or
sudo service mongodb status
Step 5: Start mongo console.
mongo
但我也试了,却没有解决...
卸载之前装的mongodb:
sudo apt-get purge mongodb-org
sudo apt-get autoremove
Remove the old mongodb.list you created:
sudo rm /etc/apt/sources.list.d/mongodb.list
sudo apt-get autoremove
Remove the old mongodb.list you created:
sudo rm /etc/apt/sources.list.d/mongodb.list
准备重新安装,由失败到成功,整理了一下:
1、执行命令 sudo apt-get install mongodb-server
2、进入目录 vim ~/.bashrc
3、添加此句:export PATH=/home/yhl/mongodb-linux/bin:$PATH
4、mongod -version 查看版本号
5、mkdir data
6、mkdir log
7、mongod --dbpath data/ --logpath log/mongodb.log -logappend --fork
8、mongo 查看shell脚本
9、echo "mongod --dbpath data/ --logpath log/mongodb.log -logappend --fork">> start.sh //该语句是将启动命令保存在start中,方便下次启动使用
(亲测成功)
二、补充一下之前遇到的问题:
1、
sudo service mongod start
Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.
添加以下内容: