Reputation: 1623
I've installed the mongodb 2.0.3, using the mongodb-10gen debian package. Everything went well, except the service which is installed by default is not starting up when computer starts. The mongod
is running only as root user. maybe this is the reason. but as far as I know, the services should be running since they are added by the root user.
What may be the solution?
if I run just mongod
Tue Mar 27 13:00:44 [initandlisten] couldn't open /data/db/transaction_processor_dummy_development.ns errno:1 Operation not permitted
If I run sudo service mongodb start
it says:
mongodb start/running, process 4861
but there's no process when looking with htop
and mongo
says:
MongoDB shell version: 2.0.3
connecting to: test
Tue Mar 27 13:02:40 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
Upvotes: 88
Views: 395477
Reputation: 801
In my case the mongodb
directory inside /var/lib
and /var/log
was missing.
I traced this from the syslog
and journalctl
logs.
Creating the mongodb
directory in the respective folders and changing the ownership to MongoDB user has fixed the issue.
Make sure to run sudo systemctl restart mongod.service
after the above steps.
YW!
Upvotes: 0
Reputation: 1280
I have another situation where removing the lock file does not work.
And I solved it with:
systemctl stop mongod
chown -R mongodb:mongodb /var/lib/mongodb
systemctl start mongod
Where you replaced the second line chown -R mongodb:mongodb /var/lib/mongodb
to chown -R mongodb:mongodb {your mongodb file location}
Upvotes: 0
Reputation: 72
add this line in .bash_profile
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
then run source .bash_profileenter code here
Upvotes: 0
Reputation: 10132
In Fedora 35, I had to delete /tmp/mongodb-27017.sock
file to have it run successfully.
You may check the logs to confirm your issue sudo less /var/log/mongodb/mongod.log
Upvotes: 0
Reputation: 942
Here's a weird one, make sure you have consistent spacing in the config file.
For example:
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: 'enabled'
If the authorization key has 4 spaces before it, like above and the rest are 2 spaces then it won't work.
Upvotes: 0
Reputation: 43626
Removing the .lock
file and reinstalling did not solve the issue on my machine (Ubuntu 19.10). The problem was that after unexpected shutdown, the MongoDB sock does not belong to the MongoDB group and user anymore.
So, I follow the steps below:
Change the user:group permission:
chown mongodb:mongodb <YOUR_SOCK>
sudo systemctl start mongod
Upvotes: 18
Reputation: 4739
I had struggled with the similar issue and sharing the solution accordingly. We use a mongo replica set and mongo service on my secondary server was taking too long to start. (approx 10-15 minutes)
Couldn't find anything until attempted to configure the mongo with some different folder in --dbpath And that worked fine, so we got to know that the earlier path, which was a mount directory had some issues. So followed with nss team to get the network mount issue solved.
Hope this helps someone
Upvotes: 1
Reputation: 151916
What helped me diagnose the issue was to run mongod
and specify the /etc/mondgob.conf
config file:
mongod --config /etc/mongodb.conf
That revealed that some options in /etc/mongdb.conf were "Unrecognized". I had commented out both options under security:
and left alone only security:
on one line, which caused the service to not start. This looks like a bug.
security:
# authorization: enabled
# keyFile: /etc/ssl/mongo-keyfile
^^ error
#security:
# authorization: enabled
# keyFile: /etc/ssl/mongo-keyfile
^^ correctly commented.
Upvotes: 2
Reputation: 7172
Recall that according to official MongoDB documentation, the right command to start the service is (@Ubuntu): sudo service mongod start
(06/2018) (no mongodb
or mongo
).
Reference: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
Upvotes: 3
Reputation: 2342
I had issue that starting the service mongodb failed, without logs. what i did to fix the error is to give write access to the directory /var/log/mongodb for user mongodb
Upvotes: 2
Reputation: 9
Install mongodb for ubuntu 14.04
sudo nano /etc/apt/sources.list.d/mongodb-org-3.2.list
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.10 mongodb-org-server=3.2.10 mongodb-org-shell=3.2.10 mongodb-org-mongos=3.2.10 mongodb-org-tools=3.2.10
Upvotes: 0
Reputation: 4501
I was bored of this problem so I decided to create a shell script to restore my mongo data base easily.
#!/bin/sh
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
Upvotes: 28
Reputation: 2446
I took a different approach:
Background: I use mongodb, single node, local to my server, as a staging area.
I installed mongo based on instructions available in MongoDB docs.
So, this is not 'prime' infrastructure, does not need to be up all the time - but still essential.
What I do: In my run script, I check if mongo is running using -
if pgrep "mongod" >/dev/null 2>&1
If it is not running, then I run
sudo mongod &
Been working like a charm, no setup etc.
If your use case is similar, let me know if it works for you too.
Good luck!
Upvotes: 2
Reputation: 1011
Please check your permissions for "data" folder. This is a permission issue, as linux users will face this issue due to SE linux permissions. So you change the ownerand group both to "mongodb" for the "data" folder
Upvotes: 4
Reputation: 1051
This can also happen if your file permissions get changed somehow. Removing the lock file didn't help, and we were getting errors in the log file like:
2016-01-20T09:14:58.210-0800 [initandlisten] warning couldn't write to / rename file /var/lib/mongodb/journal/prealloc.0: couldn't open file /var/lib/mongodb/journal/prealloc.0 for writing errno:13 Permission denied
2016-01-20T09:14:58.288-0800 [initandlisten] couldn't open /var/lib/mongodb/local.ns errno:13 Permission denied
2016-01-20T09:14:58.288-0800 [initandlisten] error couldn't open file /var/lib/mongodb/local.ns terminating
So, went to check permissions:
ls -l /var/lib/mongodb
total 245780
drwxr-xr-x 2 mongodb mongodb 4096 Jan 20 09:14 journal
drwxr-xr-x 2 root root 4096 Jan 20 09:11 local
-rw------- 1 root root 67108864 Jan 20 09:11 local.0
-rw------- 1 root root 16777216 Jan 20 09:11 local.ns
-rwxr-xr-x 1 mongodb nogroup 0 Jan 20 09:14 mongod.lock
To fix:
# chown -R mongodb:mongodb /var/lib/mongodb
Remove the lock file if it's still there:
# rm /var/lib/mongodb/mongod.lock
Start mongodb
# service mongodb start
Tail the log and you should see at the end of it:
tail -f /var/log/mongodb/mongodb.log
2016-01-20T09:16:02.025-0800 [initandlisten] waiting for connections on port 27017
Upvotes: 38
Reputation: 2342
For ubunto , what made it happen and was real simple is to install mongodb package:
sudo apt-get install mongodb
Upvotes: 4
Reputation: 5545
This can also happen if the disk is full at your logpath
path (e.g. if you have a dedicated /log/
directory/drive and it is full).
This had me panicking for a good 15 minutes because it also prevents you from reading the mongod.log
when starting the process, so difficult to troubleshoot.
Upvotes: 3
Reputation: 598
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
sudo service mongodb start
Upvotes: 6
Reputation: 1336
1 - disable fork
option in /etc/mongodb.conf
if enabled
2 - Repair your database
mongod --repair --dbpath DBPATH
3 - kill current mongod process
Find mongo processes
ps -ef | grep mongo
you'll get mongod PID
mongodb PID 1 0 06:26 ? 00:00:00 /usr/bin/mongod --config /etc/mongodb.conf
Stop current mongod process
kill -9 PID
4 - start mongoDB service
service mongodb start
Upvotes: 13
Reputation: 631
Nianliang's solution turned out so useful from my Vagrant ubunuto, thart I ended up adding these 2 commands to my /etc/init.d/mongodb file:
.
.
.
start|stop|restart)
rm /var/lib/mongodb/mongod.lock
mongod --repair
.
.
.
Upvotes: 3
Reputation: 3066
On my ubuntu server, just run:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
Upvotes: 131
Reputation: 2170
just re-installed mongo and it worked. No collections lost. Easiest solution atleast for me
Upvotes: 3
Reputation: 1623
Fixed!
The reason was the dbpath
variable in /etc/mongodb.conf
.
Previously, I was using mongodb 1.8, where the default value for dbpath was /data/db
.
The upstart job mongodb
(which comes with mongodb-10gen package) invokes the mongod
with --config /etc/mongodb.conf
option.
As a solution, I only had to change the owner of the /data/db
directory recursively.
Upvotes: 37
Reputation: 3105
Remember that when you restart the database by removing .lock files by force, the data might get corrupted. Your server shouldn't be considered "healthy" if you restarted the server that way.
To amend the situation, either run
mongod --repair
or
> db.repairDatabase();
in the mongo shell to bring your database back to "healthy" state.
Upvotes: 16