Wednesday, November 9, 2011

Lifeline
Lifeline Communiqué
Communiqué
Date: 09th Nov 2011
Tip of the Day:
      
Hardware Vs Software RAID
Feature
Software RAID Hardware RAID
Cost: High
Low
Software RAID is part of OS, so no need to spend extract money.
Complexity: Low
The software RAID works on partition level and it can sometime
Medium to high
increase complexity if you mix different partitions and hardware
RAID.
Write back caching (BBU): Yes
The software RAID cannot add a battery. Hardware RAID can
run in write-back mode if it has a BBU installed. With BBU
pending writes are not lost on a power failure.
No
Performance: High
With the software based RAID0 and RAID1 performance is
negligible. However, performance goes down when you use
Depend upon
parity-based arrays and/or several arrays at the same time. The
usage
performance of a software-based array is dependent on the server
CPU performance and current load.
Overheads (CPU, RAM etc): No
The software RAID must use server's CPU and RAM for RAID
Depend upon
software. The more hard drives means more CPU cycle will go to
usage
software RAID instead of your Apache / Postfix or MySQL
server.
Disk hot swapping: Yes
It means replacing hard disk without shutting down the server.
Many RAID controller supports disk hot swapping.
No
Regards, Team TSG, Infrastructure Availability
Services
Hot spare support: Yes
A hard disk is physically installed in the array which stays
inactive until an active drive fails, when the system automatically Yes
replaces the failed drive with the spare, rebuilding the array with
the spare hard disk included.
/boot partition: No Yes
It is hard to make fail over with software RAID if /boot fails
while booting the server. This can result into unexpected errors
and data loss. However, LILO and FreeBSD loader can get
around this problem too.
Open source factor: No
*BSD / OpenSolaris and Linux RAID software drivers are open
source. It means more people can fix problems as compare to a Yes
closed source hardware firmware. You can move, mix and match
different sizes with open source software RAID.
Vendor lock in (open formats): See above. No Yes
Higher write throughput: No Yes
Hardware RAID with BBU may offers higher write throughput.
Faster rebuilds: Yes
Hardware RAID with BBU may offers faster rebuilds as compare No
to software based solution.
Can act as a backup solution?: No No
Both software and hardware RAID cannot protect you against
human errors or system failures or viruses. Daily scheduled and
off site backups of your system are highly recommended. Use
tools such as rsync, rsnapshot, tar, dump, restore and others to
make daily backups.
Recommend usage: +Low cost +Do you run a
                 solution mission critical
                 +Better for cluster or setup?
                 RAID0 or +Heavy database
                 RAID1 driven dynamic
                 +Single server / site
                 workstation +Do you want the
                 +Perfect for highest
                 home and small performance
                 business users. possible?
                 +No vendor lock-
                 ins
Regards, Team TSG, Infrastructure Availability
Services

Sunday, November 6, 2011

Browser Statistics

Browser Statistics Month by Month

2011 Internet Explorer Firefox Chrome Safari Opera
September 22.9 % 39.7 % 30.5 % 4.0 % 2.2 %
August 22.4 % 40.6 % 30.3 % 3.8 % 2.3 %
July 22.0 % 42.0 % 29.4 % 3.6 % 2.4 %
June 23.2 % 42.2 % 27.9 % 3.7 % 2.4 %
May 24.9 % 42.4 % 25.9 % 4.0 % 2.4 %
April 24.3 % 42.9 % 25.6 % 4.1 % 2.6 %
March 25.8 % 42.2 % 25.0 % 4.0 % 2.5 %
February 26.5 % 42.4 % 24.1 % 4.1 % 2.5 %
January 26.6 % 42.8 % 23.8 % 4.0 % 2.5 %
         

Friday, November 4, 2011

PHP String Variables

A string variable is used to store and manipulate text.

String Variables in PHP

String variables are used for values that contain characters.
In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP.
After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.
Below, the PHP script assigns the text "Hello World" to a string variable called $txt:
<?php
$txt="Hello World";
echo $txt;
?>
The output of the code above will be:
Hello World
Now, lets try to use some different functions and operators to manipulate the string.

The Concatenation Operator

There is only one string operator in PHP.
The concatenation operator (.)  is used to put two string values together.
To concatenate two string variables together, use the concatenation operator:
<?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>
The output of the code above will be:
Hello World! What a nice day!
If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string (a space character), to separate the two strings.


The strlen() function

The strlen() function is used to return the length of a string.
Let's find the length of a string:
<?php
echo strlen("Hello world!");
?>
The output of the code above will be:
12
The length of a string is often used in loops or other functions, when it is important to know when the string ends. (i.e. in a loop, we would want to stop the loop after the last character in the string).

The strpos() function

The strpos() function is used to search for a character/text within a string.
If a match is found, this function will return the character position of the first match. If no match is found, it will return FALSE.
Let's see if we can find the string "world" in our string:
<?php
echo strpos("Hello world!","world");
?>
The output of the code above will be:
6
The position of the string "world" in the example above is 6. The reason that it is 6 (and not 7), is that the first character position in the string is 0, and not 1.

PHP String Variables

A string variable is used to store and manipulate text.

String Variables in PHP

String variables are used for values that contain characters.
In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP.
After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.
Below, the PHP script assigns the text "Hello World" to a string variable called $txt:
<?php
$txt="Hello World";
echo $txt;
?>
The output of the code above will be:
Hello World
Now, lets try to use some different functions and operators to manipulate the string.

The Concatenation Operator

There is only one string operator in PHP.
The concatenation operator (.)  is used to put two string values together.
To concatenate two string variables together, use the concatenation operator:
<?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>
The output of the code above will be:
Hello World! What a nice day!
If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string (a space character), to separate the two strings.


The strlen() function

The strlen() function is used to return the length of a string.
Let's find the length of a string:
<?php
echo strlen("Hello world!");
?>
The output of the code above will be:
12
The length of a string is often used in loops or other functions, when it is important to know when the string ends. (i.e. in a loop, we would want to stop the loop after the last character in the string).

The strpos() function

The strpos() function is used to search for a character/text within a string.
If a match is found, this function will return the character position of the first match. If no match is found, it will return FALSE.
Let's see if we can find the string "world" in our string:
<?php
echo strpos("Hello world!","world");
?>
The output of the code above will be:
6
The position of the string "world" in the example above is 6. The reason that it is 6 (and not 7), is that the first character position in the string is 0, and not 1.

PHP Variables

A variable is used to store information.

Variables in PHP

Variables are used for storing values, like text strings, numbers or arrays.
When a variable is declared, it can be used over and over again in your script.
All variables in PHP start with a $ sign symbol.
The correct way of declaring a variable in PHP:
$var_name = value;
New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.
Let's try creating a variable containing a string, and a variable containing a number:
<?php
$txt="Hello World!";
$x=16;
?>


PHP is a Loosely Typed Language

In PHP, a variable does not need to be declared before adding a value to it.
In the example above, you see that you do not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on its value.
In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it.
In PHP, the variable is declared automatically when you use it.

Naming Rules for Variables

  • A variable name must start with a letter or an underscore "_"
  • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
  • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)

PHP Syntax

Basic PHP Syntax

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with <? and end with ?>.
For maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.
<?php
?>
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:
<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html>
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.

Comments in PHP

In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.
<html>
<body>

<?php
//This is a comment

/*
This is
a comment
block
*/
?>

</body>
</html>

PHP Installation

What do you Need?

If your server supports PHP you don't need to do anything.
Just create some .php files in your web directory, and the server will parse them for you. Because it is free, most web hosts offer PHP support.
However, if your server does not support PHP, you must install PHP.
Here is a link to a good tutorial from PHP.net on how to install PHP5: http://www.php.net/manual/en/install.php

Download PHP

Download PHP for free here: http://www.php.net/downloads.php

Download MySQL Database

Download MySQL for free here: http://www.mysql.com/downloads/

Download Apache Server

Download Apache for free here: http://httpd.apache.org/download.cgi

Introduction of PHP

What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software
  • PHP is free to download and use

What is a PHP File?

  • PHP files can contain text, HTML tags and scripts
  • PHP files are returned to the browser as plain HTML 
  • PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

  • MySQL is a database server
  • MySQL is ideal for both small and large applications
  • MySQL supports standard SQL
  • MySQL compiles on a number of platforms
  • MySQL is free to download and use

PHP + MySQL

  • PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Why PHP?

  • PHP runs on different platforms (Windows, Linux, Unix, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP is FREE to download from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side

Where to Start?

To get access to a web server with PHP support, you can:
  • Install Apache (or IIS) on your own server, install PHP, and MySQL
  • Or find a web hosting plan with PHP and MySQL support

Thursday, November 3, 2011

How to create and execute, run php file on windows

So you installed WampServer on Windows.
Now how to create and execute or run you php file on windows ???

First START WampServer by clicking your START MENU and then selecting WampServer and then click start WampServer.

Once Server is started then you will see a WampServer icon in the right corner of your taskbar where your clock is present.

Now open the drive where you installed your wampserver.(ex. C:/wamp/)
Then open the www folder. (ex. C:/wamp/www/)
This is your Base directory, your all projects will come here.

Now create a directory here named mytest.
Now open notepad or any other text editor you have. Type the following in it.


  1. <?php  
  2. phpinfo();  
  3. ?>  


Save the file to the directory mytest as index.php


Now click on the icon present in the right hand side of your taskbar and then click on localhost
Now you will see the list of projects, then click on mytest, you can see that your program is executed.
It will show you all the details of the php version you have installed.

How to use PHP on Windows - WampServer

Many of us use windows operating system and want to know how to use php on Windows operating system ?

For this there is a very simple and useful solution. Even you don't have to setup & configure many things.

Following things are required for using php on windows

  • Apache Server
  • Mysql
  • PHP
WampServer is a Windows web development environment. With this we can create web applications with Apache, PHP and the MySQL database. Even PHPMyAdmin is provided to manage your databases.

Just Download WampServer and install it and you are done. WampServer is an open source project, free to use.

Share your blog links, blogs, websites

Hi Friends, linuxopensourceindia.blogspot.com is a place to share experience and knowledge.
You can Help us to spread the word either by forwarding this URL or putting this on your blog or website.
Even I am thinking of putting a section which will list the useful resources for programming, so if you have a blog or website which is related to php, php codes, php scripts, ajax, css, html,open source or if its technical blog then please contact me by writing a comment here about your blog, i will definitely like to add your link here on my blog.
Because to share our knowledge it has to be accessible to other many people. So lets help each other to share knowledge.


We all can have a section on our blog or website to share some useful resources which also helps in link building & SEO(Search Engine Optimization) and promotion.

Your comments are always welcome about this idea, whether is good or bad.
I am waiting for your reply.

Thank you.

php for beginners

f you are a beginner to php then there are some useful resources available on the net to start with.
You can go through following sites to get information.

1) http://www.w3schools.com/PHP/ - This is a very useful website explaining many functions with examples.

more links will be here........

What is PHP

PHP (Hypertext Pre-Processor)

PHP is a scripting language used for producing dynamic webpages.
PHP is a free open-source server-side scripting language. 
PHP code can be embedded in HTML.

You can find the more information about php on the following Wiki link.

http://en.wikipedia.org/wiki/PHP

Network-Based Linux Installation

Introduction

Fedora Linux allows you to do operating system installations via a network connection using a Kickstart server. It is frequently much faster than using CDs and the process can be automated. The procedure is fairly simple:
  • Connect the new server (installation client) to the same network as the server with the pre-loaded installation files (installation server).
  • Boot the installation client from a specially created boot CD
  • Enter your preferred installation method (FTP, HTTP, NFS) and the needed network parameters to do this
  • The installation procedure will then continue with the more familiar Fedora Linux installation screens. Enter your selections and then complete the installation.
This chapter will briefly explain how to set this up using all three methods using a single installation server (bigboy) with an IP address of 192.168.1.100.

Setting Up The Kickstart Server

Kickstart can be configured on an FTP, NFS or Apache server. Each method is explained below, but my experience has been that the Apache server has a number of advantages over the other two.
Using a web server for kickstart is generally easier because:
  • Sometimes a kickstart server has to be located on a remote network, often passing through a firewall. Strict firewall rules for HTTP are generally easier to configure than those for FTP or NFS.
  • The http:// nomenclature used by kickstart for accessing files is more familiar to users than that used for NFS and FTP. This may be important for you when configuring files for automated kickstart installation.

Basic Preparation

In this example we are going to set up a kickstart server that will be used in Fedora Core installations. All the necessary files will be placed in the /data/network-install directory.

Create The Installation Directories

We'll first create the directories /data/network-install/RPM and /data/network-install/ISO in which we will copy the necessary files.
[root@bigboy tmp]# mkdir -p /data/network-install/RPM
[root@bigboy tmp]# mkdir -p /data/network-install/ISO
You now need to place the network installation driver files into the base directory.

Copying The Files

