The weirdest thing happened. We have a mongodb instance with both journal and logs on separate hard drives running on a single amazon ec2 backed by ebs. The server unexpectedly shutdown this morning and when I looked at it, I noticed that mongo didn't start on startup.
I manually started mongo using the command
sudo mongod --fork --logpath /var/log/mongodb.log
It ran fine but when I looked at the database, all our our data had gone missing. I tried exiting out with the --repair option but it did nothing. This is what the logs from the initial mongod looks like:
2015-10-05T16:39:17.881+0000 [initandlisten] MongoDB starting :
pid=2757 port=27017 dbpath=/data/db 64-bit host=ip-172-31-59-166
2015-10-05T16:39:17.882+0000 [initandlisten] db version v2.6.8
2015-10-05T16:39:17.882+0000 [initandlisten] git version: 3abc04d6d4f71de00b57378e3277def8fd7a6700
2015-10-05T16:39:17.882+0000 [initandlisten] build info: Linux build5.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-10-05T16:39:17.882+0000 [initandlisten] allocator: tcmalloc
2015-10-05T16:39:17.882+0000 [initandlisten] options: { processManagement: { fork: true }, systemLog: { destination: "file", path: "/var/log/mongodb.log" } }
2015-10-05T16:39:17.890+0000 [initandlisten] journal dir=/data/db/journal
2015-10-05T16:39:17.893+0000 [initandlisten] recover : no journal files present, no recovery needed
2015-10-05T16:39:17.893+0000 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
2015-10-05T16:39:28.081+0000 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
2015-10-05T16:39:40.496+0000 [initandlisten] allocating new ns file /data/db/local.ns, filling with zeroes...
2015-10-05T16:39:40.654+0000 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
2015-10-05T16:39:40.654+0000 [FileAllocator] creating directory /data/db/_tmp
2015-10-05T16:39:40.659+0000 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.002 secs
2015-10-05T16:39:40.664+0000 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-10-05T16:39:40.664+0000 [initandlisten] added index to empty collection
2015-10-05T16:39:40.665+0000 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0 reslen:37 169ms
2015-10-05T16:39:40.669+0000 [initandlisten] waiting for connections on port 27017
This looks like there are no problems with the MongoDB initial start. But it also says that it's creating new ns file though old ones existed. What is happening here and how can I recover the data?
There's no indication anything was corrupted. The log indicates this instance was started on an empty volume.
Aside from the logPath, your MongoDB process is starting up with the default parameters. So, it's going to use /data/db as the location of the data directory. Based on how on your initial description of the problem, you may have been running the separate journal and data directories an EBS mount, i.e. your MongoDB config used --dbpath.
Check that you're using the same MongoDB configuration as was used
before the server went down
Check that your EBS volumes are mounted expected. You may use the mount option to confirm that the
path /data/db is pointing to the proper EBS volume.
And just to be sure... if the instance had used ephemeral drives the data would be lost when the instance shutdown. Sometime people confuse ephemeral drives with elastic block store, which is persistent.
Related
I have installed MongoDB 3.4 on Windows 10 and I cannot execute any commands to view or create users.
I have followed the documentation to the letter and read as many answers to what seems to be a common problem, but I still cannot solve this problem.
Any help would be appreciated. Below are the command prompt outputs:
Command prompt 1 running with admin rights:
C:\Program Files\MongoDB\Server\3.4\bin>mongod.exe --storageEngine mmapv1 --dbpath C:\mongodb\data\db --directoryperdb -journal
2017-04-01T16:21:46.414+0200 I CONTROL [initandlisten] MongoDB starting : pid=10936 port=27017 dbpath=C:\mongodb\data\db 64-bit host=Acer
2017-04-01T16:21:46.415+0200 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-04-01T16:21:46.415+0200 I CONTROL [initandlisten] db version v3.4.3
2017-04-01T16:21:46.416+0200 I CONTROL [initandlisten] git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1
2017-04-01T16:21:46.416+0200 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2017-04-01T16:21:46.417+0200 I CONTROL [initandlisten] allocator: tcmalloc
2017-04-01T16:21:46.417+0200 I CONTROL [initandlisten] modules: none
2017-04-01T16:21:46.418+0200 I CONTROL [initandlisten] build environment:
2017-04-01T16:21:46.418+0200 I CONTROL [initandlisten] distmod: 2008plus-ssl
2017-04-01T16:21:46.418+0200 I CONTROL [initandlisten] distarch: x86_64
2017-04-01T16:21:46.419+0200 I CONTROL [initandlisten] target_arch: x86_64
2017-04-01T16:21:46.419+0200 I CONTROL [initandlisten] options: { storage: { dbPath: "C:\mongodb\data\db", directoryPerDB: true, engine: "mmapv1", journal: { enabled: true } } }
2017-04-01T16:21:46.429+0200 I JOURNAL [initandlisten] journal dir=C:\mongodb\data\db\journal
2017-04-01T16:21:46.429+0200 I JOURNAL [initandlisten] recover begin
2017-04-01T16:21:46.430+0200 I JOURNAL [initandlisten] info no lsn file in journal/ directory
2017-04-01T16:21:46.430+0200 I JOURNAL [initandlisten] recover lsn: 0
2017-04-01T16:21:46.431+0200 I JOURNAL [initandlisten] recover C:\mongodb\data\db\journal\j._0
2017-04-01T16:21:46.480+0200 I JOURNAL [initandlisten] recover applying initial journal section with sequence number 1
2017-04-01T16:21:46.622+0200 I JOURNAL [initandlisten] recover cleaning up
2017-04-01T16:21:46.622+0200 I JOURNAL [initandlisten] removeJournalFiles
2017-04-01T16:21:46.623+0200 I JOURNAL [initandlisten] old journal file will be removed: C:\mongodb\data\db\journal\j._0
2017-04-01T16:21:46.627+0200 I JOURNAL [initandlisten] recover done
2017-04-01T16:21:46.780+0200 I JOURNAL [durability] Durability thread started
2017-04-01T16:21:46.838+0200 I JOURNAL [journal writer] Journal writer thread started
2017-04-01T16:21:46.880+0200 I CONTROL [initandlisten]
2017-04-01T16:21:46.880+0200 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-04-01T16:21:46.881+0200 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-04-01T16:21:46.883+0200 I CONTROL [initandlisten]
2017-04-01T16:21:48.911+0200 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/mongodb/data/db/diagnostic.data'
2017-04-01T16:21:48.919+0200 I INDEX [initandlisten] allocating new ns file C:\mongodb\data\db\admin\admin.ns, filling with zeroes...
2017-04-01T16:21:49.119+0200 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2017-04-01T16:21:49.399+0200 I STORAGE [FileAllocator] allocating new datafile C:\mongodb\data\db\admin\admin.0, filling with zeroes...
2017-04-01T16:21:49.401+0200 I STORAGE [FileAllocator] creating directory C:\mongodb\data\db\admin_tmp
2017-04-01T16:21:49.407+0200 I STORAGE [FileAllocator] done allocating datafile C:\mongodb\data\db\admin\admin.0, size: 64MB, took 0.003 secs
2017-04-01T16:21:49.425+0200 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-04-01T16:21:49.425+0200 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-04-01T16:21:49.426+0200 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-04-01T16:21:49.427+0200 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-04-01T16:21:49.429+0200 I NETWORK [thread1] waiting for connections on port 27017
Command prompt 2 running with admin rights:
> use admin
switched to db admin
> db.createUser( {
... user: "siteUserAdmin",
... pwd: "password",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... });
Error coming back is
2017-04-01T16:44:14.281+0200 E QUERY [thread1]
Error: couldn't add user: not authorized on admin to execute command
{ createUser: "siteUserAdmin", pwd: "xxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 600000.0 } } : _getErrorWithCode#src/mongo/shell/utils.js:25:13
DB.prototype.createUser#src/mongo/shell/db.js:1290:15
#(shell):1:1"
> use admin
> db.getUsers();
2017-04-01T16:52:41.537+0200 E QUERY [thread1] Error: not authorized on admin to execute command { usersInfo: 1.0 } :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
DB.prototype.getUsers#src/mongo/shell/db.js:1537:1
#(shell):1:1
>
I have mongo installed on my local machine. When I start the database by running mongod I got this error (that is fairly common, and this site has solutions to workarounds):
$ mongod
mongod --help for help and startup options
2015-01-01T22:31:17.350-0600 [initandlisten] MongoDB starting : pid=2835 port=27017 dbpath=/data/db 64-bit host=hermes
2015-01-01T22:31:17.351-0600 [initandlisten] db version v2.6.4
2015-01-01T22:31:17.351-0600 [initandlisten] git version: nogitversion
2015-01-01T22:31:17.351-0600 [initandlisten] build info: Darwin minimavericks.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2015-01-01T22:31:17.351-0600 [initandlisten] allocator: tcmalloc
2015-01-01T22:31:17.351-0600 [initandlisten] options: {}
2015-01-01T22:31:17.351-0600 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2015-01-01T22:31:17.351-0600 [initandlisten] dbexit:
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to close listening sockets...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to flush diaglog...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to close sockets...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: waiting for fs preallocator...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: lock for final commit...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: final commit...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: closing all files...
2015-01-01T22:31:17.352-0600 [initandlisten] closeAllFiles() finished
2015-01-01T22:31:17.355-0600 [initandlisten] dbexit: really exiting now
I created a directory in my development environment at /my/curent/directory/data/db and started mongo again with $ mongod --dbpath /my/curent/directory/data/db, this time producing:
2015-01-01T22:32:31.282-0600 [initandlisten] options: { storage: { dbPath: "./data/db" } }
2015-01-01T22:32:31.319-0600 [initandlisten] journal dir=./data/db/journal
2015-01-01T22:32:31.320-0600 [initandlisten] recover : no journal files present, no recovery needed
2015-01-01T22:32:31.383-0600 [FileAllocator] allocating new datafile ./data/db/local.ns, filling with zeroes...
2015-01-01T22:32:31.383-0600 [FileAllocator] creating directory ./data/db/_tmp
2015-01-01T22:32:31.482-0600 [FileAllocator] done allocating datafile ./data/db/local.ns, size: 16MB, took 0.098 secs
2015-01-01T22:32:31.842-0600 [FileAllocator] allocating new datafile ./data/db/local.0, filling with zeroes...
2015-01-01T22:32:32.756-0600 [FileAllocator] done allocating datafile ./data/db/local.0, size: 64MB, took 0.914 secs
2015-01-01T22:32:33.215-0600 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-01-01T22:32:33.216-0600 [initandlisten] added index to empty collection
2015-01-01T22:32:33.216-0600 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0 reslen:37 1852ms
2015-01-01T22:32:33.216-0600 [initandlisten] waiting for connections on port 27017
2015-01-01T22:33:31.402-0600 [clientcursormon] mem (MB) res:33 virt:2635
2015-01-01T22:33:31.402-0600 [clientcursormon] mapped (incl journal view):160
2015-01-01T22:33:31.402-0600 [clientcursormon] connections:0
It's great. Using the mongo shell, I can access my collections that I was working with in this directory, but I can also see all of my other databases from weeks prior (when this directory did not exist) using show dbs. What purpose does the --dbpath option serve if not to isolate where data is stored? Is something weird happening here?
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:\Program Files\MongoDB\mongod.cfg) or on the command line with the --dbpath option.
Read more about MongoDB Installation
If you are using windows then create data\db folder under C drive.
If you are using your own directory for data then pass full path of the folder as --dbpath argument value.
If MongoDB’s default data directory path "\data\db" is correct but accessing old data means just check your Task Manager.
End all mongo command and restart your mongodb. I tried it, working well
I am running MongoDB inside the Docker, a linux container. Based on this Dockerfile.
I am using the latest mongo release, 2.6.4 installed on Ubuntu 14.04 64bits. I am able to start the mongod, I do have a /data/db folder in the container and the host machine ( even used as mounted folder, it is there in host machine. ). Do have enough memory, but I was getting errors.
From the logs below, you could clear tell that I am trying to connect the db twice, the connection won't be open for some reasons. Someone could help me?
Note: the machine only have git and mongo installed. Do mongo need anything else as dependencies?
2014-09-04T05:14:50.645+0000 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=f00d8205ca65
2014-09-04T05:14:50.645+0000 [initandlisten] db version v2.6.4
2014-09-04T05:14:50.645+0000 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-04T05:14:50.645+0000 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-04T05:14:50.645+0000 [initandlisten] allocator: tcmalloc
2014-09-04T05:14:50.646+0000 [initandlisten] options: {}
2014-09-04T05:14:50.648+0000 [initandlisten] journal dir=/data/db/journal
2014-09-04T05:14:50.648+0000 [initandlisten] recover : no journal files present, no recovery needed
2014-09-04T05:14:50.703+0000 [FileAllocator] allocating new datafile /data/db/local.ns, filling with zeroes...
2014-09-04T05:14:50.703+0000 [FileAllocator] creating directory /data/db/_tmp
2014-09-04T05:14:50.705+0000 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB, took 0 secs
2014-09-04T05:14:50.708+0000 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
2014-09-04T05:14:50.709+0000 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.001 secs
2014-09-04T05:14:50.711+0000 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2014-09-04T05:14:50.711+0000 [initandlisten] added index to empty collection
2014-09-04T05:14:50.712+0000 [initandlisten] waiting for connections on port 27017
2014-09-04T05:15:50.721+0000 [clientcursormon] mem (MB) res:36 virt:341
2014-09-04T05:15:50.721+0000 [clientcursormon] mapped (incl journal view):160
2014-09-04T05:15:50.721+0000 [clientcursormon] connections:0
2014-09-04T05:15:57.976+0000 [initandlisten] connection accepted from 172.17.42.1:56593 #1 (1 connection now open)
2014-09-04T05:15:57.976+0000 [conn1] end connection 172.17.42.1:56593 (0 connections now open)
Someone said it could be less memory to run mongo. after running the momery check, I do still have a good amount of memory to run Mongo.
[ root#512ea0e1096b:/data ]$ free -m
total used free shared buffers cached
Mem: 2001 436 1564 0 24 276
-/+ buffers/cache: 136 1865
Swap: 2991 0 2991
The process of adding a mongoDb (2.4) cartridge to my OpenShift application seems to work fine but ends up with an error and no cartridge is added. It looks like a disk space problem (I have already mysql in the same application), but I freed plenty of space and, strangely enough, the problem only appears at the very end of setup. Here is the log (hiding login details):
Starting MongoDB cartridge
note: noprealloc may hurt performance in many applications
Sat May 3 19:38:54.847 [initandlisten] MongoDB starting : pid=389973 port=2701
dbpath=/var/lib/openshift/5c0013917b4d45c68fddbb75e082a35a/mongodb/data/ 64-bit host=ex-std-node94.prod.rhcloud.com
Sat May 3 19:38:54.848 [initandlisten] db version v2.4.6
Sat May 3 19:38:54.848 [initandlisten] git version: nogitversion
Sat May 3 19:38:54.848 [initandlisten] build info: Linux x86-023.build.eng.bos.redhat.com 2.6.18-371.el5 #1 SMP Thu Sep 5 21:21:44 EDT 2013 x86_64 BOOST_LIB_VERSION=1_41
Sat May 3 19:38:54.849 [initandlisten] allocator: tcmalloc
Sat May 3 19:38:54.849 [initandlisten] options: { auth: true, bind_ip: "127.2.148.131", config: "/tmp/mongodb.repair.conf", dbpath: "/var/lib/openshift/5c0013917b4d45c68fddbb75e082a35a/mongodb/data/", nohttpinterface: "true", noprealloc: "true", pidfilepath: "/var/lib/openshift/5c0013917b4d45c68fddbb75e082a35a/mongodb/pid/mongodb.pid", quiet: "true", repair: true, smallfiles: "true" }
**************
You specified --repair but there are dirty journal files. Please
restart without --repair to allow the journal files to be replayed.
If you wish to repair all databases, please shutdown cleanly and
run with --repair again.
**************
Sat May 3 19:38:54.865 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Sat May 3 19:38:54.866 dbexit:
Sat May 3 19:38:54.866 [initandlisten] shutdown: going to close listening sockets...
Sat May 3 19:38:54.866 [initandlisten] shutdown: going to flush diaglog...
Sat May 3 19:38:54.867 [initandlisten] shutdown: going to close sockets...
Sat May 3 19:38:54.867 [initandlisten] shutdown: waiting for fs preallocator...
Sat May 3 19:38:54.867 [initandlisten] shutdown: closing all files...
Sat May 3 19:38:54.867 [initandlisten] closeAllFiles() finished
Sat May 3 19:38:54.868 dbexit: really exiting now
Warning: Gear 5c0013917b4d45c68fddbb75e082a35a is using 98.9% of disk quota
Warning: Gear 5c0013917b4d45c68fddbb75e082a35a is using 97.3% of disk quota
Attempting to repair MongoDB ...
MongoDB 2.4 database added. Please make note of these credentials:
Root User: ------------
Root Password: ------------
Database Name: ------------
Connection URL: mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/
Failed to execute: 'control start' for /var/lib/openshift/5c0013917b4d45c68fddbb75e082a35a/mongodb
Any idea on how to solve it? Thank you
Yes, as per the logs it looks like you have consumed most of your 1GB disk space. The 1 GB disk space is consumed by all your application cartridges and storage.Which web cartridge are you using? Can you check the disk space usage using quota -s command. SSH into the application gear and run quota -s command. Or if you have rhc command-line installed then you can use rhc ssh --app <app_name> --command 'quota -s'. You can clean up disk space using rhc tidy --app <app_name> command. After cleaning up, try running rhc cartridge command again. You can create a scalable application and that would allow every cartridge to be installed on a different gear. This would allow each cartridge more disk space.
I have started learning MongoDB and for which trying to install it on Ubuntu (which I recently shifted from windows). Facing issues to start it with sudo service mongodb start. Following are the logs:
Sun Aug 4 20:25:36.774 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
**************
Error: journal files are present in journal directory, yet starting without journaling enabled.
It is recommended that you start with journaling enabled so that recovery may occur.
**************
Sun Aug 4 20:25:36.774 [initandlisten] exception in initAndListen: 13597 can't start without --journal enabled when journal/ files are present, terminating
Sun Aug 4 20:25:36.774 dbexit:
Sun Aug 4 20:25:36.774 [initandlisten] shutdown: going to close listening sockets...
Remove journal files : everything under /var/lib/mongodb/journal if you want to disable journaling (not recommended) or use journaling: journal=true in config file or --journal from command line.
If MongoDB has been shutdown forcefully then the journal files are not cleaned up. The warning is here so that you can decide whether you want to recover from a failure (recommended). For recovery to work, you need to start MongoDB with --journal. Journalling is turned on by default though so I expect your /etc.mongodb.conf file has a nojournal=true line. You can remove that one instead as well.
If you really don't care about recovering, then you can simply remove all the files under /var/lib/mongodb/journal—but realise that you might end up with broken data files.