All things Sysadmin
Just another manic Monday

tooltip - inotify-tools

August 26th, 2008 by admin

A nifty tool which might be handy when getting to know a system or tracking down I/O usage is inotify-tools . It’s a lightweight interface to the kernel’s inotify function. It gives a quick overview over which files are accessed and how in any given directory and it’s subdirectories (if asked to).
It can quickly give an overview of efficiency of caching, frequency of commits, and all sorts of useful information for a whole range of applications.

Here’s some example output from the inotifywatch utility during a mysqlslap run:

# inotifywatch  /var/lib/mysql/mysqlslap/*
Establishing watches...
Finished establishing watches, now collecting statistics.
total  access  modify  close_write  close_nowrite  open  delete_self  filename
728    450     274     1            0              1     1            /var/lib/mysql/mysqlslap/t1.MYD
241    0       238     1            0              0     1            /var/lib/mysql/mysqlslap/t1.MYI
5      1       0       0            1              1     1            /var/lib/mysql/mysqlslap/t1.frm
2      0       0       0            0              0     1            /var/lib/mysql/mysqlslap/db.opt
.

Granted - as far as MySQL is concerned - most information is accessible through SHOW GLOBAL STATUS and/or SHOW ENGINE INNODB STATUS commands. But if you for instance have an erratic fear of the key_read_requests variable, you could always look at how often your MYI files are accessed. You catch my drift..

If you’re only interested in certain file operations, you can apply filters. If you for instance only have interest in file writes, your run would look like this:

# inotifywatch -e modify -e delete_self /var/lib/mysql/mysqlslap/*
Establishing watches...
Finished establishing watches, now collecting statistics.
total  modify  delete_self  filename
49     47      1            /var/lib/mysql/mysqlslap/t1.MYI
44     42      1            /var/lib/mysql/mysqlslap/t1.MYD
2      0       1            /var/lib/mysql/mysqlslap/db.opt
2      0       1            /var/lib/mysql/mysqlslap/t1.frm
.

You can monitor pretty much any file operation, so this tool can be used in a whole range of scenarios. Ever wondered just how many temp files your application creates or? Are you sure it doesn’t open and close the file handle for each operation? Do you want to know which file on your website is the most popular download at the moment but can’t wait until the webstats crontab has ran? I could go on…

inotify-tools come with another utility inotifywait. This tool looks for activity on a specified file or directory and instantly tells you which operation was performed. Nothing amazing, but I can see a few areas of use for that as well, though most of them have tools for that purpose already.

Posted in misc | No Comments »

lighttpd 2.0

August 2nd, 2008 by admin

Linked from a post on the lighttpd blog is a page outlining the plans for lighttpd 2.0

While I’ve experienced some of the “oddities” they refer to, I have every bit of confidence in the developers. Even so - it’s a risky path to go down. They will most likely iron out the current shortcomings and oddities, but it’s fairly likely that a few new will be introduced along the way. I do however believe the planned use of the well proven glib is likely to prevent some of them.

It will be mighty interesting to see the impact of using libev for managing events. It certainly helps when “flying light”. Another interesting thing will be to see what plugins people come up with!

Graceful restarts will be most welcomned as well!

Go go lighttpd!

Posted in Webservers | No Comments »

Some trickery or resilience with Varnish

July 22nd, 2008 by admin

As of now, Varnish has no means to detect whether a backend is available or at good health before sending a request (periodic checking is scheduled for ver 2.0 and will presumably work with the cluster mode as well). So if you’ve got two or more backends, and under some condition can’t or won’t serve a request immediately or want to send it elsewhere depending on some circumstance, you can do this using HTTP return code or header with the not-so-well-documented feature ‘restart’ (then again, what feature is well documented in Varnish?).

‘restart’ will effectively increase a counter by 1 and re-run vcl_recv(). You can set how many times a restart should take place before giving up entirely - should you not use the counter in a condition prior to it reaching the limit - by starting varnishd with -p max_restarts=n or ‘param.set max_restarts 1′ on the CLI. This variable defaults to 4, and you can of course set conditions depending on the number of restarts.

Here’s a sample VCL to do this:

backend be1 {
.host = "127.0.0.1";
.port = "81";
}
backend be2 {
.host = "10.0.0.2";
.port = "81";
}

sub vcl_recv {
if (req.restarts == 0) {
set req.backend = be1;
} else if (req.restarts == 1) {
set req.backend = be2;
}
}

sub vcl_fetch {
if (obj.status != 200 && obj.status != 302) {
restart;
}
}

