Mongod starting error (errno 45) : Unable to lock file - mongodb

When I try to start mongod with the following command:
mongod --dbpath data/db
I get the following error:
[initandlisten] exception in initAndListen: 98 Unable to lock file:
data/db/mongod.lock errno:45 Operation not supported. Is a mongod instance
already running?, terminating
but when I use the ps command line, I don't see any running mongod instance.
I have tried to:
delete the whole directory data/ and recreate the path data/db
change the rights of the file mongod.lock
But none of these worked.
Any idea of what I should do? Thanks

Not All File systems support locking, Are you by any chance using NFS?
could you add FS type, mount options and permissions for your data folder?

Related

How to repair MongoDb when someone deleted one database directory from the db directory?

One guy deleted one Database directory from the dbpath of MongoDb as we configured --directoryperdb.
Is there any option to ignore that database and I can start the server. Currently mongod --repair giving
2020-04-22T15:19:56.118+0000 E STORAGE [initandlisten] WiredTiger error (2) [1587568796:118648][22758:0x7fd9688ad580], file:Test/collection-556-3480094503407958
80.wt, WT_SESSION.salvage: /home/dbdir/db/Test/collection-556-348009450340795880.wt: handle-open: open: No such file or directory
2020-04-22T15:19:56.121+0000 I - [initandlisten] Invariant failure rs.get() src/mongo/db/catalog/database.cpp 195
And when trying to start the server It is giving segmentation fault. Is there any way I can fix the database.
Test is the database that was deleted?
After making a backup, grep the remaining tree for other files that reference it and try to delete those as well.

Unable to start mongod with one missing collection wt file

I have a working mongod instance (v3.2.21).
But suddenly it stopped working. When i run mongo command it is throwing me following error:
2019-06-04T13:52:41.725+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
When i checked log its showing:
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] WiredTiger (2) [1559655403:388180][8404:0x7fb74e904c80], file:collection-1-1305830686620002691.wt, WT_SESSION.open_cursor: /mnt/volume-fra1-01//collection-1-1305830686620002691.wt: handle-open: open: No such file or directory
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] no cursor for uri: table:collection-1-1305830686620002691
2019-06-04T13:36:43.388+0000 F - [initandlisten] Invalid access at address: 0x58
2019-06-04T13:36:43.398+0000 F - [initandlisten] Got signal: 11 (Segmentation fault).
The collection which was earlier there is now missing in data directory
I tried to use --repair but the process gets stop at this collection.
I have looked at various resources but couldn't figure out how to make it working? Is there way so that wiredtiger escape this collection?
MongoD 4.0.3 and newer has better repair facilities as per SERVER-19815.
One thing you can try:
Copy your original dbpath so if the attempt is not successful, you don't clobber your original data
Download the 4.0.3 binaries (or newer, currently the latest is 4.0.10)
mongod --repair using the 4.0.3 binaries to attempt to repair the copied dbpath
If the repair is successful, try to run the 3.2.21 binaries pointing to the repaired dbpath
Please note that this repair attempt is best-effort and there's no guarantee of success. Having an up-to-date backup is still recommended. You might also want to investigate how the dbpath is missing a file to begin with.

Can't launch mongodb

I don't know where I went wrong,
but there is an error after error going on here, first it was
STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /var/lib/mongodb, terminating
I fixed with addition of permissions with this command:
sudo chmod -R go+w /var/lib/mongodb
, then
couldn't open /var/lib/mongodb/local.0 Operation not permitted
fixed it with another sort of permissions(
sudo chown -R $USER /var/lib/mongodb
)
now its complaining about:
F JOURNAL [initandlisten] dbexception during recovery: 13544 recover error couldn't open /var/lib/mongodb/journal/j._0
2017-11-20T13:19:16.443+0200 I STORAGE [initandlisten] exception in initAndListen: 13544 recover error couldn't open /var/lib/mongodb/journal/j._0, terminating
Update:
Fixed that as well with
sudo chown -R mongodb:mongodb /var/lib/mongodb
now its
exception in initAndListen: 13440 bad offset:0 accessing file: /var/lib/mongodb/local.0. See http://dochub.mongodb.org/core/data-recovery, terminating
what is happening? I mean my Ubuntu is not some super secured version,
I wish there was some
mongod --repair
command for me to use, but there isn't, whenever I try to do it it complains about
exception in initAndListen: 29 Data directory /data/db not found., terminating
although in the etc/mongod.config the specified path is /var/lib/mongodb (that's where I was giving all this permissions at)
Edit:
fixed that with the CMD "do sudo mkdir /data", the repair run its course successfully, but it didn't help me.
so what do I do? how to fix it?
how to run the Mongodb?
additional info: I ran it using
sudo service mongod start

Can't start mongoDB as a service

I'd like to run mongoDB as a service. The instance shall be configured as a single-node replicaset to be able to connect a elasticSearch instance to it with a the connector.
So I extended the mongod.conf:
...
replication:
replSetName: "singleNodeRepl"
...
I tried different ways to start now the mongod, but nothing works.
When I try to start the service by $ service mongod start, following error is thrown:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.106" (uid=1225 pid=26018 comm="start mongod ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
When I execute this command as sudo (whats not best-practise, right?), its "running" and following message is shown:
mongod start/running, process 26034
But process 26034 doesn't exist and ps aux | grep mongo also shows nothing?!
Next try: Run it as a normal application
mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl
Here following exception is shown:
2016-04-08T14:31:35.192+0200 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-08T14:31:35.192+0200 I CONTROL [initandlisten] dbexit: rc: 100
Everything is fine when I run ~$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl, but thats not my target: Its not running as a service and its running as root.
The mongod-logfile often keeps untouched. But the last lines are curious:
2016-04-08T14:24:56.242+0200 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-04-08T14:24:56.242+0200 I - [initandlisten] Fatal Assertion 28578
2016-04-08T14:24:56.242+0200 I - [initandlisten]
***aborting after fassert() failure
A mongodb-27017.sock existed, but deleting (what was suggested anywhere) didn't help.
Based on the erros above if tried serveral solutions, but nothing helps.
I think it's a very simple mistake...but which one?
[edit:]
I discovered, that I perhaps should have specified the config-location. So the (working but bad) command looks like:
$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl --config /etc/mongod.conf
This brings following error:
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
Thats an old thing, which was the solution for this problem and suddenly doesn't work anymore!?
I've had issues stopping and starting mongod as a service. Turns out there was an issue with the upsart script.
I found this discussion which seemed to fix it.
The suggested solution was pretty much: (copy pasting now)
vim /etc/init.d/mongod
look for stop() function (and start() function for good measure) and remove quotes around $PIDFILE in the following line.
killproc -p $PIDFILE -d 300 /usr/bin/mongod
Do this:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
Let me know if this doesn't work!

mongod instance exits on new database partition with errno :13 Permission denied

mongod instance on /data/db partition works fine. But when I created a new directory /data/rs1 for database and initialized mongod on it using
mongod --logpath "1.log" --dbpath /data/rs1 --port 27017
It gives me the following error:
STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/rs1/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
However if i try to initiate the same instance using 'sudo' , it works fine. Also, I have tried changing the permissions for /data/rs1 to the current user using chown, it doesn't work either. These are the current permissions of /data/rs1 folder
drwxr-xr-x 9 user123 wheel 306 Apr 27 14:32 rs1
Are there any other permissions that I am missing for /data/rs1?
Note: There is no instance of mongod running when I run the above command