Linux and Open Source articles, topics and discussion with your questions answered by dmourati, a Linux expert with over eight years production experience.

Tuesday, December 18, 2007

Disabling Snapshots on a NetApp Filer

Network appliance makes a series of devices called NetApp filers. These are network-attached storage devices used to share a filesystem across the network.

These filers support a feature known as snapshot. A snapshot is a point-in-time picture of the disk. The snapshot can be used as a backup or for any other copy and keep procedure.

In some cases, these snapshots can be undesirable. To disable them, log on to filerview.

Go to the:

Volumes->Snapshots->Manage

menu.

Select the checkboxes next to the snapshots you want to delete.

Then click delete.

A dialog box asking you to confirm comes up.

Confirm the deletion.

You are done.

Wednesday, December 12, 2007

Working with Cron

In today's installment dmourati will show you how to setup cron to do your bidding. With a little advanced planning, you can have cron run jobs for you while you sleep freeing you up to do other, more interesting work.
cron

Cron is a daemon to execute scheduled commands. This can be setup on a system-wide basis, or for individual user accounts. Today we will setup a system level cron.

Configuring a Cron Job

To set up a system cron job, make a new file in /etc/cron.d. This directory is used to store cron entries. Here's an example:


[root@lncdw2 cron.d]# cat ds-log-syncer
30 00 * * * root /usr/local/sbin/ds-log-syncer.sh > /dev/null 2>&1


This entry starts off with the standard cron format:

minute hour day month day-of-week user script

A "*" above just means every.

So, this can be read as follows

At 30 minutes past midnight, every day, the root user should run the following script /usr/local/sbin/ds-log-syncer.sh and redirect the output to /dev/null (throw it away).

Script

Here's the shell script that the cron entry refers to:

#!/bin/bash
#Streaming logs:
#From DS:/var/log/streaming/* to
#lncdw2:/var/log/streaming/
#Httpd logs:
#From DS:/var/log/httpd/* to lncdw2:/var/log/httpd/

#Setup directories
mkdir -p /var/log/streaming/Three/threeprodds1/ /var/log/streaming/Three/threeprodds2/ /var/log/streaming/Three/threeprodds3/ /var/log/streaming/Three/threeprodds4/ /var/log/streaming/Three/threeprodds5/
mkdir -p /var/log/httpd/Three/threeprodds1/ /var/log/httpd/Three/threeprodds2/ /var/log/httpd/Three/threeprodds3/ /var/log/httpd/Three/threeprodds4/ /var/log/httpd/Three/threeprodds5/

#Get Three streaming logs
echo "Synchronizing Three streaming logs" | logger -s -t ds-log-syncer.sh
rsync -avze ssh rhythm@threeprodds1:/var/log/streaming/ /var/log/streaming/Three/threeprodds1/&
rsync -avze ssh rhythm@threeprodds2:/var/log/streaming/ /var/log/streaming/Three/threeprodds2/&
rsync -avze ssh rhythm@threeprodds3:/var/log/streaming/ /var/log/streaming/Three/threeprodds3/&
rsync -avze ssh rhythm@threeprodds4:/var/log/streaming/ /var/log/streaming/Three/threeprodds4/&
rsync -avze ssh rhythm@threeprodds5:/var/log/streaming/ /var/log/streaming/Three/threeprodds5/&

#Get Three httpd logs
echo "Synchronizing Three streaming logs" | logger -s -t ds-log-syncer.sh
rsync -avze ssh rhythm@threeprodds1:/var/log/httpd/ /var/log/httpd/Three/threeprodds1/&
rsync -avze ssh rhythm@threeprodds2:/var/log/httpd/ /var/log/httpd/Three/threeprodds2/&
rsync -avze ssh rhythm@threeprodds3:/var/log/httpd/ /var/log/httpd/Three/threeprodds3/&
rsync -avze ssh rhythm@threeprodds4:/var/log/httpd/ /var/log/httpd/Three/threeprodds4/&
rsync -avze ssh rhythm@threeprodds5:/var/log/httpd/ /var/log/httpd/Three/threeprodds5/&



As you can see, this script is used to synchronize log files down to this local system. Some "logger" statements have been added to generate useful log messages on this host as well.

Running It

The cool thing is that once you set this up, there is nothing left to do. Sit back, relax, and enjoy synchronized logs.

For more information on rsync over SSH as used in the script, stick around linfactory.

Tuesday, December 11, 2007

Monitoring a File's Age with Nagios

Sometimes when running Linux you need to know how long a file has been sticking around. One great example is the presence and age of a lock file. In this case, I'm running a repository syncing tool called cobbler and I want to make sure it is running successfully

Nagios

Nagios is an open source monitoring software package. I've been using Nagios since its earlier name Netsaint was still in effect. Nagios will be the subject of another post here on linfactory so stick around.

Plugins

