Posts Tagged ‘mongo’

Post

Running MongoDB Completely in RAM

In sysadmin on August 11, 2011 by Wenzi Tagged: , ,

The project I am working on runs test cases constantly ( and you should too ) that are constantly creating and destroying MongooDB databases.

All those database allocations ( Mongo allocating the datafile ) was taking a lot of time on this not small project.

So with a need for speed, we put the database in RAM. This is how, if you need more speed , you can run Mongo completely in RAM.

/home/me# mkfs -q /dev/ram1 32768
/home/me# mkdir -p /ramcache
/home/me# mount /dev/ram1 /ramcache

[1] Make a filesystem in ram. mkfs makes a /dev in ram of the specified size. In this case 32M ( 32768 ), but you will have to make a bigger one for mongo, greater than 192M.

[2] Make a mount point. We need a directory to ‘attach’ the ram filesystyem so normal applications can access it as part of the file system.

[3] Mount the drive. Mount the ram drive on the mount point you just made.

To test it, we run mongodb with the ramcach as the datapath.

mongod –dbpath /ramcache/ –port 29019

 

Looking at the directory from another terminal window ( or tmux ) we can see that the lock file was created.

me@li132-23:~$ ls -la /ramcache/
total 18
drwxrwxrwx 3 root root 1024 Aug 11 04:36 .
drwxr-xr-x 22 root root 4096 Aug 11 04:31 ..
drwx------ 2 root root 12288 Aug 11 04:30 lost+found
-rwxr-xr-x 1 me me 6 Aug 11 04:37 mongod.lock

Now we can connect to the mongo server.

mongo --host localhost:29019

Now it just acts like a regular server, because it is, just running in RAM.

> use wenzi
switched to db wenzi
> doc = { author : 'wenzi', post : 'Water : the new Coke' }
> db.posts.insert(doc);

Comments Off

Post

Rotating MongoDB Log Files with Logrotate

In sysadmin on August 3, 2011 by Wenzi Tagged: , , , , ,

Rotating log files is something sys admins are all familiar with doing. There are a few ways to backup MongoDB, with the most common are the logRotate command and logrotate.

I prefer runCommand(“logRotate”) to rotate my log files. I administer a couple of MongoDB instalations and I check on them every day, and for those I prefer rotating them manually.

I do still have a mongoDB that is my little orphan server that runs logrotate. It just runs and I check on it every few weeks. For this one I use log rotate to make sure my disks do not fill up.

But theare are some people who prefer using logroatate, just because they are old school. I am one of those for everything but mongo.

So if you are used to logrotate, here is a script for you. You will have to change the parts for your own setup of course.

This server only ones one mongod ( yes, bad but this is not a critial machine ). If you are running more than one instnce the you will have to make changes obviously.

Place this in the file /etc/logrotate.d/mongodb

/var/log/mongodb/*.log {
	rotate 52
	size 50M
	compress
	weekly
	dateext
	missingok
	notifempty
	sharedscripts
	postrotate
		/bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
	endscript
}

Cheers

Comments Off