The HTTP, NFS and FTP kickstart methods all require the base set of Fedora files to be installed on the kickstart server. Here's how to do it:
1) Create a mount point for your CD ROM drive.
[root@bigboy tmp]# mkdir /mnt/cdrom
2) Mount your first Fedora CD ROM.
[root@bigboy tmp]# mount /dev/cdrom /mnt/cdrom
3) Copy the files from the CD ROM base directory to the hard disk
[root@bigboy tmp]# cp -r /mnt/cdrom/* /data/network-install/RPM
4) Unmount your CD ROM and use the eject command to retrieve it from the drive bay.
[root@bigboy tmp]# umount /dev/cdrom
[root@bigboy tmp]# eject cdrom
5) Repeat steps 2 to 4 with all your CDROMs. Overwrite files when prompted.
Note: Note: You also have the option to FTP all the files of the desired version of Fedora from the Fedora website to the /data/network-install/RPM directory.

HTTP & FTP Preparation

Copy all the contents of each installation CD to the /data/network-install/RPM directory. This will require about 3-5 GB of space. When this is completed, your /data/network-install/RPM directory should look like this:
[root@bigboy tmp]# ls -1 /data/network-install/RPM
eula.txt
Fedora
fedora.css
GPL
images
index.html
isolinux
README-Accessibility
RELEASE-NOTES-en_US.html
repodata
RPM-GPG-KEY
RPM-GPG-KEY-beta
RPM-GPG-KEY-fedora
RPM-GPG-KEY-fedora-extras
RPM-GPG-KEY-fedora-legacy
RPM-GPG-KEY-fedora-rawhide
RPM-GPG-KEY-fedora-test
RPM-GPG-KEY-rawhide
stylesheet-images 
[root@bigboy tmp]#

NFS Preparation

Create ISO images of the installation CDs and place them in the /data/network-install/ISO directory. This will require about 3-5 GB of space as well. You can download the ISO images from the Fedora website or use the Fedora CDs as shown below. If you create the ISOs files from CDs, make sure they have the same file names as the ones you can download from the Fedora Web site.
Follow these steps for each CD, substituting the filename where necessary:
[root@bigboy tmp]# cd /data/network-install/ISO
[root@bigboy ISO]# dd if=/dev/cdrom of=filename.iso bs=32k
...
...
[root@bigboy ISO]# eject cdrom
Note: Here is a sample procedure to make ISO files with the older mkisofs command. You may have to install the mkisofs RPM on newer Fedora versions. The command requires a mounted CDROM drive, so don't forget the mount command.
[root@bigboy ISO]# mount /mnt/cdrom
[root@bigboy ISO]# mkisofs -J -r -T -o filename.iso /mnt/cdrom
[root@bigboy ISO]# eject cdrom

Setup Your Webserver

You will now have to setup Apache to give the file listings of your /data/network-install/RPM and /data/network-install/ISO directories by pointing your browser to the URL http://192.168.1.100/network-install/RPM/ or http://192.168.1.100/network-install/ISO/ respectively. A sample /etc/httpd/conf.d/kickstart.conf configuration is below. Remember to restart Apache to make these settings take effect.
NameVirtualHost 192.168.1.100
 
#
# For HTTP Installations
#
<VirtualHost 192.168.1.100>
  ServerName 192.168.1.100
  DocumentRoot /data/
</VirtualHost>

<Directory /data/network-install>
   Options +Indexes
   AllowOverride AuthConfig
   order allow,deny
   allow from all
</Directory>

Setup Your FTP Server

You'll also have to set up your VSFTPD server to make incoming anonymous FTP connections log in to the /data/network-install/RPM directory by default. You will also want to enable the correct logging. Here is a sample snippet of the vsftpd.conf file. Remember to restart VSFTPD to make these settings take effect
#
# File: vsftpd.conf
#

#
# Anonymous FTP Root Directory
#

anon_root=/data/network-install/RPM

#
# Log file definition
#

xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log

Create A Special FTP User

You can also create a special user for non anonymous FTP installations with its home directory as "/". You must also make sure that the user has read access to the /data/network-install directory. An example is below.
[root@bigboy tmp]# useradd -g users ftpinstall
[root@bigboy tmp]# passwd ftpinstall
Changing password for user ftpinstall.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@bigboy tmp]#
[root@bigbot tmp]# usermod -d / ftpinstall
[root@bigbot tmp]#

Setup Your NFS Server

The steps for setting up an NFS server are more complicated.
1) Create a /etc/exports file with the following entry in it. You must use tabs, not spaces between the entries
/data/network-install    *(ro,sync)
2) Make sure that the rpcbind (portmap on older versions of Linux) , nfs, nfslock and netfs daemons are all running to create an NFS server. The startup scripts for these are found in the /etc/init.d directory. 
3) Run the exportfs command to add this directory to the NFS database of network available directories.
[root@bigboy tmp]# exportfs -ra
4) The installation client must have a matching pair of forward and reverse DNS entries on your DNS server. In other words, a DNS lookup on the IP address of the installation client must return a server name that will map back to the original IP address when a DNS lookup is done on that same server name.
[root@bigboy tmp]# host 192.168.1.96
96.1.168.192.in-addr.arpa domain name pointer 192-168-1-96.my-site.com.
[root@bigboy tmp]#
 
[root@bigboy tmp]# host 192-168-1-96.my-site.com
192-168-1-96.my-site.com has address 192.168.1.96
[root@bigboy tmp]#
This may mean that you will have to create entries for all your DHCP IP addresses if you choose to use a DHCP method of assigning IP addresses during installation.

Configure Your DHCP Server

During the installation procedure, the installation client will prompt you for the IP address it should use for the installation process. I recommend selecting the option that makes the Installation Client get its address via DHCP. This will automate the installation more and will therefore make it faster. It will also reduce the possibility of human error.


Creating A Kickstart Boot CD

Creating a kickstart boot CD is easy to do. Here are the steps:
1. Your RPM directory should have a subdirectory named images in it. There will be a file there named boot.iso which is used in booting your system when installing Linux from DVD or CD. Fedora mirror sites that have directory structures similar to that of the DVD also have a boot.iso file located in the <fedora-version>/Fedora/i386/os/images/ directory. This file is different in both size and function to that on your DVD. It usually larger than 10 MB in size and it is the boot file you need for kickstart. Download the boot.iso file from your favorite mirror site using a utility like wget.
[root@bigboy tmp]# wget http://website.org/8/Fedora/i386/os/images/boot.iso
2. You will now need the device name of your CDROM device. This can be obtained using the wodim command. In this case it is called /dev/scd0.
[root@bigboy tmp]# wodim --devices
wodim: Overview of accessible drives (1 found) :
-------------------------------------------------------------
 0  dev='/dev/scd0'     rwr--- : 'LITE-ON' 'DVDRW LH-20A1P'
-------------------------------------------------------------
[root@bigboy tmp]#
3. Insert a blank CD. The wodim command can now be used again to burn the boot.iso ISO image file to the CD.
[root@bigboy tmp]# wodim dev=/dev/scd0 driveropts=burnfree,noforcespeed \
fs=14M -dao -eject -overburn -v boot.iso
...
...
...
BURN-Free was never needed.
wodim: fifo had 6 puts and 6 gets.
wodim: fifo was 0 times empty and 0 times full, min fill was 100%.
[root@bigboy RPM]# 
Keep the CD. You will soon need it for your kickstart client machine.

The Network Installation

From here on, the installation procedure mimics the regular Linux installation, except for the first couple steps.
  • Connect your client Linux box to the DHCP network.
  • Boot your system using the kickstart boot CD. This is the only CD you'll need for future network installations.
  • A menu will appear. Select “Install or upgrade an existing system”.
  • Go through the usual steps until the process prompts for the "Installation Method". You will see a number of choices
Local CDROM
Hard Drive
NFS Image
FTP
HTTP
  • Select the network option of your choice (NFS, FTP, HTTP)
  • Select the Ethernet device to which the installation client is connected to the installation server network. This would most likely be interface "eth0".
  • Select "DHCP" in the following "Configure TCP/IP" screen. This will make the Installation client use DHCP during the installation.

If You Selected The NFS Method

You will now reach the "NFS setup" menu. Enter the IP address of the installation server as the "NFS Server Name". The "Red Hat directory" will be "/data/network-install/ISO". The following menus will be the usual Fedora GUI installation screens.

If You Selected The HTTP Method

You will now reach the "HTTP Setup" menu. Enter the IP address of the installation server when prompted for a "Web site name".The "Red Hat directory" will be /network-install/RPM. The following menus will be text based versions of the usual Fedora installation screens.
During the installation, issue the following command on the server to check the Apache logs. It will help to verify whether the kickstart client is accessing the files correctly. You should get a status code of 200<code> after each GET statement. You should retrace your steps if you are not.

[root@bigboy tmp]# tail -f /var/log/httpd/access_log
192.168.1.247 - - [12/Nov/2006:12:01:04 -0800] "GET /network-install/RPM/repodata/repomd.xml HTTP/1.1" 200 1140 "-" "urlgrabber/2.9.9"
192.168.1.247 - - [12/Nov/2006:12:01:05 -0800] "GET /network-install/RPM/repodata/primary.xml.gz HTTP/1.1" 200 844228 "-" "urlgrabber/2.9.9"
192.168.1.247 - - [12/Nov/2006:12:01:19 -0800] "GET /network-install/RPM/repodata/comps.xml HTTP/1.1" 200 853899 "-" "urlgrabber/2.9.9"

If You Selected The FTP Method

You will now reach the "FTP Setup" menu. Enter the IP address of the installation server as the "FTP Site Name".
  • "Not Selecting" The Non-Anonymous FTP Box
The "Red Hat directory" will be "/". The following menus will be text based versions of the usual Fedora installation screens.
  • "Selecting" The Non-Anonymous FTP Box
The "Red Hat directory" will be "/data/network-install/RPM". Enter the username and password of your special FTP user account. The following menus will be text based versions of the usual RedHat installation screens.
Note: During the installation, issue the following command on the server to check the FTP logs. It will help to verify whether the kickstart client is accessing the files correctly.
[root@bigboy ~]# tail -f /var/log/vsftpd.log 
Sun Nov 12 20:53:12 2006 1 192.168.1.231 1140 /data/network-install/RPM/repodata/repomd.xml b _ o r ftp-install ftp 0 * c
Sun Nov 12 20:53:21 2006 2 192.168.1.231 844228 /data/network-install/RPM/repodata/primary.xml.gz b _ o r ftp-install ftp 0 * c
Sun Nov 12 20:53:40 2006 2 192.168.1.231 853899 /data/network-install/RPM/repodata/comps.xml b _ o r ftp-install ftp 0 * c

Troubleshooting The Network Installation

You can do some basic troubleshooting by accessing the various installation status screens available.
  • The installation logs can always be viewed by hitting <CTRL-ALT-F3>
  • Kernel messages can be seen by hitting <CTRL-ALT-F4>
  • Access to a limited BASH shell Kernel can be gained by hitting <CTRL-ALT-F2>
  • You can return to the main installation screen at any time by hitting <CTRL-ALT-F1> for text based installations and <CTRL-ALT-F7> when the GUI is used.
  • Examine your server's <code>/var/log/httpd/access_log, /var/log/httpd/error_log files for the HTTP method; the /var/log/vsftpd.log file for the FTP method; and your /var/log/messages file for the NFS method.


Automating Installation With Kickstart

Both Fedora and RedHat Linux save all the parameters you used during installation in the /root/anaconda-ks.cfg kickstart configuration file. You can use this file to create an automated installation of a duplicate system which can be useful if you have a large number of servers to install.
This section shows you how to automate network installations using the kickstart application and NFS. You can use HTTP and FTP but they have been omitted to keep the discussion brief.

How To Create New Kickstart Configuration Files

You can create a customized kickstart configuration file by using the "ksconfig" command from a GUI console. It will bring up a menu from which you can select all your installation options. When finished, you save the configuration with the filename of your choice.
You may want to then edit the configuration file and comment out certain parameters that may change from system to system with a "#". These could include things like the system's name and IP address. During the kickstart process you will be prompted for these unspecified values.
Note: Do not change the order of the entries in the kickstart configuration file.
Note: The IP address you assign must be on the same subnet as that of the DHCP server for kickstart to work. If the server is going to reside on a different network after the installation, then you'll have to run a separate script to change the IP addressing information after the installation is complete.

Adding Post Installation Commands

You may want to run some commands on the newly created Linux installation after kickstart is complete. Some processes that are activated by default by Fedora may not be suitable for your server and may need to be disabled.
This can be done by placing a %post section at the end of the kicksrart file with all the post installation commands you wish to run. Here is an example:
%post
chkconfig isdn off
chkconfig pcmcia off
chkconfig portmap off
chkconfig apmd off
chkconfig nfslock off
chkconfig nfs off

A Note About Using anaconda-ks.cfg