In this simple VCL, a request destined for this instance of Varnish which doesn’t return 200 or 302 from the backend, is effectively sent to 10.0.0.2 which may have something else in store for the visitor!

If I for instance use the above VCL and set be1 to return a 301 for / and send a request to Varnish, this is what shows up in varnishlog:


10 ObjProtocol c HTTP/1.1
10 ObjStatus c 301
10 ObjResponse c Moved Permanently
10 ObjHeader c Date: Tue, 22 Jul 2008 00:25:29 GMT
10 ObjHeader c Server: Apache/2.0.59 (CentOS)
10 ObjHeader c X-Powered-By: PHP/5.1.6
10 ObjHeader c Location: http://be1.northernmost.org:6081/links.php/
10 ObjHeader c Content-Type: text/html; charset=UTF-8
13 BackendClose b be1
10 TTL c 1839681264 RFC 120 1216686329 1216686329 0 0 0
10 VCL_call c fetch
10 VCL_return c restart
10 VCL_call c recv
10 VCL_return c lookup
10 VCL_call c hash
10 VCL_return c hash
10 VCL_call c miss
10 VCL_return c fetch
12 BackendClose b be2
12 BackendOpen b be2 10.0.0.1 38478 10.0.0.2 81
12 TxRequest b GET
12 TxURL b /
12 TxProtocol b HTTP/1.1

10 ObjProtocol c HTTP/1.1
10 ObjStatus c 200
10 ObjResponse c OK
10 ObjHeader c Date: Mon, 21 Jul 2008 23:37:24 GMT
10 ObjHeader c Server: Apache/2.2.6 (FreeBSD) mod_ssl/2.2.6 OpenSSL/0.9.8e DAV/2
10 ObjHeader c Last-Modified: Thu, 10 Jul 2008 14:26:46 GMT
10 ObjHeader c ETag: “35e801-3-3702d580″
10 ObjHeader c Content-Type: text/html
12 BackendReuse b be2

You can of course use this for very basic resilience as well, but that’s definitely a job for your load balancer. Also be aware about the overhead in this, since the request after all is sent to the backend and processed before passed on to the other node.

Maybe it’s not the most useful feature in the world, but I thought it was nifty!

Posted in Sundry sysadmin | 2 Comments »

LVM with dmraid

July 15th, 2008 by admin

When adding a new disk for a customer running CentOS 4.7 on severely old hardware, I bumped into something I’ve never had happening to me before. Basically the system wouldn’t let me create the Physical Volume and gave me this message:

[root@gwyneth ~]# pvcreate /dev/hdc1
Can’t open /dev/hdc1 exclusively. Mounted filesystem?

hdc1 was obviously not mounted or in any other way used. Or so I thought. As I was flicking through the loaded kernel modules, I saw the dm_* modules being loaded and I was quite sure I knew what it was at that point. dmraid is hogging the disk. I verified that dmraid was indeed aware of the new disk with:

[root@gwyneth ~]# dmraid -r
/dev/hdc: pdc, “pdc_hceidaeha”, mirror, ok, 78125000 sectors, data@ 0

So deactivating the (in)appropriate RAID set:

[root@gwyneth ~]# dmraid -a no pdc
[root@gwyneth ~]# pvcreate /dev/hdc1
Physical volume “/dev/hdc1″ successfully created

Obviously, if you currently aren’t or don’t plan on ever run any software RAID setup (which you shouldn’t on a server in my opinion), you do best in removing the dmraid package altogether to avoid the same or similar problems in the future.

Posted in Sundry sysadmin | No Comments »

Resyncing slaves with slaves

July 5th, 2008 by admin

When dealing with replicated setups with two or more slaves sharing a master, it appears as if a lot of people overlook the obvious. You don’t need to take your master down to resync a slave. I was hoping I wouldn’t need to post about this, but I see people taking down their masters when they have perfectly healthy slaves way too often to let it slip.

You’ve got everything you need on the other slave(s). Provided that it’s in good health, you’ve got all the data, the master’s binlog file name and position. Run SHOW SLAVE STATUS\G on the slave, take note of Relay_Master_Log_File and Exec_Master_Log_Pos which are the same as what you’d get from SHOW MASTER STATUS\G on the master instance, minus the lag which is irrelevant in this case. Then proceed to sync the data from the healthy slave and use the above values in the CHANGE MASTER TO statement (obviously setting MASTER_HOST to the real master, not the other slave).

Happy higher availability!

Posted in MySQL | 2 Comments »

« Previous Entries