Archive for the ‘sysadmin’ Category

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

Learning Xen With the Book Of Zen

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



IF YOU ARE STARTING XEN
I do recommend this book. It is a little dated ( about two years ) but it is still a good read.

The book is put out by No Starch press which has an hippy/indie bookseller feel to it.it is also fifty bucks which is sort of pricy.

They mainly focus on the ‘free’ versions of Xen. If you bought Xen, this book will still help you get a better feeling about Xen.

WHAT I LIKE

There is good stuff in the book on using Xen and system administration. Written in a pretty plain style with an emphasis on the what and why of system administration.

In other words, it doesn’t suck.

WHAT I HATE

I hate the cover. Really. I have been trying to find some rhyme or reason for it, but I cannot except for one. One of the authors drew it.

I kept finding myself wanting to hate the book because of the cover & illustrations, but I didn’t. Like I said before, it is published by No Starch press. They seem to be really bad at cover design. I am sure they would say ‘creative’, ‘eccentric’, or ‘artistic’. I just think …. bad.

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

Post

MongoDB : Making a Specific Node Primary in a Replica Set

In sysadmin on July 24, 2011 by Wenzi Tagged: , , , ,

MongoDB is funny in that you are having a conversation with the cluster than sending commands.

Making a PARTICULAR machine primary is one of those times. Now I will separate the blog into three parts. Pre  Mongo 1.7.2, Mongo 1.7.2 to Mongo 1.9.1 and after Mongo 1.9.1

PRE MONGO 1.7.2

I have no idea, never tried it. If you are still using a pre 1.7.2 version, stop it. Unless you have some reason for sticking to an old version, just move to a newer version.

MONGO 1.7.2 to MONGO 1.9.1

Mongo 1.7.2 introduced ReplFreeze. That is the ability to stop a machine from becoming primary for a certain period of time. For example,

rs.freeze(120)

would stop the node from becoming the primary server for 120 seconds.

You would freeze all the nodes you did not want to become primary and then tell the current primary to step down as primary.  A new election would be held, and all the frozen nodes would decline to be elected to be primary, leaving the one you did not freeze to be primary.

POST MONGO 1.9.1

This is the easiest case. 1.9.1 introduced a variable priority.

You would set the priority of the server you want to become primary higher. If the server you want to become primary is within 10 seconds of the current primary, the current primary will step-down. If it is too far behind, an election would be held when it came within 10 seconds. Or if you cannot wait, you could force the primary to step  down.

db.adminCommand({replSetStepDown:1000000, force:1})

You will be primary less until the higher priority node catches up.

Comments Off

Post

Lion 10.7 – Dropping FTP File Sharing

In sysadmin on July 24, 2011 by Wenzi Tagged: , , , ,

I just installed 10.7 on a laptop I am using. No surprise, I like 10.7 except for the crazy scrolling direction which I promptly changed back to normal.  Then I went to ftp some tar archives to it and ftp did not work. Ok, clicked into Settings, Sharing and then File Sharing.

NO FTP

This really sucks, and my first thought was , “I they are not going to include an ftp server i will install one my self”. I , like most people, have been using ftp forever. My favorite client was ncftp.

Then I thought. I had actually been trying to get away from ftp. It was insecure after all. The thing that was holding me back was ncftp.

So I bit the bullet and started using sftp …. and I hate it. just missing so many nice feature of ncftp.

Anyway, my search goes on for a new sftp client. One with things like bookmarks and filename completion.

Comments Off