Hi, Am editing dbpath of running mongodb in 'amazon ubuntu
instance'(have more than 30 GB data), and I attached some volumes I
for data, log, and joural
I followed mongodb-ec2
mount /data , /log and /journal
stop mongodb
edit /etc/mongodb.conf
mongodb.conf
dbpath=/data
copy all files from old dir to new mount volumes.
start mongodb
.
For testing I run a python script,
from pymongo import MongoClient
db = MongoClient().my_testdb
I got the error message,
pymongo.errors.ConnectionFailure: could not connect to
localhost:27017: [Errno 111] Connection refused
So I remove the lock from the /data/mongod.lock.
and run sudo mongod --repair The following error I got
..........
ERROR: dbpath (/data/db/) does not exist
........
My question is, even though I configured dbpath=/data, why it try to look for the path /data/db? how can I resolve it?
When you run mongod --repair you are not using your config file at all, so you will need to pass --dbpath as part of the command, e.g.:
mongod --dbpath /data --repair
Or if you wish to use the config file, run:
mongod -f /etc/mongod.conf --repair
Related
Im setting my dbpath like so:
mongod --dbpath /Users/dylan/development/mongodb/data/db
it then connects to the db and runs fine. But as soon as I exit and try to start mongod again it comes up with this error:
Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option
for some reason it isn't saving the --dbpath
It is a best practice to store all startup parameters in the mongod.conf yaml file
and start the mongod process every time with mongo --config mongodb.conf file or as a service.
example content:
storage:
dbPath: /Users/dylan/development/mongodb/data/db
If you dont specify the dbPath location , the mongod process start with default dbPath location( /data/db ) or if started as service the dbPath found in default config file located in linux at /etc/mongod.conf
I started learning mongoDB a couple of days ago. Post installation, I am trying to change the dbpath as follows:
mongod --dbpath C:\myfolder\myproj\data\db
running the above command, I got the below statements in the command line:
Now i typed the below command to check if the dbpath has changed
mongod dbpath
this line still returns:
C:\data\db
I also tried running the below command to change the dbpath (as mentioned in a youtube video https://www.youtube.com/watch?v=pWbMrx5rVBE, but still the dbpath didn't change
mongod --directoryperdb --dbpath c:\myfolder\myproj\data\db
Can someone tell me how can I change my dbpath?
I looked at the stackoverflow question MongoDB not using /etc/mongodb.conf after I changed dbpath and also Unable to change the dbpath in mongodb through mongodb.conf but none of them helped
When you run
mongod --dbpath C:\myfolder\myproj\data\db
You are starting an instance of mongod with it's data directory as C:\myfolder\myproj\data\db
Running a second
mongod dbpath
is effectively starting a new instance of mongod - which, by default, has its dbpath as \data\db
Just run mongod --dbpath C:\myfolder\myproj\data\db as you are, then use mongo to connect to it (or whatever client you're using)
When connecting to that instance, you'll be using the instance that is storing it's data in C:\myfolder\myproj\data\db
I have installed MongoDB on a Ubuntu server like is indicated in the docs http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. Then, I have modified the configuration file /etc/mongod.conf for, later, run a mongod service.
MongoDB runs correctly if I execute:
sudo mongod -f /etc/mongod.conf
But MongoDB stops if I execute:
sudo service mongod start
In the config file /etc/mongod.conf I changed only this:
dbpath=/data/db
logpath=/root/logs/mongod.log
port=20000
With this configuration, the log file is not created too.
If I don't modify the previous values indicated, the service starts correctly. The default values are:
dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongod.log
port = 27017
Because the log file is not created with the custom configuration, I have only changed the dbpath for see the error:
[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?
I tried to run the following commands but without success:
sudo chown -R `id -u` /data/db
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
Stack:
Ubuntu 14.10
MongoDB 2.6.5
We must make all the directories/files owned by mongod user. For this:
sudo chown -R mongodb:mongodb /data/db
I found a special case where the use of symlinks appears to fail:
Using a standard enterprise install of mongodb except I changed the /var/lib/mongodb to a symlink as I wanted to use an XFS filesystem for my database folder and a third filesystem for the log folder.
$sudo systemctl start mongod (fails with a message no permission to write to mongodb.log).. but it succceded if I started with the same configuration file:
.. as the owner of the external drives (ziggy) I was able to start $mongod --config /etc/mongodb.conf --fork
I eventually discovered that .. the symlinks pointed to a different filesystem and the mongodb (user) did not have permission to browse the folder that the symlink referred. Both the symlinks and the folders the symlinks referred had expansive rights to the mongod user so it made no sense?
Am running MongoDB 2.2 on Ubuntu and if I run:
sudo mongod
I get an error that it can't find /data/db, which is not where the database is. In mongod.conf the database path is specified as the Ubuntu 10gen default /var/lib/mongodb which is where the db is located. Seems like mongod is not finding the conf file. So when I run:
sudo mongod -f /etc/mongodb.conf
The server starts up fine and output is logged to the log file: /var/log/mongodb/mongodb.log. All is happy. I can switch to another shell, log into mongo shell, see the databases and run queries.
So, I cancel out of that and try to run as a service:
> sudo status mongodb
mongodb stop/waiting
> sudo start mongodb
mongodb start/running, process 10468
Looks good so far, but the mongo server did not start. Running another:
> sudo status mongodb
mongodb stop/waiting
> mongo
MongoDB shell version: 2.2.0
connecting to: test
Sat Sep 1 19:07:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
"test" is not the correct database, and nothing appears in the log file.
I am at a loss as to what could be wrong. I checked the upstart scripts and they seem fine. /etc/init/mongodb.conf runs:
mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf
OK, this all comes down to permissions, but let's take it step by step. When you run sudo mongod it does not load a config file at all, it literally starts with the compiled in defaults - port 27017, database path of /data/db etc. - that is why you got the error about not being able to find that folder. The "Ubuntu default" is only used when you point it at the config file (if you start using the service command, this is done for you behind the scenes).
Next you ran it like this:
sudo mongod -f /etc/mongodb.conf
If there weren't problems before, then there will be now - you have run the process, with your normal config (pointing at your usual dbpath and log) as the root user. That means that there are going to now be a number of files in that normal MongoDB folder with the user:group of root:root.
This will cause errors when you try to start it as a normal service again, because the mongodb user (which the service will attempt to run as) will not have permission to access those root:root files, and most notably, it will probably not be able to write to the log file to give you any information.
Therefore, to run it as a normal service, we need to fix those permissions. First, make sure MongoDB is not currently running as root, then:
cd /var/log/mongodb
sudo chown -R mongodb:mongodb .
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb .
That should fix it up (assuming the user:group is mongodb:mongodb), though it's probably best to verify with an ls -al or similar to be sure. Once this is done you should be able to get the service to start successfully again.
First confirm that the mongodb user/group has permission to write to both the data directory and log file:
$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.
$ sudo chown -R mongodb:mongodb /var/log/mongodb.log
Start up MongoDB as a Daemon (background process) using the following command:
$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath
/var/log/mongodb.log --logappend
To Shut Down MongoDB enter the Mongo CLI, access the admin and issue the shutdown command:
$ ./mongo
> use admin
> db.shutdownServer()
Ref: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
I too had the same problem. So I went to cd /var/lib/mongodb/ and deleted the mongod.lock file
Then it worked for me.
After checking all permission in the data, journal and log folders as suggested by #nelsonic, my problem was solved by giving permission to lock file in the /tmp folder
sudo chown mongod:mongod mongodb-27017.sock
I was running it as a AWS Amazon Linux instance.
I figured that out by executing as the mongod user as below, and then, researching the error code. It might be useful for other troubleshooting.
sudo -S -u mongod mongod -f /etc/mongod.conf
Just try this command:
sudo chown mongodb /tmp/mongodb-27017.sock
Nothing worked for me, then I've found that it was a permissions problem on /tmp directory:
sudo chmod 1777 /tmp
sudo chown root:root /tmp
None of the above answers worked for me. I finally figured it out by debugging the init script with:
sudo bash -x /etc/init.d/mongodb start
And seeing it was passing the wrong config path to mongod. I simply changed the line in /etc/init.d/mongodb from "CONF=/etc/mongodb.conf" to "CONF=/etc/mongod.conf". Version 2 uses the former, and installing version 3 added /etc/mongod.conf with the new format but apparently did not update the init script.
UPDATE: I now have a much stranger problem where the init script works, but only if I run it with "sudo bash -x /etc/init.d/mongodb start" and not with "sudo service mongodb start". Same thing for stop.
My mongodb was starting when launched from the command line as the mongod user, but not as a service with User=mongod.
After an hour checking permissions, definition of the service, sockets... it was SElinux !
In /etc/selinux/config I switched from enforcing to permissive and reboot. It is now ok.
After none of the above answers worked for me, deleting my log file brought Mongo back to life.
These days this error can occur if you've updated mongod and you are running and old database. Mongod will be using the wiredTiger engine by default and you'll have a mmapv1 database
edit the engine setting in /etc/mongod.conf
# engine: wiredTiger
engine: mmapv1
Careful - YAML is whitespace sensitive
journalctl/systemd won't see this problem. Check the mongod log in /var/log/mongodb/mongod.log
I presume you can convert the database with something like the steps outlined here
https://docs.mongodb.com/manual/tutorial/change-standalone-wiredtiger/
I can't seem to connect to Mongo DB, which I've installed as a Windows Service on my local machine. I've also built a little WPF application which communicates with MongoDB.
The errormessage:
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:8
4
exception: connect failed
Unclean shutdown detected.
You should launch it with --repair flag.
mongod --repair
After repair is finished, stop this one and launch it normally. Documentation on --repair option.
Quicker:
sudo rm /data/db/mongod.lock
sudo mongod --dbpath /data/db --repair
sudo mongod --dbpath /data/db
If you do a repair operation as root user be sure that afterwards all db files are owned by the mongodb user, otherwise mongodb will not start
chown -R mongodb:mongodb /data/db
rm /data/db/mongod.lock
/etc/init.d/mongodb start
$ mongo
> use dbname
> db.repairDatabase()
Note --repair functionality is also available in the shell with the db.repairDatabase() helper for the repairDatabase command.
See also http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/:
If you are using the official MongoDB repo on Ubuntu instead of the default packages, the accepted answer will not work.
The mongod command, by default, uses /data/db as the default dbPath config setting whereas /etc/mongodb.conf uses /var/lib/mongodb as the path. Therefore if you just do mongod --repair, it will try to repair a database at /data/db, which is the wrong path.
I also found that if you execute mongod as the root user, any files created will be owned by root, so you need to execute the repair with the mongodb user.
This is what I eventually did to get it to work:
sudo chown -R mongodb: /var/lib/mongodb # Just to make sure permissions are correct
sudo -u mongodb mongod --dbpath /var/lib/mongodb --repair
sudo service mongodb start
Write the command as below and I think it will solve the problem:
cd data/
rm -rf mongod.lock*
cd ..
mongod --repair
./mongod
Follow this step to restart your mondoDB as fresh
1, Kill all the processes that mongod is running
to do this forcefully kill each process that are running on port 27017(default port for mongodb)
lsof -n -i4TCP:27017 Where 27017 is the port number the process is
running at
this returns the process id(PID) and run
kill -9 "PID" Replace PID with the number you get after running the
first command
2, restart mongo using mongod command