It is possible to use the /root/anaconda-ks.cfg file as a template for future installations. RedHat comments out the partitioning information in this file, so you will either have to uncomment it and then make your partitioning modifications or be prepared to be prompted for your portioning information.

How To Run A Kickstart Installation

It is best to place your kickstart files in a subdirectory under the /data/network-install directory. The examples below assume the subdirectory is called /data/network-install/kickstart.
Remember that you may want to remove the "#" comments from the partition section of the file. If not, you will be prompted for this information.

Using a NFS Server

Verify that the first two lines of the file look like this or else you may be prompted for NFS ISO file location information.
install
nfs --server=192.16.1.100 --dir=/data/network-install/ISO

Using a Web Server

Verify that the first two lines of the file look like this or else you may be prompted for RPM base file location information.
install
url --url http://192.168.1.100/network-install/RPM

Booting With Your Kickstart Files

There are two ways to specify the name of the kickstart file to use. The first is to enter it manually from the LILO boot: prompt when you insert the boot CD. The second is to have your DHCP server automatically tell the Kickstart client about the name of the kickstart file to use when it assigns the IP address. Both methods are listed below:
Manually Specifying the Kickstart Filename
Once you have booted from your boot CDROM, you'll need to use the following command at the lilo boot: prompt to continue with the installation. The ks.cfg file is the kickstart configuration file we want to use.
NFS Method
boot: linux ks=nfs:192.168.1.100:/kickstart/ks.cfg
HTTP Method
boot: linux ks=http://192.168.1.100/network-install/kickstart/ks.cfg
Configuring The Filename Automatically
Whenever you have to create lots of cloned Linux servers, then you may want to configure your DHCP server to specify the single kickstart configuration file you wish to use. Here is how it's done:
1) Place your kickstart file in the /data/network-install/kickstart directory.
2) Edit your dhcpd.conf file and add the following lines to the section for the interface that will be serving DHCP IP addresses. The next-server value is the IP address of the kickstart server.
filename "/data/network-install/kickstart/ks.cfg";
next-server 192.168.1.100;
3) Insert the boot CD into the kickstart client Linux box and connect it to the DHCP network. At the boot: prompt type in the following command:
boot: linux ks
Kickstart will first search for a configuration file named ks.cfg on either the boot CD. It will then automatically attempt to get a DHCP IP address and see if the DHCP server will specify a configuration file.
Kickstart will then use NFS to get both the configuration file and the installation ISOs. The rest should be automatic.

Conclusion

The Kickstart method of Fedora Linux installation can greatly reduce the length of time it takes to install the operating system. Time is saved not only because a network connection can be faster than using CDs, but also because it can be left unattended to install a predetermined Linux configuration. A Kickstart server connected to an isolated wireless network dedicated to the purpose may be a good idea for data centers with hundreds of Linux servers.

Modifying the Kernel to Improve Performance

Introduction

Like a government that rules a nation and all its provinces, the Linux kernel is the central program that not only governs how programs interact with one another, but also provides the guidelines on how they should use the computer's core infrastructure, such as memory, disks, and other input/output (I/O) devices for the user's benefit.
Linux drivers, the programs that manage each I/O device, are the staff that keeps all the government departments running. Continuing with the analogy, the more departments you make the kernel manage, the slower Linux becomes. Large kernels also reduce the amount of memory left over for user applications. These may then be forced to juggle their memory needs between RAM and the much slower swap partitions of disk drives, causing the whole system to become sluggish.
The Fedora installation CDs have a variety of kernel RPMs, and the installation process autodetects the one best suited to your needs. For this reason, the Fedora Linux kernel installed on your system is probably sufficient. The installation process chooses one of several prebuilt kernel types depending on the type of CPU and configuration you intend to use (Table 33-1).

Table 33-1: Kernels Found On Fedora Installation CDs

Processor Type Configuration
i586 Single processor
i586 Multiprocessor (SMP)
i686 Single processor
i686 Multiprocessor (SMP)

The Pros And Cons Of Kernel Upgrades

Despite this best fit installation, you may want to rebuild the kernel at times. For example, there is no installation RPM for multiprocessor systems with large amounts of memory. You may also want to experiment in making a high-speed Linux router without support for SCSI, USB, Bluetooth, and sound but with support for a few NIC drivers, an IDE hard drive, and a basic VGA console. This would require a kernel rebuild.
Rebuilding the kernel in a small business environment is usually unnecessary. If your system starts to slow down and you can't afford to replace hardware or are unable to add more RAM, however, you may want to tune the kernel by making it support only necessary functions or updating built-in parameters to make it perform better. Sometimes new features within the new kernel are highly desirable; for example, the version 2.6 kernel has much more efficient data handling capabilities than the older version 2.4, providing new life for old hardware.
Kernel tuning on a production server shouldn't be taken lightly, because the wrong parameters could cause your system to fail to boot, software to malfunction, or hardware peripherals to become unavailable. Always practice on a test system and keep a backup copy of your old kernel. Whenever possible, hire a consultant with kernel experience to help, and use this chapter and other references as a guide to prepare you for what to expect.
This chapter provides only an overview of the steps to take. It won't make you an expert, but it will expose you to the general process and provide greater confidence when you need to research the task with a specialized guide.

The Kernel Sources Package

