Basics of Linux Server Administration, Part 1

I have decided to start writing a small series of posts based on things I have learnt over the past few years. I run a small group of Linux servers — mostly web application servers running PHP, MySQL and PostgreSQL — with a variety of different distributions; some of them are running Gentoo Linux, a couple of others are running Debian or Ubuntu, and I’ve installed Fedora Core 6 on my home server, but the majority of what I’ve learnt (and will talk about here) is universal and will apply equally to all Linux distro’s.

In this article I’m going to cover disk space.

The Problem

In an ideal world disks would have an infinite amount of space, but unfortunately that’s not the case. The consequences of running out of space on a server can be catastrophic, and will often bring a server to its knees very swiftly. Services often fail when they can’t write to their logs or create temporary files, so monitoring disk usage is a vital part of an administrators job.

Keeping an Eye

We can monitor disk space on a Linux server with the df command. Here is an example of the output from one of my servers:

piro danbee # df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hdc3             10238812   2596020   7122688  27% /
udev                    241904       176    241728   1% /dev
/dev/hdc4            181436296 119808716  52411092  70% /home/media/data
shm                     241904         0    241904   0% /dev/shm

There are a number of options we can pass to df to make its output more readable. The -h option will tell df to show the sizes ‘human readable’:

piro danbee # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdc3             9.8G  2.5G  6.8G  27% /
udev                  237M  176K  237M   1% /dev
/dev/hdc4             174G  115G   50G  70% /home/media/data
shm                   237M     0  237M   0% /dev/shm

As you can see, that’s much more readable. :)

Long Term

As a long term solution, wouldn’t it be nice if the server kept a check on disk space and let you know when it was getting a bit low? The easiest way to deal with this is by setting up a script that checks the disk space on selected partitions regularly, and alerts us somehow when remaining disk space drops below a pre-defined level.

The most obvious alert method would be email, so that’s what we use here. The mailx command will let us easily send an email. If your distro hasn’t already got it, you should be able to install it easily using your default package manager.

Anyway, without further ado, here is the script:

#!/bin/sh

# Disk space checker script
# -------------------------

# Set warning and low limit to 1.5gb and 1gb
warninglimit = 1500000
lowlimit = 1000000

# File systems to check
filesystems = "/home /var /"

# Email address to send alerts to
alert_email = "fakeemail@fakedomain.com"

# Loop through filesystems
for fs in $filesystems
do
        # Get the remaining space on this filesystem
        size=`df -k $fs|grep $fs|awk '{ print $3; }'`

        if [[ $size -le $lowlimit ]]
        then
        echo "URGENT: Low disk space for $fs ($size) on $HOSTNAME" > email_message.txt
                    mailx -s "URGENT: Low disk space for $fs ($size) on $HOSTNAME" $alert_email < email_message.txt

                break
        fi

        if [[ $size -le $warninglimit ]]
        then
        echo "WARNING: Low disk space for $fs ($size) on $HOSTNAME" > email_message.txt
                    mailx -s "WARNING: Low disk space for $fs ($size) on $HOSTNAME" $alert_email < disc_space_warning.txt
    fi
done

Copy this to a file somewhere on your server (something like /usr/scripts/check_disks.sh), make it executable and symlink it from /etc/cron.daily or /etc/cron.hourly.

# chmod +x /usr/scripts/check_disks.sh
# ln -s /usr/scripts/check_disks.sh /etc/cron.daily/check_disks

Or, if you haven’t got an /etc/cron.daily directory, add a line to your crontab file that reads something like the following.

00 01 * * * root /usr/scripts/check_disks.sh

Doing it this way will also allow for more flexibility in when you want the script to check.

Do Most PCI Wireless NICs Suck?

I decided a week ago, while in B&Q, to add a PCI Wireless network card to my main PC. I was originally planning to run cables from the corner of the lounge where the router is located, to the back bedroom where the computers are situated.

The card I bought from B&Q was a TrendNet card. Fairly generic, based on a Ti TNET chipset. It took me about an hour to get it connected to my network (the same network that took me mere seconds to connect to from my Powerbook) and once it was connected, browsing the Internet became an almost nostalgic experience. Nostalgic because the last time I remember it being that slow was when I used a dial up modem! Even accessing the admin interface on the router was slow!

So I decided to pack that one back in it’s box and return it, and promptly ordered a Netgear WG311T from Amazon.co.uk. ‘Can’t go wrong with a Netgear’ I thought. Oh, how wrong could I be…

