Thursday, January 7, 2010

Network File Service ( NFS)

A Network File System(NFS) allows remote hosts to mount file systems over the network and interact with those file systems as though they are mounted locally.
NFS v3 has got many features over older version of NFS ( NFS v2) like better error reporting, variable size file handling. NFS v2 uses UDP protocol which is stateless protocol so reduces network traffic but when server goes down client will clog the network with traffic with packets to search for NFS server. NFS v3 uses TCP as the default protocol.

Following are the services required to run a NFS server

1. portmap : The rpc service for Linux, maps calls made from other machines to the correct RPC services.
2. nfs: Starts the appropriate RPC processes to service requests for shared NFS file systems.
3. rpc.mountd : mounts and unmounts filesystems.
4. rpc.nfsd : NFS server process . This process corresponds to nfs service.

Other services are rpc.lockd, rpc.statd, rpc.rquotad

As already mentioned that NFS is a rpc process, so before starting nfs portmap service which actually maps rpc request to the correct services should be up and running. When a RPC service start , it notifies to portmap with the port no that they are monitoring and the RPC program number they expect to serve. Client system contacts portmap on the server with a particular RPC program number . The portmap service redirect the clinet to the proper port no so it can communicate with the requested service.

So before we go ahead with nfs server configuration , lets check the status of portmap service status and the RPC based services which is enabled for portmap
rpcinfo -p
or # service portmap status ( to check for only portmap status)

Configuration file

NFS server configuration file is /etc/exports which controls which filesystems are exported to remote hosts and specifies options.

Example:

/data linuxserver

where /data is exported filesystem and which can be accessed only from host( linuxserver). Without any options specifed , it will be mounted as read-only . To mount as rw mode , you need to specifically mentioned as given below

/data linuxserver(rw)

There are various options are available like wdelay, root_squash, all_squash. async and sync . For detailed explanation of each option , please visit the following link.
http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/ref-guide/s1-nfs-server-export.html

Once you are ready with the configuration file(/etc/exports) , start the nfs server (service nfs start)

Cool server configuration is done . Below are the few utilities which is useful to verify the exported list , refreshes the export list .
exporftfs -a
exportfs -v ( to view the exports and their options on the local machine).
showmount -e hostname (to display the exports from remote machine)
rpcinfo -p hostname ( used to probe the portmapper on hostname and print a list of all registered RPC services)
exportfs -u (unexport all shared directories)

Finally we are done with the server configuration . Now lets start with the client side configuration . Nothing much on the client side, we need to know various ways of mounting the remote filesystem.
NFS share mounted at boot time by /etc/init.d/netfs so check whether netfs service is running
chkconfig --list grep netfs

Option 1:

Using mount command
e.g mount linuxserver:/data /local/data

where linuserver is the hostname where /data is in the export list . /local/data is the mount point in the local machine .

Option 2:

Monday, January 4, 2010

Linux file system

Have you ever come across a situation where you have installed linux with partition of fixed size and later you realized that one of the partition size needs to be increased. The only way is to delete the existing partition , create new partition of the required size, install the operating system again and reinstall the application . Is not a tedious process ? Yes it is . LVM is there to rescue you from the tedious task of reinstalling the OS.

Now lets discuss what exactly this LVM is, what it does and how to create that.

LVM is a Logical Volume Manager in Linux. LVM v2 is the latest version of LVM but is almost completely backward compatible with the volume created LVM v1 . Before upgrading from LVM v1 to LVM v2 snapshot volume must be deleted on LVM v1 if one is created.

Kernel 2.6 defaulty support LVM v2 but 2.4 kernel needs patching to support LVM v2 which defaultly supports LVM v1.

Before we go ahead and create logical volume using LVM lets understand the following terms.
Volume Group:
The Volume Group is the highest level abstraction used withn the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit

Physical Volume:
A Physical Volume is typically a hard disk.

Logical Volume:
It actually contain the file system(ext3) as in disk partion in non-LVM system.

Physical Extent:
Each phyical volume is divided into chunk of data, known as physical extents, these extents have the same size as logical extents in the volume group.

Logical Extent:
Each logical volume is split into chunks of data, known as logical extents and the size is same for all logical volumes in the volume group.

Following are the steps to be followed to create logical volumes .In the following example lets assume its a scsi devices and is the first device on the system
1. Create partition using fdisk with partion id 8e
fdisk /dev/sda

2. Create phyical volume on partition created in steps 1
pvcreate /dev/sda{5,7}

3. Create volume group.
vgcreate vgo /dev/sda{5,7}

vg0 is the volume group name which includes three physical volume sda5, sda6 and sda7.

4. Create logical volume
lvcreate -L +150M -n development Vg0

logical volume "development" of size 150MB

Once the logical volume is created , the final steps , create filesystem , mount it and start using to store files.

5. mkfs.ext3 /dev/Vg0/developement ( putting filesystem on the logical volume)

6 .mount /dev/Vg0/development /data ( to mount the filesyste).

7. Update the /etc/fstab file to automatically mount the above partition
/dev/Vg0/development /data ext3 defaults 0 0

Finally we have a logical volume ready to use. But one of the main advantage of lvm is partition resizing without deleting and formating the partion . The command is

lvextend -L +50MB /dev/Vg0/development

To reduce the size of the logical volume

lvreduce -L -3G -n /dev/Vg0/development