You will need to install the kernel source code on your system prior to modifying your kernel. As of Fedora Core 3, the kernel sources come as a source RPM package that matches the version of the kernel you are running. In Fedora Core 2 and earlier, the Kernel sources came as a generic RPM package called kernel-source, the installation of which is covered in Appendix III, "Fedora Version Differences".
The newer method is more complicated as it requires a number of post installation steps. Though the process is well documented in the release notes section of the Fedora website (http://fedora.redhat.com/docs/release-notes/) there are some clarifications that are needed. These are explained in the following section.

Installing Kernel Sources

The installation process for the kernel sources is long, but not very complicated. Here is how it's done:
1. Determine the version of your kernel with the uname command. In this case it is version 2.6.14-1.1644.
[root@bigboy tmp]# uname -r
2.6.14-1.1644_FC4smp
[root@bigboy tmp]#
2. Visit your favorite Fedora operating system download mirror and get the corresponding source RPM package. If you are running the original version of the kernel that came with your installation discs, then the sources will be located in the /core/<version>/i386/os/SRPMS/ directory. If the kernel has been updated using yum or some other method, the sources will be located in the /core/updates/<version>/SRPMS/ directory. In this example the sources of an updated Core 4 kernel is downloaded from the /core/updates/4/SRPMS/ directory of http://download.fedora.redhat.com using wget.
[root@bigboy tmp]# wget
http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.14-1.1644_FC4.src.rpm
--15:32:22-- 
http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.14-1.1644_FC4.src.rpm
           => `kernel-2.6.14-1.1644_FC4.src.rpm'
Resolving download.fedora.redhat.com... 66.187.224.20,
209.132.176.20, 209.132.176.220, ...
Connecting to
download.fedora.redhat.com|66.187.224.20|:80...
connected.
HTTP request sent, awaiting response... 200 OK
Length: 40,454,218 (39M) [application/x-rpm]

100%[=========================>] 40,454,218   862.89K/s    ETA 00:00

15:33:10 (842.22 KB/s) -
`kernel-2.6.14-1.1644_FC4.src.rpm' saved
[40454218/40454218]

[root@bigboy tmp]#
3. Install the contents of the RPM file into the /usr/src/redhat/SOURCES and /usr/src/redhat/SPECS directories using the rpm command.
[root@bigboy tmp]# rpm -Uvh kernel-2.6.14-1.1644_FC4.src.rpm 
   1:kernel                 ########################################### [100%]
[root@bigboy tmp]#
4. The kernel source directory tree will have to be created next. Enter the /usr/src/redhat/SPECS directory and create the tree using the rpmbuild command with the -bp option.
[root@bigboy tmp]# cd /usr/src/redhat/SPECS
[root@bigboy SPECS]# ls
kernel-2.6.spec
[root@bigboy SPECS]# rpmbuild -bp --target $(arch) kernel-2.6.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.44004
+ umask 022
+ cd /usr/src/redhat/BUILD
...
...
...
removed `./init/Kconfig.orig'
removed `./init/main.c.orig'
+ find . -name '*~' -exec rm -fv '{}' ';'
+ exit 0
[root@bigboy SPECS]#
5. The tree has now been created in the /usr/src/redhat/BUILD/kernel-<version> directory. You can link, move or copy this directory to become /usr/src/linux depending on your needs and the likelihood of you compiling multiple kernel versions in future. In this case, the tree is moved and then linked.
[root@bigboy SPECS]# cd /usr/src/redhat/BUILD/kernel-2.6.14/
[root@bigboy kernel-2.6.14]# ls
linux-2.6.14  vanilla
[root@bigboy kernel-2.6.14]# mv linux-2.6.14 /usr/src/
[root@bigboy kernel-2.6.14]# cd /usr/src
[root@bigboy src]# ln -s ./linux-2.6.14 linux
[root@bigboy src]# ls
kernels  linux  linux-2.6.14  redhat
[root@bigboy src]#
6. The configuration files for specific kernels shipped in Fedora Core will be located in the configs/ directory. In this case the uname -a command is used to determine the systems CPU type (686) and the kernel type (SMP, Symmetrical Multi Processor), and the relevant configuration file is then copied to become the new /usr/src/linux/.config file to be used during the kernel compilation.
[root@bigboy src]# cd /usr/src/linux
[root@bigboy linux]# uname -a
Linux bigboy.my-web-site.org 2.6.14-1.1644_FC4smp #1 SMP
Sun Nov 27 03:39:31 EST 2005 i686 i686 i386 GNU/Linux
[root@bigboy linux]# cp configs/kernel-2.6.14-i686-smp.config .config
cp: overwrite `.config'? y
[root@bigboy linux]#
7. You can also automatically copy the correct file from the /usr/src/linux/configs/ directory to /usr/src/linux/.config using the make oldconfig command.
[root@bigboy linux]# cd /usr/src/linux
[root@bigboy linux]# make oldconfig
You should now be ready to compile a customized kernel at your leisure, but first I'll discuss Kernel modules.

Kernel Modules

Over the years the Linux kernel has evolved, in the past device drivers were included as part of this core program, whereas now they are loaded on demand as modules.

Reasons For Kernel Modules

There are a number of advantages to this new architecture:
  • Updates to a driver, such as a USB controller module, don't require a complete recompilation of the kernel; just the module itself needs recompiling. This reduces the likelihood of errors and ensures that the good, working base kernel remains unchanged.
  • An error in a device driver is less likely to cause a fault that prevents your system from booting. A faulty device driver can be prevented from loading at boot time by commenting out its entry in the /etc/modprobe.conf file, or by using the rmmod command after boot time. In the past, the kernel would have to be recompiled.
  • Updates to a driver don't require a reboot either, just the unloading of the old and reloading of the new module.
  • You can add new devices to your system without requiring a new kernel, only the new module driver is needed. This adds a great deal of flexibility without a lot of systems administrator overhead.
There are some drivers that will always need to be compiled into the kernel to make sure your system boots correctly. For example, routines for basic system functions used in reading and writing files, are an indispensable integrated part of any kernel.
Loadable kernel modules now include device drivers to manage various types of filesystems, network cards, and terminal devices to name a few. As they work so closely with the kernel, the modules need to be compiled specifically for the kernel they are intended to support. The kernel always looks for modules for its version number in the /lib/modules/<kernel version> directory and permanently loads them into RAM memory for faster access. Some critical modules are loaded automatically, others need to be specified in the /etc/modprobe.conf file.
The kernel recompilation process provides you with the option of compiling only the loadable modules. I won't specifically cover this, but simultaneous recompilation of all modules will be covered as part of the overall recompilation of your kernel.

How Kernel Modules Load When Booting

One question that must come to mind is "How does the kernel boot if the disk controller modules reside on a filesystem that isn't mounted yet?"
As stated in Chapter 7, "The Linux Boot Process", the GRUB boot loader resides on its own dedicated partition and uses the /boot/grub/grub.conf file to determine the valid kernels and their locations. The grub.conf file not only defines the available kernels, but also the location of the root partition and an associated ramdisk image that is automatically loaded into memory and that contains just enough modules to get the root filesystem mounted.
Note: In Fedora Linux, the /boot/grub/grub.conf file can also be referenced via the symbolic link file named /etc/grub.conf.

Modules And The grub.conf File

In this example of the /boot/grub/grub.conf file, the kernel in the /boot directory is named vmlinuz-2.6.8-1.521, its RAM disk image file is named initrd-2.6.8-1.521.img, and the root partition is (hd0,0).
#
# File: /boot/grub/grub.conf
#
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Fedora Core (2.6.8-1.521)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-1.521 ro root=LABEL=/
        initrd /initrd-2.6.8-1.521.img
 
The .img file is created as part of the kernel compilation process, but can also be created on demand with the mkinitrd command.
The (hd0,0).disk definition may seem strange, but there is a file that maps the GRUB device nomenclature to that expected by Linux in the /boot/grub/device.map file.
#
# File: /boot/grub/device.map
#
(fd0)     /dev/fd0
(hd0)     /dev/hda
During the next phase of the boot process, the loaded kernel executes the init program located on the RAM disk, which mounts the root filesystem and loads the remaining modules defined in the /etc/modprobe.conf file before continuing with the rest of the startup process.

Loading Kernel Modules On Demand

It is possible to load add-on modules located under the /lib/modules/<kernel version> directory with the modprobe command. For example, the iptables firewall application installs kernel modules that it uses to execute NAT and pass FTP traffic. In this example: these modules are loaded with the modprobe command with the aid of the /etc/rc.local script.
#
# File: /etc/rc.local
#
# Load iptables FTP module when required
modprobe ip_conntrack_ftp

# Load iptables NAT module when required
modprobe iptable_nat
Kernel module drivers that are referenced by the operating system by their device aliases are placed in the /etc/modprobe.conf file and are loaded automatically at boot time. In the example, you can see that devices eth1 and eth0 use the natsemi and orinoco_pci drivers respectively.
#
# /etc/modprobe.conf
#
alias eth1 natsemi
alias eth0 orinoco_pci
Linux has a number of commands to help you with modules. The lsmod command lists all the ones loaded. In the example, you can see that iptables, NFS, and the Orinoco drivers are all kernel modules. You can use the modprobe command to load and unload modules or use the insmod and rmmod commands. See the man pages for details.
[root@bigboy tmp]# lsmod
Module                  Size  Used by
...
...
iptable_filter          2048  0
ip_tables              13440  1 iptable_filter
...
...
exportfs                4224  1 nfsd
nfs                   142912  0
lockd                  47944  3 nfsd,nfs
autofs4                10624  1
sunrpc                101064  20 nfsd,nfs,lockd
...
...
natsemi                18016  0
orinoco_pci             4876  0
orinoco                31500  1 orinoco_pci
hermes                  6528  2 orinoco_pci,orinoco
...
...
[root@bigboy tmp]#

Finally, when in doubt about a device driver, try using the lspci command to take a look at the devices that use your PCI expansion bus. Here you can see that the natsemi module listed in the lsmod command has a high probability of belonging to the 01:08.0 Ethernet controller: device made by National Semiconductor.
[root@bigboy tmp]# lspci
...
...
01:07.0 Network controller: Intersil Corporation Prism 2.5 Wavelan chipset (rev 01)
01:08.0 Ethernet controller: National Semiconductor Corporation DP83815 (MacPhyter) Ethernet Controller
01:0c.0 Ethernet controller: 3Com Corporation 3c905C-TX/TX-M [Tornado] (rev 78)
[root@bigboy tmp]#

Creating A Custom Kernel

The installation of the kernel sources creates a file called README in the /usr/src/linux directory that briefly outlines the steps needed to create a new kernel. Take a look at a more detailed explanation of the required steps.

Make Sure Your Source Files Are In Order

Cleaning up the various source files is the first step. This isn't so important for a first time rebuild, but it is vital for subsequent attempts. You use the make mrproper command to do this; it must be executed in the Linux kernel version's subdirectory located under /usr/src. In this case, the subdirectory's name is /usr/src/linux-2.6.5-1.358.
[root@bigboy tmp]# cd /usr/src/linux
[root@bigboy linux]# make mrproper
...
...
...
[root@bigboy linux]#

The ".config" File

You next need to run scripts to create a kernel configuration file called /usr/src/linux/.config. This file lists all the kernel options you wish to use.

Backup Your Configuration

The .config file won't exist if you've never created a custom kernel on your system before, but fortunately, RedHat stores a number of default .config files in the /usr/src/linux/configs directory. You can automatically copy the .config file that matches your installed kernel by running the make oldconfig command in the /usr/src/linux directory.
[root@bigboy tmp]# cd /usr/src/linux
[root@bigboy linux]# ls .config
ls: .config: No such file or directory
[root@bigboy linux]# make oldconfig
...
...
...
[root@bigboy linux]#
If you've created a custom kernel before, the .config file that the previous custom kernel build used will already exist. Copy it to a safe location before proceeding.

Customizing The ".config" File

Table 33-2 lists three commands that you can run in the /usr/src/linux directory to update the .config file.

Table 33-2 Scripts For Modifying The .config File

Command Description
make config Text based utility that prompts you line by line. This method can become laborious.
make menuconfig Text menu based utility.
make gconfig X-Windows GUI based utility.

Table 33-3 Kernel Option Choices

Kernel Option Choice Description
M The kernel will load the drivers for this option on an as needed basis. Only the code required to load the driver on demand will be included in the kernel.
Y Include all the code for the drivers needed for this option into the kernel itself. This will generally make the kernel larger and slower but will make it more self sufficient. The "Y" option is frequently used in cases in which a stripped down kernel is one of the only programs Linux will run, such as purpose built home firewall appliances you can buy in a store. There is a limit to the overall size of a kernel. It will fail to compile if you select parameters that will make it too big.
N Don't make the kernel support this option at all.

Table 33-4 Kernel Configuration Options

Option Description
Code maturity level options Determines whether Linux prompts you for certain types of development code or drivers.
Loadable module support Support for loadable modules versus a monolithic kernel. Most of the remaining kernel options use loadable modules by default. It is best to leave this alone in most cases.
Processor type and features SMP, Large memory, BIOS and CPU type settings.
General setup Support for power management, networking, and systems buses such as PCI, PCMCIA, EISA, ISA
Memory technology devices Linux subsystem for memory devices, especially Flash devices
Parallel port support Self explanatory
Plug and Play configuration Support of the automatic new hardware detection method called plug and play
Block devices Support for a number of parallel-port-based and ATAPI type devices. Support for your loopback interface and RAM disks can be found here too.
Multidevice support (RAID, LVM) Support for RAID, 0, 1, and 5, as well as LVM.
Cryptography support (CryptoAPI) Support for various types of encryption
Networking options TCP/IP, DECnet, Appletalk, IPX, ATM/LANE
Telephony support Support for voice to data I/O cards
ATA/IDE/MFM/RLL support Support for a variety of disk controller chipsets
SCSI support Support for a variety of disk controller chipsets. Also sets limits on the maximum number of supported SCSI disks and CDROMs.
Fusion MPT support High speed SCSI chipset support.
I2O device support Support for specialized Intelligent I/O cards
Network device support Support for Ethernet, Fibre Channel, FDDI, SLIP, PPP, ARCnet, Token Ring, ATM, PCMCIA networking, and specialized WAN cards.
Amateur Radio support Support for packet radio
IrDA subsystem support Infrared wireless network support
ISDN subsystem Support for ISDN
Old CD-ROM drivers (not SCSI, not IDE) Support for non-SCSI, non-IDE, non ATAPI CDROMs
Input core support Keyboard, mouse, and joystick support in addition to the default VGA resolution.
Character devices Support for virtual terminals and various serial cards for modems, joysticks and basic parallel port printing.
Multimedia devices Streaming video and radio I/O card support
Crypto Hardware support Web-based SSL hardware accelerator card support
Console drivers Support for various console video cards
Filesystems Support for all the various filesystems and strangely, the native languages supported by Linux.
Sound Support for a variety of sound cards
USB support Support for a variety of USB devices
Additional device driver support Miscellaneous driver support
Bluetooth support Support for a variety of Bluetooth devices
Kernel hacking Support for detailed error messages for persons writing device drivers

Configure Dependencies

As I mentioned before, the .config file you just created lists the options you'll need in your kernel. In version 2.4 of the kernel and older, the make dep command was needed at this step to prepare the needed source files for compiling. This step has been eliminated as of version 2.6 of the kernel.

Edit The Makefile To Give The Kernel A Unique Name

Edit the file Makefile and change the line "EXTRAVERSION =" to create a unique suffix at the end of the default name of the kernel.
For example, if your current kernel version is 2.6.5-1.358, and your EXTRAVERSION is set to -6-new, your new additional kernel will have the name vmlinuz-2.6.5-6-new.
Remember to change this for each new version of the kernel you create.

Compile A New Kernel

You can now use the make command to create a compressed version of your new kernel and its companion .img RAM disk file. This could take several hours on a 386 or 486 system. It will take about 20 minutes on a 400MHz Celeron.
[root@bigboy linux-2.6.5-1.358]# make 
...
...
...
[root@bigboy linux-2.6.5-1.358]#
Note: In older versions of Fedora the command to do this would have been make bzImage.

Build The Kernel's Modules

You can now use the make modules_install command to copy all the modules created in the previous step to the conventional module locations.
[root@bigboy linux]# make modules_install
...
...
...
[root@bigboy linux]#
Note: In versions of Fedora before Core 3, this was a two step process. The make modules command would compile the modules, but locate them within the Linux kernel source directory tree under the directory /usr/src/. The make modules_install command would then relocates them to where they should finally reside under the /lib/modules/<kernel version> directory.

Copy The New Kernel To The /boot Partition

The kernel and the .img you just created needs to be copied to the /boot partition where all your systems active kernel files normally reside. This is done with the make install command.
This partition has a default size of 100MB, which is enough to hold a number of kernels. You may have to delete some older kernels to create enough space.
[root@bigboy linux]# make install
...
...
...
[root@bigboy linux]#

Here you can see that the new kernel vmlinuz-2.6.5-1.358-new is installed in the /boot directory.
[root@bigboy linux]# ls -l /boot/vmlinuz*
lrwxrwxrwx 1 root root       22 Nov 28 01:20 /boot/vmlinuz -> vmlinuz-2.6.5-1.358-new
-rw-r--r-- 1 root root  1122363 Feb 27  2003 /boot/vmlinuz-2.6.5-1.358
-rw-r--r-- 1 root root  1122291 Nov 28 01:20 /boot/vmlinuz-2.6.5-1.358-new
[root@bigboy linux]#

Updating GRUB

You should now update your /etc/grub.conf file to include an option to boot the new kernel. The make install command does this for you automatically.
In this example, default is set to 1, which means the system boots the second kernel entry, which happens to be that of the original kernel 2.6.5-1.358. You can set this value to 0, which makes it boot your newly compiled kernel (the first entry).
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.5-1.358-new)
        root (hd0,0)
        kernel /vmlinuz-2.6.5-1.358-new ro root=LABEL=/
        initrd /initrd-2.6.5-1.358-new.img
title Red Hat Linux (2.6.5-1.358)
        root (hd0,0)
        kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/
        initrd /initrd-2.6.5-1.358.img

Kernel Crash Recovery

Sometimes the new default kernel will fail to boot or work correctly with the new kernel. A simple way of recovering from this is to reboot your system, selecting the old version of the kernel from the Fedora splash screen. Once the system has booted with this stable version, edit the grub.conf file and set the default parameter to point to the older version instead. If this fails, you may want to boot from a CD with the original kernel. You can then try to either reinstall a good kernel RPM or rebuild the failed one over again after fixing the configuration problem that caused the trouble in the first place.

How To Create A Boot CD

The kernel in Fedora Core 2 and higher is too big to fit on a floppy disk, so you'll have to create a boot CD instead. Here are the steps.
1. Each installed kernel has a dedicated subdirectory for its modules in the /lib/modules directory. Get a listing of this directory. Here there are two installed kernels; versions 2.6.5-1.358custom and 2.6.8-1.521.
[root@bigboy tmp]# ls /lib/modules/
2.6.5-1.358custom  2.6.8-1.521
[root@bigboy tmp]#
2. Select the desired kernel and use the mkbootdisk command to create a CD ISO image named /tmp/boot.iso of one of the kernels, in this case 2.6.8-1.521:
[root@bigboy tmp]# mkbootdisk --iso --device /tmp/boot.iso \
                     2.6.8-1.521
3. Burn a CD using the image. This creates a boot CD with the specified kernel, named vmlinuz, and a scaled-down version of the grub.conf configuration file named isolinux.cfg, both located in the isolinux subdirectory of the CD. This example mounts the newly created CD-ROM and takes a look at the isolinux.cfg file to confirm that everything is okay.
[root@bigboy tmp]# mount /mnt/cdrom
[root@bigboy tmp]# ls /mnt/cdrom/isolinux/
boot.cat  boot.msg  initrd.img  isolinux.bin  isolinux.cfg   TRANS.TBL  vmlinuz
[root@bigboy tmp]# cat /mnt/cdrom/isolinux/isolinux.cfg
default linux
prompt 1
display boot.msg
timeout 100
label linux
        kernel vmlinuz
        append initrd=initrd.img ro  root=/dev/hda2
[root@bigboy tmp]#
When you reboot your system with the CD, the boot process automatically attempts to access your files in the /root partition and boot normally. The only difference being that the kernel used is on the CD.

Updating The Kernel Using RPMs

It is also possible to install a new standardized kernel from an RPM file. As you can see, it is much simpler than creating a customized one.
To create an additional kernel using RPMs, use the command
[root@bigboy tmp]# rpm -ivh kernel-file.rpm
To replace an existing kernel using RPMs, you need only one line
[root@bigboy tmp]# rpm -Uvh kernel-file.rpm

Conclusion

Building a customized Linux kernel is probably something that most systems administrators won't do themselves. The risk of having a kernel that may fail in some unpredictable way is higher when you modify it, and, therefore, many system administrators hire experts to do the work for them. After reading this chapter, at least you will have an idea of what is going on when the expert arrives, which can help considerably when things don't go according to plan.

Monitoring Server Performance

Introduction

You can monitor your system's Web performance quite easily with graphical Linux tools. You'll learn how to use several in this chapter, including MRTG, which is based on SNMP and monitors raw network traffic, and Webalizer, which tracks Web site hits.

Debian / Ubuntu Differences

This chapter focuses on Fedora / CentOS / RedHat for simplicity of explanation. Whenever there is a difference in the required commands for Debian / Ubuntu variations of Linux it will be noted.
The universal difference is that the commands shown are done by the Fedora / CentOS / RedHat root user. With Debian / Ubuntu you will either have to become root using the "sudo su –" command or you can temporarily increase your privilege level to root using the "sudo <command>" command.
Here is an example of how to permanently become root:
user@ubuntu:~$ sudo su -
[sudo] password for peter: 
root@ubuntu:~#
Here is an example of how to temporarily become root to run a specific command. The first attempt to get a directory listing fails due to insufficient privileges. The second attempt succeeds when the sudo keyword is inserted before the command.
user@ubuntu:~$  ls -l /var/lib/mysql/mysql
ls: cannot access /var/lib/mysql/mysql: Permission denied
user@ubuntu:~$ sudo ls -l /var/lib/mysql/mysql
[sudo] password for peter: 
total 964
-rw-rw---- 1 mysql mysql   8820 2010-12-19 23:09 columns_priv.frm
-rw-rw---- 1 mysql mysql      0 2010-12-19 23:09 columns_priv.MYD
-rw-rw---- 1 mysql mysql   4096 2010-12-19 23:09 columns_priv.MYI
-rw-rw---- 1 mysql mysql   9582 2010-12-19 23:09 db.frm
...
...
...
user@ubuntu:~$
 
Now that you have got this straight, let’s continue with the discussion.

SNMP

Most servers, routers and firewalls keep their operational statistics in object identifiers (OIDs) that you can remotely retrieve via the Simple Network Management Protocol (SNMP). For ease of use, equipment vendors provide Management Information Base (MIB) files for their devices that define the functions of the OIDs they contain. That's a lot of new terms to digest in two sentences, so take a moment to look more closely.

OIDs And MIBs

OIDs are arranged in a structure of management information (SMI) tree defined by the SNMP standard. The tree starts from a root node, which then descends through branches and leaves that each add their own reference value to the path separated by a period.. Figure 22-1 shows an OID structure in which the path to the enterprises OID branch passes through the org, dod, internet, and private branches first. The OID path for enterprises is, therefore, 1.3.6.1.4.1.

Figure 22-1 SNMP OID Structure

Snmp.gif
Management Information Bases (MIBs) are text definitions of each of the OID branches. Table 22-1 shows how some commonly used OIDs map to their MIB definitions. For example, the SMI org MIB defines all the topmost OIDs found at the next layer, which is named dod; the internet MIB under dod defines the function of the topmost OIDs in the directory, mgmt, experimental, and private branches. This MIB information is very useful for SNMP management programs, enabling you to click on an OID and see its value, type, and description.

Table 22-1 OIDs And Their Equivalent MIBs

OID MIB
1.3 org
1.3.6 dod
1.3.6.1 internet
1.3.6.1.1 directory
1.3.6.1.2 mgmt
1.3.6.1.3 experimental
1.3.6.1.4 private
1.3.6.1.4.1 enterprises
You can refer to an OID by substituting the values in a branch with one of these more readable MIB aliases. For example, you can reference the OID 1.3.6.1.4.1.9.9.109.1.1.1.1.5 as enterprises.9.9.109.1.1.1.1.5.1 by substituting the branch name (enterprises) for its OID numbers (1.3.6.1.4.1).
Remember, only the OID value at the very tip of a branch, the leaf, actually has a readable value. Think of OIDs like the directory structure on a hard disk. Each branch is equivalent to a subdirectory, and the very last value at the tip (the leaf) correlates to a file containing data.
The Linux snmpget command outputs the value of a single leaf, and the snmpwalk command provides the values of all leaves under a branch. I'll discuss these commands later; for now, all you need to know is that the command output frequently doesn't list the entire OID, just the MIB file in which it was found and the alias within the MIB. For example
SNMPv2-MIB::sysUpTime.0
Here the OID value was found in the SNMPv2-MIB file and occupies position zero in the sysUpTime alias.
Equipment manufacturers are usually assigned their own dedicated OID branch under the enterprises MIB, and they must also provide information in universally accepted OIDs for ease of manageability. For example, NIC interface data throughput values must always be placed in a predefined location in the general tree, but a memory use value on a customized processor card may be defined in a MIB under the manufacturer's own OID branch.

SNMP Community Strings

As a security measure, you need to know the SNMP password, or community string, to query OIDs. There are a number of types of community strings, the most commonly used ones are the Read Only or "get" community string that only provides access for viewing statistics and system parameters. In many cases the Read Only community string or password is set to the word "public;" you should change it from this easy-to-guess value whenever possible. The Read/Write or "set" community string is for not only viewing statistics and system parameters but also for updating the parameters.

SNMP Versions

There are currently three versions of SNMP.
  1. SNMP Version 1: The first version of SNMP to be implemented, version 1 was designed to be a protocol to provide device statistics and error reporting without consuming a lot of system resources. Security was limited to community strings and access controls based on the IP address of the querying server. Data communication wasn't encrypted.
  2. SNMP Version 2: The second version of SNMP, often referred to as v2c, expanded the number of supported error codes, increased the size of counters used to track data, and had the ability to do bulk queries that more efficiently loaded response packets with data. SNMP v2c is backward compatible with version 1.
  3. SNMP Version 3: This version provides greater security and remote configuration capabilities than its predecessors. Access isn't limited to a single community string for read-only and read/write access, as usernames and passwords have been introduced. Views of OIDs in a MIB can also be limited on a per-user basis. Support for encrypted SNMP data transfer and transfer error detection is also provided.
Remember their differences, because you will need to specify the version number when doing SNMP queries.

Doing SNMP Queries

Configuring SNMP on a server isn't hard, but it does require a number of detailed steps.

Installing SNMP Utilities on a Linux Server

If you intend to use your Linux box to query your network devices, other servers or even itself using SNMP commands, MRTG or any other tool, you need to have the SNMP client programs installed. The devices you query need to have a constantly running SNMP server application running to provide the clients with the data they are requesting.
You’ll need to install both the client and server software on your Linux server to maximize your understanding of all the examples provided.
Note: With Fedora / Redhat the packages to install would be net-snmp-utils (client) and net-snmp (server) and with Debian / Ubuntu the packages are snmp (client) and snmpd (server).
Most RedHat and Fedora Linux software product packages are available in the RPM format, whereas Debian and Ubuntu Linux use DEB format installation files. When searching for these packages, remember that the filename usually starts with the software package name and is followed by a version number, as in net-snmp-utils-5.1.1-2.i386.rpm. (If you need an installation refresher, see Chapter 6, "Installing Linux Software").

Starting the Linux SNMPd Server

The methodologies vary depending on the variant of Linux you are using as you’ll see next.
Fedora / CentOS / RedHat
With these flavors of Linux you can use the chkconfig command to get snmpd configured to start at boot:
[root@bigboy tmp]# chkconfig snmpd on
To start, stop, and restart snmpd after booting use the service command:
[root@bigboy tmp]# service snmpd start
[root@bigboy tmp]# service snmpd stop
[root@bigboy tmp]# service snmpd restart
To determine whether snmpd is running you can issue either of these two commands. The first will give a status message. The second will return the process ID numbers of the snmpd daemons.
[root@bigboy tmp]# service snmpd status
[root@bigboy tmp]# pgrep squid
Note: Remember to run the chkconfig command at least once to ensure snmpd starts automatically on your next reboot.
Ubuntu / Debian
With these flavors of Linux the commands are different. Try installing the sysv-rc-conf and sysvinit-utils DEB packages as they provide commands that simplify the process. (For help on downloading and installing the packages, see Chapter 6, Installing Linux Software). You can use the sysv-rc-conf command to get snmpd configured to start at boot:
user@ubuntu:~$ sudo sysv-rc-conf snmpd on
To start, stop, and restart snmpd after booting the service command is the same:
user@ubuntu:~$ sudo service snmpd start
user@ubuntu:~$ sudo service snmpd stop
user@ubuntu:~$ sudo service snmpd restart
To determine whether snmpd is running you can issue either of these two commands. The first will give a status message. The second will return the process ID numbers of the snmpd daemons.
user@ubuntu:~$ sudo service snmpd status
user@ubuntu:~$ pgrep snmpd
Note: Remember to run the sysv-rc-conf command at least once to ensure snmpd starts automatically on your next reboot.

Allowing SNMPd to Listen on Multiple Interfaces

The /etc/sysconfig/snmpd file (Redhat / CentOS /Fedora) and the /etc/default/snmpd file (Debian / Ubuntu) define some universal operating parameters for your SNMP server to work.
One of its functions is to define which network interfaces on which SNMP will listen for queries. In many distributions the default behavior is to only listen on localhost (127.0.0.1). The SNMPDOPTS line in the snmpd file defines the IP addresses on which to listen. In this example, only localhost is defined.
# 
# File: snmpd
#
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'
This can be verified using the netstat command which shows snmpd listening only on localhost.
root@ubuntu:/tmp# netstat -au | grep snmp
udp        0      0 localhost:snmp          *:*
root@ubuntu:/tmp#
You can activate all interfaces by removing the reference to 127.0.0.1, like this:
# 
# File: snmpd
#
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'
This can be verified using the netstat command which shows snmpd listening on all addresses (*).
root@ubuntu:/tmp# netstat -au | grep snmp
udp        0      0 *:snmp                  *:*
root@ubuntu:/tmp# 
Note: Remember to restart snmpd for this to take effect.

SNMP Utilities Command Syntax

The SNMP utility tools package installs a number of new commands on your system for doing SNMP queries, most notably snmpget for individual OIDs and snmpwalk for obtaining the contents of an entire MIB. Both commands require you to specify the community string with a -c operator. They also require you to specify the version of the SNMP query to be used with a -v 1, -v 2c, or -v 3 operator for versions 1, 2, and 3, respectively. The first argument is the name or IP address of the target device and all other arguments list the MIBs to be queried.
This example gets all the values in the interface MIB of the local server using SNMP version 1 and the community string of craz33guy.
[root@bigboy tmp]# snmpwalk -v 1 -c craz33guy localhost interface
...
...
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: eth1
...
...
IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING: 0:9:5b:2f:9e:d5
IF-MIB::ifPhysAddress.3 = STRING: 0:b0:d0:46:32:71
...
...
[root@bigboy tmp]#
Upon inspecting the output of the snmpwalk command, you can see that the second interface seems to have the name eth0 and the MAC address 0:9:5b:2f:9e:d5. You can now retrieve the individual MAC address using the snmpget command.
[root@bigboy tmp]# snmpget -v 1 -c const1payted localhost ifPhysAddress.2
IF-MIB::ifPhysAddress.2 = STRING: 0:9:5b:2f:9e:d5
[root@bigboy tmp]#
You can confirm this information using the ifconfig command for interface eth0; the very first line shows a matching MAC address.
[root@bigboy tmp]# ifconfig -a eth0
eth0      Link encap:Ethernet  HWaddr 00:09:5B:2F:9E:D5  
          inet addr:216.10.119.244  Bcast:216.10.119.255   Mask:255.255.255.240
...
...
[root@bigboy tmp]#
You'll now see how you can configure SNMP on your Linux server to achieve these results.

Configuring Simple SNMP on a Linux Server

By default Fedora, installs the net-snmp package as its SNMP server product. This package uses a configuration file named /etc/snmp/snmpd.conf in which the community strings and other parameters may be set. The version of the configuration file that comes with net-snmp is quite complicated. I suggest archiving it and using a much simpler version with only a single line containing the keyword rocommunity followed by the community string. Here is an example.
1) Save the old configuration file and make sure the new configuration file has the correct permissions
[root@bigboy tmp]# cd /etc/snmp/ 
[root@bigboy snmp]# mv snmpd.conf snmpd.conf.old
[root@bigboy snmp]# touch snmpd.conf
[root@bigboy snmp]# chmod 600 snmpd.conf
[root@bigboy snmp]# vi snmpd.conf
2) Enter the following line in the new configuration file to set the Read Only community string to craz33guy.
rocommunity craz33guy
3) Configure Linux to start SNMP services on each reboot with the chkconfig or sysv-rc-conf command depending on your linux variation:
For Fedora / RedHat / CentOS it would be:
[root@bigboy root]# chkconfig snmpd on
For Ubuntu / Debian it would be:
user@ubuntu:~$ sudo sysv-rc-conf snmpd on 
4) Start SNMP to load the current configuration file.
[root@bigboy root]# service snmpd start
Starting snmpd: [ OK ]
[root@bigboy root]#
5) Test whether SNMP can read the system and interface MIBs using the snmpwalk command.
[root@bigboy snmp]# snmpwalk -v 1 -c craz33guy localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux bigboy 2.4.18-14 #1 Wed Sep 4 11:57:57 EDT 2002 i586
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
SNMPv2-MIB::sysUpTime.0 = Timeticks: (425) 0:00:04.25
SNMPv2-MIB::sysContact.0 = STRING: root@localhost
SNMPv2-MIB::sysName.0 = STRING: bigboy
...
...
...
[root@bigboy snmp]# snmpwalk -v 1 -c craz33guy localhost interface
IF-MIB::ifNumber.0 = INTEGER: 3
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: wlan0
IF-MIB::ifDescr.3 = STRING: eth0 
...
...
...
[root@bigboy snmp]# 
Now that you know SNMP is working correctly on your Linux server, you can configure SNMP statistics gathering software, such as MRTG, to create online graphs of your traffic flows.

SNMP On Other Devices

In the example, you were polling localhost. You can poll any SNMP-aware network device that has SNMP enabled. All you need is the IP address and SNMP Read Only string and you'll be able to get similar results. Here is an example of a query of a device with an IP address of 192.168.1.1.
[root@bigboy snmp]# snmpwalk -v 1 -c chir1qui 192.168.1.1 interface
Note: When issuing snmpwalk and snmpget commands, remember to use the proper version switch (-v 1, -v 2c, or -v 3) for the version of SNMP you're using.

Basic SNMP Security

The security precautions that need to be taken with SNMP vary depending on the version you are using. This section outlines the basic steps for protecting your MIB data.

SNMP Versions 1 and 2

The most commonly supported versions of SNMP don't encrypt your community string password so you shouldn't do queries over insecure networks, such as the Internet. You should also make sure that you use all reasonable security measures to allow queries only from trusted IP addresses either via a firewall or the SNMP security features available in the snmp.conf file. You can also configure your server to use the TCP wrappers feature outlined in Appendix I, "Miscellaneous Linux Topics," to limit access to specific servers without the need of a firewall.
In case you need it, the snmpd.conf file can support limiting MIB access to trusted hosts and networks.
The snmpd.conf file has two security sections; a section with very restrictive access sits at the top of the file and is immediately followed by a less restrictive section. The example that follows is a modification of the less restrictive section. You will have to comment out the more restrictive statements at the top of the file for it to work correctly.


##       sec.name     source           community
##       ========     ======           =========
com2sec  local       localhost        craz33guy
com2sec  network_1   172.16.1.0/24    craz33guy
com2sec  network_2   192.168.2.0/24   craz33guy

##       Access.group.name   sec.model        sec.name
##       =================  =========         ========
group    MyROGroup_1        v1                local
group    MyROGroup_1        v1                network_1
group    MyROGroup_2        v2c               network_2

##   MIB.view.name     incl/excl  MIB.subtree  mask
##   ==============   =========  ===========  ====
view all-mibs         included   .1           80

##      MIB                
##      group.name   context sec.model sec.level prefix read     write  notif
##      ==========   ======= ========= ========= ====== ====     =====  =====
access  MyROGroup_1  ""       v1       noauth    exact  all-mibs none   none
access  MyROGroup_2  ""       v2c      noauth    exact  all-mibs none   none
In our example:
  • Only three networks (localhost, 172.16.1.0/24, and 192.168.1.0/24) are allowed to access the server with the craz33guy community string.
  • Each network is matched to a either a group called MyROGroup_1 using SNMP version 1, or group called MyROGroup_2 using SNMP version 2.
  • All the MIBs on the server are defined by the view named all-mibs.
  • An access statement ensures that only the defined networks have read only access to all the MIBs. MyROGroup_1 only has version 1 access with MyROGroup_2 only having version 2 access.
  • Modification of the MIBs via SNMP is denied because the word "none" is in the write section of the access statement.
These precautions are probably unnecessary in a home environment where access is generally limited to devices on the home network by a NAT firewall.
After editing the snmpd.conf file and restarting the snmpd daemon on server bigboy, the remote client smallfry can poll the interface MIB using v2, but bigboy cannot do so on localhost. However bigboy can poll itself on localhost using v1. This is expected.
root@bigboy:/tmp#  snmpwalk -v 2c -c craz33guy localhost system
Timeout: No Response from localhost
root@bigboy:/tmp#  snmpwalk -v 1 -c craz33guy localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux bigboy 2.6.32-26-generic-pae #48-Ubuntu SMP Wed Nov 24 10:31:20 UTC 2010 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (38537) 0:06:25.37
SNMPv2-MIB::sysContact.0 = STRING: root
SNMPv2-MIB::sysName.0 = STRING: bigboy
...
...
...
root@bigboy:/tmp# 

[root@smallfry ~]# snmpwalk -v 2c -c craz33guy 192.168.2.111 system
SNMPv2-MIB::sysDescr.0 = STRING: Linux bigboy 2.6.32-26-generic-pae #48-Ubuntu SMP Wed Nov 24 10:31:20 UTC 2010 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1022) 0:00:10.22
SNMPv2-MIB::sysContact.0 = STRING: root
SNMPv2-MIB::sysName.0 = STRING: bigboy
SNMPv2-MIB::sysLocation.0 = STRING: Unknown
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
...
...
...
[root@smallfry ~]#

SNMP Version 3

SNMPv3 is a much more secure alternative to earlier versions as it encrypts all its data and uses a username / password combination for client authentication. The username should be located in the /etc/snmp/snmpd.conf file with a corresponding automatically generated password located in the /var/net-snmp/snmpd.conf file. Here is how it's done.
1. Install the net-snmp-devel (RedHat / Fedora / CentOS) or libsnmp-base (Ubuntu / Debian) package as it contains the utility that will allow you to generate the password. If you need an installation refresher, see Chapter 6, "Installing Linux Software")
2. Stop the snmpd process.
[root@bigboy tmp]# service snmpd stop
Stopping snmpd: [  OK  ]
[root@bigboy tmp]#
3. Automatically create username and password entries using the net-snmp-config command. In this example the authentication password of "rootsrockreggae" for the read only (-ro) username "username4snmpv3" is encrypted using the MD5 algorithm. The data received will not be encrypted.
[root@bigboy tmp]# net-snmp-config --create-snmpv3-user -ro -a MD5 -A rootsrockreggae username4snmpv3

adding the following line to /var/net-snmp/snmpd.conf:
   createUser username4snmpv3 MD5 "rootsrockreggae" DES
adding the following line to /etc/snmp/snmpd.conf:
   rouser username4snmpv3
[root@bigboy tmp]# service snmpd start
Starting snmpd: [  OK  ]
[root@bigboy tmp]#
Note: In Fedora / RedHat / Centos, the SNMPv3 username / password pair will be stored in the file /var/net-snmp/snmpd.conf. The type of user, in this case read-only, will be stored in the file /etc/snmp/snmpd.conf.
Note: In Debian / Ubuntu, the SNMPv3 username / password pair will be stored in the file /var/lib/snmp/snmpd.conf. The type of user, in this case read-only, will be stored in the file /usr/share/snmp/snmpd.conf.
4. To encrypt the data received we use the net-snmp-config command again to create a username just for this purpose. A new read only username "securev3user" and authentication password "mandeville" are used, but this time the data will be encrypted using the DES algorithm with the privacy password of "savlamar".
[root@bigboy tmp]# net-snmp-config --create-snmpv3-user -ro -a MD5 -A mandeville -x DES -X savlamar securev3user

adding the following line to /var/net-snmp/snmpd.conf:
   createUser securev3user MD5 "mandeville" DES savlamar
adding the following line to /etc/snmp/snmpd.conf:
   rouser securev3user
[root@bigboy tmp]#

5. Start the snmpd process.
[root@bigboy tmp]# service snmpd start
Starting snmpd: [  OK  ]
[root@bigboy tmp]#
6. First we'll do a query from remote host smallfry. We specify the authentication password and authentication encryption method, and we also use the -l flag to indicate that authentication will be used, but that data privacy will be disabled (the authNoPriv option).
[root@smallfry ~]# snmpget -v 3 -u username4snmpv3 -l authNoPriv -a MD5 -A rootsrockreggae  192.168.1.100 SNMPv2-MIB::sysORDescr.8

SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
[root@smallfry ~]#
The query returns an easy to read string, "The management information definitions for the SNMP User-based Security Model". This unencrypted string can also be seen in the tshark packet capture of the server's interface.
[root@bigboy tmp]# tshark -n -i eth1 -x port 161
Capturing on eth1
...
...
...

  0.005889 192.168.1.100 -> 192.168.1.50 SNMP get-response

0000  00 c0 4f 46 0c 2e 00 b0 d0 46 32 71 08 00 45 00   ..OF.....F2q..E.
0010  00 f0 00 00 40 00 40 11 b3 b2 c0 a8 02 c8 c0 a8   ....@.@.........
0020  02 32 00 a1 80 0a 00 dc 87 38 30 81 d1 02 01 03   .2.......80.....
0030  30 11 02 04 45 a2 23 54 02 03 00 ff e3 04 01 01   0...E.#T........
0040  02 01 03 04 38 30 36 04 0d 80 00 1f 88 80 71 11   ....806.......q.
0050  68 72 0e b1 e7 45 02 01 12 02 01 39 04 0f 75 73   hr...E.....9..us
0060  65 72 6e 61 6d 65 34 73 6e 6d 70 76 33 04 0c 46   ername4snmpv3..F
0070  6c 74 26 51 4d aa 65 61 59 06 1a 04 00 30 7f 04   lt&QM.eaY....0..
0080  0d 80 00 1f 88 80 71 11 68 72 0e b1 e7 45 04 00   ......q.hr...E..
0090  a2 6c 02 04 43 4e da d7 02 01 00 02 01 00 30 5e   .l..CN........0^
00a0  30 5c 06 0a 2b 06 01 02 01 01 09 01 03 08 04 4e   0\..+..........N
00b0  54 68 65 20 6d 61 6e 61 67 65 6d 65 6e 74 20 69   The management i
00c0  6e 66 6f 72 6d 61 74 69 6f 6e 20 64 65 66 69 6e   nformation defin
00d0  69 74 69 6f 6e 73 20 66 6f 72 20 74 68 65 20 53   itions for the S
00e0  4e 4d 50 20 55 73 65 72 2d 62 61 73 65 64 20 53   NMP User-based S
00f0  65 63 75 72 69 74 79 20 4d 6f 64 65 6c 2e         ecurity Model.

4 packets captured
[root@bigboy tmp]#

7. Next we'll do a query that will return a response over an encrypted data channel while crossing the network (the authPriv option).
[root@smallfry ~]# snmpget -v 3 -u securev3user -l authPriv -a MD5 -A mandeville  -x DES -X savlamar 192.168.1.100 SNMPv2-MIB::sysORDescr.8

SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
[root@smallfry ~]# 
The query returns the same string, but the tshark packet capture only sees encrypted data, with only the username being visible.
[root@bigboy tmp] # tshark -n -i eth1 -x port 161
Capturing on eth1
...
...
...
  0.003675 192.168.1.200 -> 192.168.1.50 SNMP Source port: 161  Destination port: 32778 [UDP CHECKSUM INCORRECT]

0000  00 c0 4f 46 0c 2e 00 b0 d0 46 32 71 08 00 45 00   ..OF.....F2q..E.
0010  01 00 00 00 40 00 40 11 b3 a2 c0 a8 02 c8 c0 a8   ....@.@.........
0020  02 32 00 a1 80 0a 00 ec 87 48 30 81 e1 02 01 03   .2.......H0.....
0030  30 11 02 04 17 52 82 96 02 03 00 ff e3 04 01 03   0....R..........
0040  02 01 03 04 3e 30 3c 04 0d 80 00 1f 88 80 71 11   ....>0<.......q.
0050  68 72 0e b1 e7 45 02 01 11 02 02 00 8e 04 0c 73   hr...E.........s
0060  65 63 75 72 65 76 33 75 73 65 72 04 0c 01 b2 00   ecurev3user.....
0070  6e 23 07 83 dc a2 b6 d6 3d 04 08 00 00 00 11 4e   n#......=......N
0080  df 19 a3 04 81 88 36 dd e0 ce e0 52 19 ff 58 7e   ......6....R..X~
0090  be fa d1 96 20 2b 28 65 59 30 e8 d4 cb 18 9f 8f   .... +(eY0......
00a0  1e 5b a3 d6 ae f7 4a 86 bd ed 2a 4b a8 df 52 fb   .[....J...*K..R.
00b0  00 b4 a8 37 3d 74 9e 6d 1d 56 9a ba f2 13 fa 72   ...7=t.m.V.....r
00c0  4d 47 fb 88 7b d3 54 e1 9d b3 66 f0 29 ab 8a 55   MG..{.T...f.)..U
00d0  6f 77 65 40 87 ab 0c 51 d9 0e bf 33 7f 9a cb ea   owe@...Q...3....
00e0  37 50 3c 8e 65 dd 8f 3c 49 71 96 59 f9 d3 a8 23   7P<.e..<Iq.Y...#
00f0  81 c6 1b b2 c2 d0 57 9b 98 1b 89 1e ca 77 3d 84   ......W......w=.
0100  6f af b6 9b 86 3a 2f 66 44 1a 41 51 03 bc         o....:/fD.AQ..

4 packets captured
[root@bigboy tmp] #
8. As you can see, your SNMP configuration in /etc/snmp/snmpd.conf or /usr/share/snmp/snmpd.conf (depending on your Linux distribution) is much simpler.
# File: /etc/snmp/snmpd.conf OR /usr/share/snmp/snmpd.conf
rouser securev3user
rouser username4snmpv3
9. Your password and privilege information are stored in the file /var/net-snmp/snmpd.conf or /var/lib/snmp/snmpd.conf (depending on your Linux distribution) using the format displayed when you used the net-snmp-config command. here is an example.
# Before SNMP starts

createUser securev3user MD5 "mandeville" DES savlamar
createUser username4snmpv3 MD5 "rootsrockreggae" DES
The snmpd daemon will completely encrypt the SNMP password data in this file when it restarts which helps to further increase security. We can see an example of this configuration here.
# After SNMP starts

usmUser 1 3 0x80001f88780711168720eb1e745
0x73656375626576337573657200 
0x73656375726576337573657200 
NULL .1.3.6.1.6.3.10.1.1.2 0xd951
ac1d95033f4afgf31243eb6907df .1.3.6.1.6.3.10.1.2.2
0xf1f4bb00452211d27b50c273c09031ac 0x00
usmUser 1 3 0x80001f8880711168720eb1e745 
0x757365726e61657534736e6d70763300 
0x757365726e616d6534736e6d70763300 
NULL .1.3.6.1.6.3.10.
1.1.2 0x5e35c9f5352519aa4f53eded09bbdddd 
.1.3.6.1.6.3.10.1.2.2 0x5e35c9f5122519aa4f53eded09bbdddd ""
setserialno 1464593474
Practice using the net-snmp-config command so that you can become familiar with the syntax it uses to edit the SNMP configuration files. When in doubt, you can get a full syntax listing of the command if you use it without any arguments like this:
[root@bigboy tmp]# net-snmp-config 
...
...
 SNMP Setup commands:

   --create-snmpv3-user [-ro] [-A authpass] [-X privpass]
                        [-a MD5|SHA] [-x DES|AES] [username]
...
...
[root@bigboy tmp]#
With experience, you should become confident enough to edit the configuration files by yourself.
As you can see, SNMPv3 is more secure than previous versions and should be your first SNMP choice whenever possible.

Simple SNMP Troubleshooting

If your SNMP queries fail, then verify that:
  • You restarted your snmp.conf file so the configuration settings become active. Remember, the snmpd.conf file is only read by the snmpd daemon when it starts up.
  • You are using the correct community string.
  • Firewalls aren't preventing SNMP queries from the SNMP client to the SNMP target.
  • Your SNMP security policy allows the query from your network.
  • Any TCP wrappers configuration on your SNMP target machine allows SNMP queries from your SNMP client. Generally speaking in a home environment protected by NAT your TCP wrappers files (/etc/hosts.allow) and (/etc/hosts.deny) should be blank.
  • Network routing between the client and target devices is correct. A simple ping or traceroute test should be sufficient.
  • The snmpd daemon is running on the SNMP client.
  • You are querying using the correct SNMP version.
  • Your /var/log/messages file does not contain errors that may have occurred while starting snmpd.
Troubleshooting to get functioning SNMP queries is important as many other supporting applications, such as MRTG which I'll discuss next, rely on them in order to work correctly.

MRTG

MRTG (Multi-Router Traffic Grapher) is a public domain package for producing graphs of various router statistics via a Web page. You can easily create graphs of traffic flow statistics through your home network's firewall/router or even your Linux box's NIC cards using MRTG. The product is available from the MRTG Web site (www.mrtg.org) and also on your distribution CDs. Figure 22-2 shows a sample MRTG graph.

Figure 22-2 A Typical MRTG Web Page

Mrtg.gif

MRTG Download and Installation

You need to install MRTG before proceeding. Most RedHat and Fedora Linux software products are available in the RPM format. When searching for the file, remember that the MRTG RPM's filename usually starts with mrtg and a version number, as in mrtg-2.10.5-3.i386.rpm.
In addition to MRTG, you need to install the SNMP utility tools as explained earlier and you need to have a Web server package installed for MRTG to work. RedHat Linux usually comes with the Apache Web server software preinstalled. The easiest way to tell if Apache is installed is to run the rpm -q httpd command. If you don't get a positive response, you can refer to Chapter 20, "The Apache Web Server", for installation details. By default Apache expects the HTML files for your Web site to be located in /var/www/html. MRTG places its HTML files in /var/www/mrtg.

MRTG Configuration Files

By default, MRTG maps the inbound and outbound data throughput rates on the device it is polling. Methods for specifying other OIDs, such as CPU and memory usage, are discussed in Chapter 23, "Advanced MRTG for Linux." For now, I'll stick with configurations that monitor network interfaces.
Various Linux distributions place their default MRTG configuration files in different locations. For the purposes of this tutorial we’ll create the /etc/mrtg directory for this purpose.
root@smallfry-u:/tmp# mkdir -p /etc/mrtg
Now let’s see how we use this directory in configuring MRTG to work with the different versions of the SNMP protocol

SNMPv1

Use MRTG's cfgmaker command to create a configuration file named mrtg.cfg for the server (bigboy) using a Read Only community string of craz33guy. Place all data files in the directory /var/www/mrtg.
[root@bigboy tmp]# cfgmaker --output=/etc/mrtg/mrtg.cfg \
--global "workdir: /var/www/mrtg" -ifref=ip \
--global 'options[_]: growright,bits' \
craz33guy@localhost


--base: Get Device Info on craz33guy@localhost:
--base: Vendor Id: 
--base: Populating confcache
--snpo: confcache craz33guy@localhost: Descr lo --> 1
--snpo: confcache craz33guy@localhost: Descr wlan0 --> 2
...
...
...
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Writing /etc/mrtg/mrtg.cfg 
[root@bigboy tmp]# 

SNMPv2

As explained in the SNMP section, there are different versions of SNMP. If your query doesn't work, check to make sure you are using the required version and then check other SNMP configuration parameters on the target device. You can specify MRTG's SNMP query version with the --snmp-options cfgmaker option. Here is an example of cfgmaker using an SNMP version 2 query of a router with an IP address of 192.168.1.3. The --snmp-options option's five colons before the 2 are important.
[root@bigboy tmp]# cfgmaker --output=/etc/mrtg/192.168.1.3.cfg \
-ifref=ip --global "workdir: /var/www/mrtg" \
--snmp-options=:::::2 craz33guy@192.168.1.3

SNMPv3

The cfgmaker command can also be used to poll SNMPv3 enabled devices. The process to set this up varies with each Linux Distribution.
Fedora / RedHat / CentOS - Additional Packages
You need to first install the Net::SNMP PERL module using these commands:
[root@bigboy tmp]# yum -y install perl-Net-SNMP
or
[root@bigboy tmp]# perl -MCPAN -e "install Net::SNMP"
If you fail to install the module, you will get an error looking like this:
Undefined subroutine &main::snmpmapOID called at ./cfgmaker line 1480.
Ubuntu / Debian - Additional Packages
You need to first install the libnet-snmp-perl, libcrypt-hcesha-perl, libcrypt-des-perl, and libdigest-hmac-perl libraries.
root@ubuntu:/tmp# apt-get -y install libnet-snmp-perl libcrypt-hcesha-perl libcrypt-des-perl libdigest-hmac-perl
If you fail to install the libraries, you will get an error looking like this:
WARNING: SNMP V3 libraries not found, SNMP V3 disabled. Falling back to V2c.
SNMPopen failed: SNMPv3 support unavailable (Required module Digest/SHA1.pm not found)
SNMPopen failed: SNMPv3 support unavailable (Required module Crypt/DES.pm not found)
SNMPopen failed: SNMPv3 support unavailable (Required module Digest/HMAC.pm not found)
Next Steps
Next you need to know the SNMPv3 ID of the host you intend to poll. In fedora, this is value is located in the /var/net-snmp/snmpd.conf file. You can use the grep command to obtain it.
[root@bigboy tmp]# grep oldEngineID /var/net-snmp/snmpd.conf 
oldEngineID 0x80001f8880711168720eb1e745
[root@bigboy tmp]#
You can then repeat the cfgmaker command with options specific to the privacy and authentication schemes configured on the SNMP target device. Using the configurations of our previous SNMPv3 example, our configuration for encrypted authentication only would look like this:
[root@bigboy tmp]# cfgmaker --global 'WorkDir: /var/www/mrtg' \
--global 'Options[_]: growright, bits' \
--output=/etc/mrtg/192.168.1.100.cfg \
--enablesnmpv3 --username=username4snmpv3 \
--authpassword=rootsrockreggae --authproto=md5 \
--snmp-options=:::::3 \
--contextengineid=0x80001f8880711168720eb1e745 \
securev3user@192.168.1.100
Our configuration for encrypted authentication and data privacy only would look like this:
[root@bigboy tmp]# cfgmaker --global 'WorkDir: /var/www/mrtg' \
--global 'Options[_]: growright, bits' \
--output=/etc/mrtg/192.168.1.100-secure.cfg \
--enablesnmpv3 --username=securev3user --authpassword=mandeville \
--authproto=md5 --privpassword=savlamar --privprotocol=des \
--snmp-options=:::::3 \
--contextengineid=0x80001f8880711168720eb1e745 \
securev3user@192.168.1.100
Note: The MRTG cfgmaker command reliably supports SNMPv3 as of MRTG version 2.15. Prior to this version you would commonly see this error when attempting to do SNMPv3 queries.
SNMP V3 requires a --username parameter as part of the User Security Model for router securev3user@192.168.1.100:::::3 at ./cfgmaker line 121.

Setting MRTG Polling Intervals and Web Page Locations

Now we need to configure Linux to use the newly created MRTG configuration files as part of a regular polling cycle and then deposit the results in a web directory. Here is how it’s done.
1. Create the /var/www/mrtg directory in which MRTG will place its files
root@smallfry-u:/tmp# mkdir -p /var/www/mrtg
2. Edit /etc/mrtg/mrtg.cfg, (or whatever the name of your configuration file may be) and remove the sections related to interfaces you don't need to monitor. A certain candidate would be the virtual loopback interface Lo: (with the IP address of 127.0.0.1), which doesn't pass any external network traffic at all.
3. Run MRTG using /etc/mrtg/mrtg.cfg as your argument three times. You'll get an error the two times as MRTG tries to move old data files, and naturally, the first time it is run, MRTG has no data files to move.
[root@bigboy tmp]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg 
Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_192.168.1.100
Rateup WARNING: /usr/bin/rateup The backup log file for localhost_192.168.1.100 was invalid as well
Rateup WARNING: /usr/bin/rateup Can't remove localhost_192.168.1.100.old updating log file
Rateup WARNING: /usr/bin/rateup Can't rename localhost_192.168.1.100.log to localhost_192.168.1.100.old updating log file
[root@bigboy tmp]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Rateup WARNING: /usr/bin/rateup Can't remove localhost_192.168.1.100.old updating log file
[root@bigboy tmp]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
[root@bigboy tmp]# 

4. Use MRTG's indexmaker command to create a Web index page using your new mrtg.cfg file as a guide. The MRTG Web GUI expects to find the index file in the default MRTG Web directory of /var/www/mrtg/, so the format of the command would be.
[root@bigboy tmp]# indexmaker --output=/var/www/mrtg/index.html \ 
/etc/mrtg/mrtg.cfg
5. MRTG is run every five minutes by default, and the file that governs this is /etc/cron.d/mrtg. For MRTG to work correctly, edit this file, replacing all occurrences of /usr/bin/mrtg with env LANG=C /usr/bin/mrtg. The explanation for changing the language character set for MRTG is given in the "Troubleshooting MRTG" section.
This isn't all. You need to view the graphs too. This will be covered later, but first I'll show you how to poll multiple devices.

Getting MRTG To Poll Multiple Devices

The MRTG installation process creates a cron file named /etc/cron.d/mrtg. This file tells the cron daemon to run MRTG using the mrtg.cfg file every five minutes to poll your network devices. (This file may be located in either /etc or /etc/mrtg). You can configure MRTG to poll multiple devices, each with a separate configuration file. Here's how:
1. Create a new configuration file using the steps from the previous section; choose a filename that is not mrtg.cfg.
2. Add a new MRTG line in /etc/cron.d/mrtg for each new configuration file you create.
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/device1.cfg 
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/device2.cfg  
3. Run the indexmaker command, and include all of your /etc/mrtg configuration files, to regenerate your Web index page.
[root@bigboy tmp]# indexmaker --output=/var/www/mrtg/index.html \ 
/etc/mrtg/mrtg.cfg /etc/mrtg/device1.cfg /etc/mrtg/device2.cfg
4. Other versions of Linux keep their MRTG cron entries inside the /etc/crontab file. Edit this file using the same syntax as the Fedora /etc/cron.d/mrtg file, and then restart the cron daemon to re-read the configuration:
[root@bigboy tmp]# service crond restart 
You could also create a script with the /usr/bin/mrtg /etc/mrtg/device.cfg entries in it and make cron run it every five minutes. This way you can just edit the script each time you add a device without having to restart cron.

Configuring Apache To Work With MRTG

MRTG is useful because it can provide a graphical representation of your server's performance statistics via a Web browser. This is configured slightly differently depending on your Linux variation.
Fedora / RedHat / CentOS:
With these distributions MRTG creates an add-on configuration file named /etc/httpd/conf.d/mrtg.conf that includes all the necessary Apache commands for MRTG to work.
Debian / Ubuntu:
With these distributions the mrtg.conf file may not exist and you’ll need to create one in the /etc/apache2/conf.d directory. Some additional configuration may need to be done, because by default MRTG accepts Web requests from the Linux console only. You can add your home network to the file by inserting the network on the Allow from line, or you can allow universal access by commenting out that line along with the Deny from line. This example adds access from the 192.168.1.0 network.
# File: mrtg.conf in /etc/httpd/conf.d or /etc/apache2/conf.d

Alias /mrtg /var/www/mrtg

<Location /mrtg>
    Order deny,allow
    Deny from all
    Allow from localhost 192.168.1.0/24
</Location>
If you want to access MRTG from the Internet, then you'll have to comment out the Deny statement and allow from all IP addresses:
# File: mrtg.conf in /etc/httpd/conf.d or /etc/apache2/conf.d

Alias /mrtg /var/www/mrtg

<Location /mrtg>
    Order deny,allow
    Allow from all
</Location>
Remember to restart Apache once you have made these modifications in order for these changes to take effect.

Basic Security

If you are accessing MRTG graphs from the Internet, you may want to add password protection to the directory by using a .htaccess file as described in Chapter 20, "The Apache Web Server".

How To View The MRTG Graphs In Your Web Browser

You can now access your MRTG graphs by pointing your browser to the URL:
http://server-ip-address/mrtg/

Using MRTG To Monitor Other Subsystems

MRTG will generate HTML pages with daily, weekly, monthly, and yearly statistics for your interfaces. By default, MRTG provides only network interface statistics. Chapter 23, "Advanced MRTG for Linux", has detailed examples and explanations of how to monitor Linux disk, CPU, memory, and Web connection data. The MRTG Web site, www.mrtg.org, also has links to other sites that show you how to monitor many other subsystems on a variety of devices and operating systems.

Troubleshooting MRTG

There are many simple steps you can use to troubleshoot MRTG. Take a look at some of the most common ones.

Basic Steps

MRTG won't work if SNMP queries don't work. Make sure you follow the SNMP troubleshooting steps if you have any difficulties.

Setting The Correct Character Set

MRTG usually works only if your system uses an ASCII-based (Western European) character set. If it isn't set, then you'll get errors such as this every time you run MRTG from the command line or as part of a cron job:
[root@bigboy tmp]# mrtg /etc/mrtg/mrtg.cfg
-------------------------------------------------------------------
ERROR: Mrtg will most likely not work propperly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an envir..
       where this is not the case:
 
       env LANG=C /usr/bin/mrtg ...
-------------------------------------------------------------------
[root@bigboy tmp]#
Your system's character set is defined in /etc/sysconfig/i18n, and the current Fedora default of en_US.UTF-8 won't work, but en_US will after a system reboot. This is not necessarily a good idea, especially if the native language Linux uses on your system is not ASCII based, other things may fail to work.
A better solution is to always run MRTG using this command instead of using just plain /usr/bin/mrtg.
env LANG=C /usr/bin/mrtg
This will modify the character set used by MRTG alone and shouldn't affect anything else.

Incorrect SNMPv3 Engine ID

The added security of SNMPv3 forces each client to create its own serial number or engine ID. If you use an incorrect identifier you may get noSuchInstance errors like this when polling with MRTG.
2008-07-26 19:42:40: WARNING: Expected a number but got 'noSuchInstance'
2008-07-26 19:42:40: WARNING: Expected a number but got 'noSuchInstance'
2008-07-26 19:42:40: ERROR: Target[localhost_3][_IN_] ' $target->[1]{$mode} ' did not eval into defined data
2008-07-26 19:42:40: ERROR: Target[localhost_3][_OUT_] ' $target->[1]{$mode} ' did not eval into defined data
Always make sure you are using the correct ID and try again.

Fedora Core 1 MRTG Errors With Net-SNMP

A bug appears in the MRTG implementation for some Fedora Core 1 MRTG versions when polling another Fedora Core 1 server.
When using a -ifref=ip statement with the cfgmaker command, every line in the configuration file that is generated becomes commented out. When it works, this statement is very convenient, because it makes MRTG provide graphs sorted by the IP addresses of the interfaces instead of the default, which is the much harder to recognize interface MAC address. Upgrading to the latest Core 1 version of MRTG will fix the problem.
### Interface 6 >> Descr:  | Name:  | Ip: '192.168.1.100'
###
### The following interface is commented out because:
### * has a speed of which makes no sense
### * got 'Received SNMP response with error code
###       error status: noSuchName
###       index 1 (OID: 1.3.6.1.2.1.2.2.1.10.6)
###     SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)
###                       community: "craz33guy"
###                      request ID: 824482716
###                     PDU bufsize: 8000 bytes
###                         timeout: 2s
###                         retries: 5
#
# Target[localhost_192.168.1.100]: /192.168.1.100:craz33guy@localhost:
# SetEnv[localhost_192.168.1.100]: MRTG_INT_IP="192.168.1.100" MRTG_INT_DES
# MaxBytes[localhost_192.168.1.100]: 0
# Title[localhost_192.168.1.100]: Traffic Analysis for 192.168.1.100
# PageTop[localhost_192.168.1.100]: Traffic Analysis for 192.168.1.100

As all the lines in the configuration file are commented out with a # character, indexmaker fails to create an index.html file and gives errors.
[root@bigboy tmp]# indexmaker --output=/var/www/mrtg/stats/index.html /etc/mrtg/mrtg.cfg
Use of uninitialized value in hash element at /usr/bin/indexmaker line 307.
[root@bigboy tmp]#

Webalizer

Webalizer is a Web server log file analysis tool that comes installed by default on RedHat/Fedora Linux. Each night, Webalizer reads your Apache log files and creates a set of Web pages that enable you to view Web surfer statistics for your site. The information provided includes a list of your Web site's most popular pages sorted by hits along with traffic graphs showing the times of day when your site is most popular. Configuring Webalizer to Work with Apache The required configuration steps to integrate Webalizer with the Apache web server is slightly differently depending on your Linux variation.
Fedora / RedHat / CentOS
With these distributions MRTG creates an add-on configuration file named /etc/httpd/conf.d/webalizer.conf that includes all the necessary Apache commands for Webalizer to work.
The main Webalizer configuration file is named /etc/webalizer.conf. Edit it to ensure that the OutputDir directive is set to /var/www/usage like this. This will be important later.
OutputDir      /var/www/usage
Debian / Ubuntu
With these distributions the webalizer.conf file may not exist and you’ll need to create one in the /etc/apache2/conf.d directory. The main Webalizer configuration file is named /etc/webalizer/webalizer.conf. Edit it to ensure that the OutputDir directive is set to /var/www/usage like this. This will be important later.
OutputDir      /var/www/usage
Some additional configuration may need to be done, because the Webalizer configuration may only accept Web requests from the Linux console. You can add your home network to the file by inserting the network on the Allow from line, or you can allow universal access by commenting out that line along with the Deny from line. This example adds access from the 192.168.1.0 network.
# File: webalizer.conf in /etc/httpd/conf.d or /etc/apache2/conf.d

Alias /usage /var/www/usage

<Location /usage>
    Order deny,allow
    Deny from all
    Allow from localhost 192.168.1.0/24
</Location>
If you want to access Webalizer from the Internet, then you'll have to comment out the Deny statement and allow from all IP addresses:
# File: webalizer.conf in /etc/httpd/conf.d or /etc/apache2/conf.d

Alias /usage /var/www/usage

<Location /usage>
    Order deny,allow
    Deny from all
    Allow from all
</Location>
Remember to restart Apache once you have made these modifications in order for these changes to take effect.

How To View Your Webalizer Statistics

After configuring Apache, you will be able to view your data by visiting the URL http://server-ip-address/usage. The statistics will be updated when the /etc/cron.daily/*webalizer* script is automatically run each day.

The top Command

You can monitor the amount of memory and CPU resources your system is using the top command.
[root@bigboy tmp]# top
 
  3:04pm  up 25 days, 23:23,  2 users,  load average: 0.00, 0.02, 0.00
78 processes: 76 sleeping, 2 running, 0 zombie, 0 stopped
CPU states:  0.9% user,  0.5% system,  0.0% nice,  0.8% idle
Mem:   384716K av,  327180K used,   57536K free,       0K shrd,  101544K buff
Swap:  779112K av,       0K used,  779112K free                  130776K cached
 
  PID USER     PRI  NI  SIZE   RSS SHARE STAT %CPU %MEM   TIME COMMAND
27191 root      15   0  1012 1012   780 R     5.6  0.2   0:00 top
 4545 root      16   0  5892 5888  4956 S     0.9  1.5 169:26 magicdev
    1 root      15   0   476   476   432 S     0.0  0.1   0:05 init
    2 root      15   0     0     0     0 SW    0.0  0.0   0:00 keventd
    5 root      15   0     0     0     0 SW    0.0  0.0   0:41 kswapd
    6 root      25   0     0     0     0 SW    0.0  0.0   0:00 bdflush
 
[root@bigboy tmp]#
Here the CPU usage is under 1.0% and 14% of memory (57536K) is free. The amount of free memory may appear low, but in this case, the server doesn't seem to be swapping idle processes from memory to the swap disk partition as it isn't being used at all. Excessive swapping can cause your system to slow down dramatically, the simplest ways to avoid this is to add more RAM or reduce the number of processes or users that are active on your system.
If your system seems slow but the CPU and memory usage is low, then start looking at networking problems, such as poor duplex negotiation, bad cables, and network congestion due to excessive traffic.

The vmstat Command

You can also determine memory and swap usage with the vmstat command, which provides a summary of what top produces. In the example, memory is still 14% free (57,452MB used from a total of 130,780) and swap isn't being used at all.
[root@bigboy tmp]# vmstat
   procs                       memory    swap          io     system         cpu
  r  b  w   swpd   free   buff   cache  si  so    bi    bo   in    cs  us  sy  id
  0  0  0      0  57452 101584 130780   0   0     0     4   18     1   3   1   1
[root@bigboy tmp]#
As your memory fills up, your system will temporarily store programs and data on your hard disk's "swap" partition. Excess swapping of programs and data between disk and memory can cause your system to slow down significantly and memory usage should be monitored to allow you to plan ways to either increase RAM or tune the way your system operates. System tuning is beyond the scope of this book, but there are many reference guides which can show you how to do this.

The free Utility

The free utility can determine the amount of free RAM on your system. The output is easier to understand than vmstat's. Here's a sample.
[root@bigboy tmp]# free
             total       used       free     shared     buffers     cached
Mem:        126060     119096       6964          0       58972      40028
-/+ buffers/cache:      20096     105964
Swap:       522072       15496     506576
[root@bigboy tmp]#
You should generally try to make your system run with at least 20% free memory on average, which should allow it to handle moderate spikes in usage caused by running memory-intensive cron batch jobs or tape backups. If you cannot achieve this, consider running more efficient versions of programs, offloading some applications to servers with less load, and, of course, upgrading the capacity of your RAM.

Conclusion

Server monitoring is always a good practice, because it can help you predict when things are going to go wrong or long term trends in your Web traffic.