The card installed fine. Connecting to the network was a painless experience that took seconds, and all seemed well. Browsing was as quick as it should be so I leave the machine thinking everything’s ok.

So a few hours later I came back to the machine, and everything has stopped. The computer is locked up tighter than a Nuns arse. Not even numlock on the keyboard works. So I turned the machine off and went to bed, hoping it was a one off. Not so. The next day, after getting home from work, the machine locks up twice in ten minutes. Did a bit of research, and it turns out that this is a common problem with this card (Atheros chip based) when partnered with VIA motherboard chipsets.  So I chanced a call to Netgear technical support.  Well, that was a waste of time.  The bloke at the end of the phone was clearly not English, and simply took me through a script that had me move the card to a different PCI slot.  Anyway, it locked up again half an hour later and that card is now in a box waiting to be returned to Amazon.

I’ve now got a Linksys card in there, which as far as I’m aware is based on a Broadcom chipset. No problems as yet, and I’m just going to keep my fingers crossed…

Notes from a Switcher, part 5

Since buying my Powerbook 6 months ago, I can’t help feeling that Apple products are currently a bit form over function. Don’t get me wrong — I love my Powerbook, and the Mac OS is well designed, slick and easy to use — but it often seems as though features that might seem fundamental in other apps are just left out, perhaps because they want to sell you a ‘Pro’ version with that feature and many others (Quicktime is one good example) or just because said feature ruins the lines of the suit, as it were.

iPhoto is one such application that appears to have features missing, mainly the ability to view photos full screen (without running a slideshow), and I’ve also noticed that the photo order within a slideshow reflects the order you have them displayed in thumbnail view so if, like me, you like to see the latest photos at the top, your slideshows will run in reverse chronological order, with no apparent way to change this.

iTunes lacks the ability to play most of my music by default — although the XiphQT component is coming along nicely (missing some metadata stuff at the moment) — and doesn’t do gapless playback, which means that mix albums and any other albums that have tracks running into each other end up with little gaps in the music. Quite annoying. There also doesn’t seem to be any way of sorting albums in the browser by any other criteria than album name. I’d prefer to sort my albums chronologically.

On the good news front, I’ve found a solution to the mouse acceleration problem in the form of SteerMouse. This handy little replacement mouse driver allows me to tune the acceleration or even turn it off, which is what I did. The bad news is that it costs $20, but I’ll be paying that $20 without too much complaint because I can now use my Bluetooth mouse properly. Do you think I could send the bill on to Apple?

What, no ‘Stop’?

There seems to be an increasing trend for media players (both hardware and software) to leave out the ‘stop’ button. They have a ‘play/pause’ button, ‘next’ and ‘previous’ track buttons, but no stop. iTunes, iPods, and my new iAudio5; none of them have a ‘stop’ button. I know the pause button does pretty much the same job, but it’s still different. It’s not quite as final ‘stop’ is it? It gives the impression that the music will start up again at some point in the future. What if I don’t like what’s playing? What if I just don’t want to listen any more?

So come on, stop leaving out the ‘stop’ button and put it back in it’s rightful place. Next to ‘play’.

Notes from a Switcher, part 4

So far, the one thing that has been bugging the hell out of me with OS X is the mouse control panel. On Windows I used to just switch the acceleration off altogether, as I’m firmly in the camp that believes the mouse pointer should follow the mouse 1:1. In fact, I even had a registry hack that disabled mouse acceleration completely, even when the ‘Enhance pointer precision’ option was checked. While we’re on that subject, who decided on the name of that option anyway?!?

This post was inspired by Michael Heilemanns recent mouse related post, and I completely agree that the mouse control panel in OS X seems to lack a lot of the options it needs. I can understand that Apple probably want it to be simple, so why not include the more advanced controls; acceleration curve etc, behind a button marked ‘Advanced’?

Two solutions appear to be popular, but neither of them support my Apple Bluetooth mouse, and they both cost money. And it seems ridiculous that third parties have felt the need to write software that fixes something Apple should have fixed.

So come on Apple, give me a decent mouse control panel which will allow me to turn the acceleration off!

 1 2 3 Next →

About

Pixelhum is the web playground of Dan Barber (danbee), a disgruntled Web Designer and general geek.

Header image by Chris Percival. Licenced under Creative Commons.

User