Plugins do the heavy lifting for Nagios. These plugins are small pieces of code that do something useful like check a ping timeout or in this case, a file's existence and age.

Check_file_age

I found a stock plugin called check_file_age. Here's how it works:

-sh-3.00$ /usr/lib/nagios/plugins/check_file_age --help
check_file_age (nagios-plugins 1.4.2) $Id: check_file_age.pl,v 1.2 2003/10/21 15:56:35 tonvoon Exp
The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
Copyright (c) 2003 Steven Grimm

Usage:
check_file_age [-w ] [-c ] [-W ] [-C ] -f
check_file_age [-h | --help]
check_file_age [-V | --version]

File must be no more than this many seconds old
File must be at least this many bytes long

Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net.
Please include version information with all correspondence (when possible,
use output from the --version option of the plugin itself).


Test Invocation


[nagios@lnciserver1 ~]$ /usr/lib/nagios/plugins/check_file_age -f /var/lib/cobbler/lock -w 3600 -c 7200
/var/lib/cobbler/lock: File not found


So, the check_file_age plugin tells us that this file is missing.

Let's look at the return code.

[nagios@lnciserver1 ~]$ echo $?
3


A non-zero return code indicates a problem. In this case the 3 corresponds to "UNKOWN." Nagios doesn't know what to make of this situation. I need to tweak this plugin. No problem, this is open source after all. I need to allow for the absence of the file as this is okay in my situation. That would just indicate the cobbler has cleaned up successfully and deleted its lock file.

Modification

For the cobbler case above, we need this situation to retun a 0.

Here's the change.

-sh-3.00$ diff -c /usr/lib/nagios/plugins/check_file_age /usr/lib/nagios/plugins/check_file_age2
*** /usr/lib/nagios/plugins/check_file_age 2006-03-06 23:57:22.000000000 +0000
--- /usr/lib/nagios/plugins/check_file_age2 2007-10-19 23:26:24.000000000 +0000
***************
*** 74,80 ****
# Examine the file.
unless (-f $opt_f) {
print "$opt_f: File not found\n";
! exit $ERRORS{'UNKNOWN'};
}

$st = File::stat::stat($opt_f);
--- 74,80 ----
# Examine the file.
unless (-f $opt_f) {
print "$opt_f: File not found\n";
! exit $ERRORS{'OK'};
}

$st = File::stat::stat($opt_f);


Invoking the Plugin

Now that we have a modified plugin in place, we'll run it to see what is up with our cobbler server.

Invocation Take Two


[nagios@lnciserver1 ~]$ /usr/lib/nagios/plugins/check_file_age2 -f /var/lib/cobbler/lock -w 3600 -c 7200
/var/lib/cobbler/lock: File not found
[nagios@lnciserver1 ~]$ echo $?
0


All good!

Monday, December 10, 2007

Fun with Fdisk

When managing disks under Linux, one of the most powerful and lowest level tools you will need to use is called fdisk. Fdisk has been around for a long time and even has use in the Microsoft world. Today, however, we will deal with linux fdisk. The Linux fdisk is a used to manipulate the partition table of disks.


Partition Table


Hard disks can be divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the disk. Fdsik manpage.

Example Partition Table

This is the partition table for a production Linux database server. The server has two disks. First, let us examine the first disk, referred to in Linux parlance as /dev/sda.

To do so, run the fdisk command and pass the argument /dev/sda to tell fdisk to look at the first disk. At the prompt, hit "p" to print the table. Pressing "m" will show you all the options.

[root@lncproddb2 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 8844.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 72.7 GB, 72746008576 bytes
255 heads, 63 sectors/track, 8844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 8844 70935007+ 8e Linux LVM


Above we see the partition table for /dev/sda on production host lncproddb2. The /dev/sda device or disk contains two partitions /dev/sda1, and /dev/sda2. The first partition, /dev/sda1 starts at the beginning of the disk, or cylinder 1 and goes to cylinder 13. It is of type 83, or Linux.

The second partition on /dev/sda is /dev/sda2. It begins on the following cylinder, number 14, and goes to the end of the disk. The /dev/sda2 partition is of type 8e known as Linux LVM which stands for Logical Volume Manager. The disk has a total of 8844 cylinders. We can also see above the this is a 72.7 GB SCSI disk.

Scanning the Bus

Some Linux machines will have more than one disk. In this case, it is helpful to scan the bus to see how many disks are there and what they are called. You can scan the bus with the fdisk -l command.

[root@lncproddb2 ~]# fdisk -l

Disk /dev/sda: 72.7 GB, 72746008576 bytes
255 heads, 63 sectors/track, 8844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 8844 70935007+ 8e Linux LVM

Disk /dev/sdb: 218.9 GB, 218909114368 bytes
255 heads, 63 sectors/track, 26614 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


Here we see the /dev/sda again as described above. There is a second hard disk, /dev/sdb that is available on this system as well.