Autofs Nfs

broken image


Direct map support

AutoFS: AutoFS is a file system mechanism that provides automatic mounting the NFS protocol. It is a client side service. AutoFS service mounts and unmounts file systems as required without any user intervention. Autofs is a program that automatically mounts specified directories on an on-demand basis. It is based on a kernel module for high efficiency, and can manage both local directories and network shares. These automatic mount points are mounted only when they are accessed, and unmounted after a certain period of inactivity. This on-demand behavior saves bandwidth and results in better performance.

Direct maps in autofs provide a mechanism to automatically mount file systems at arbitrary points in the file system hierarchy. A direct map is denoted by a mount point of /- in the master map. Entries in a direct map contain an absolute path name as a key (instead of the relative path names used in indirect maps).
Lazy mount and unmount support
Multi-mount map entries describe a hierarchy of mount points under a single key. A good example of this is the -hosts map, commonly used for automounting all exports from a host under '/net/host' as a multi-mount map entry. When using the '-hosts' map, an 'ls' of '/net/host' will mount autofs trigger mounts for each export from host and mount and expire them as they are accessed. This can greatly reduce the number of active mounts needed when accessing a server with a large number of exports.
Enhanced LDAP support
The Lightweight Directory Access Protocol (LDAP) support in autofs version 5 has been enhanced in several ways with respect to autofs version 4. The autofs configuration file (/etc/sysconfig/autofs) provides a mechanism to specify the autofs schema that a site implements, thus precluding the need to determine this via trial and error in the application itself. In addition, authenticated binds to the LDAP server are now supported, using most mechanisms supported by the common LDAP server implementations. A new configuration file has been added for this support: /etc/autofs_ldap_auth.conf. The default configuration file is self-documenting, and uses an XML format.
Proper use of the Name Service Switch (nsswitch) configuration.
The Name Service Switch configuration file exists to provide a means of determining from where specific configuration data comes. The reason for this configuration is to allow administrators the flexibility of using the back-end database of choice, while maintaining a uniform software interface to access the data. While the version 4 automounter is becoming increasingly better at handling the NSS configuration, it is still not complete. Autofs version 5, on the other hand, is a complete implementation.
Refer to man nsswitch.conf for more information on the supported syntax of this file. Please note that not all NSS databases are valid map sources and the parser will reject ones that are invalid. Valid sources are files, yp, nis, nisplus, ldap, and hesiod.
Multiple master map entries per autofs mount point
One thing that is frequently used but not yet mentioned is the handling of multiple master map entries for the direct mount point /-. The map keys for each entry are merged and behave as one map.
An example is seen in the connectathon test maps for the direct mounts below:
I have already written an article to configure NFS server which you can go to using the below link

What is Autofs?

Autofs is used to automatically mount any filesystem on demand as and when you access them and not only it will mount automatically but it can automatically unmount any filesystem when not in used for a particular predefined timeout value.

Why should I use Autofs ?

I understand a question which generally pops up in people's mind that even putting nfs share entry in /etc/fstab makes it auto mountable so how does it differs from autofs? Well as I defined above autofs is not only/at all about mounting the share on every reboot.
Take a scenario where a nfs share is supposed to be mounted at boot but it is not accessibe due to some reasons which will lead to delayed startup or even there might be a case when your OS will not at all boot up.

Advantages of AutoFS

  • Shares are accessed automatically and transparently when a user tries to access any files or directories under the designated mount point of the remote filesystem to be mounted.
  • Booting time is significantly reduced because no mounting is done at boot time.
  • Network access and efficiency are improved by reducing the number of permanently active mount points.
  • Failed mount requests can be reduced by designating alternate servers as the source of a filesystem.

In this article I will show you the configuration steps for autofs using NFS share

We we have two servers namely nfsserver and nfsclient. Lets start configuring a NFS share on nfsserver Divx pro 10 4 download free.

On nfsserver

Since this article is all about autofs I am not using much permission on the exports. These are two simple shares which I am sharing with nfsclient

Restart the nfs services or reload the shares

NOTE: Do not run this command on production environment if anyone is accessing any of the share as it will disrupt the traffic for few seconds.

Genreally we reload the nfs share using the below command

The above command reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports. This option removes entries in var/lib/nfs/etab which have been deleted from /etc/exports, and removes any entries from the kernel export table which are no longer valid.

To see all the shares and the applied permissions

Well our server side work is done lets roll over to nfsclient

NOTE: For this article I have disabled my iptables and selinux.

In case you want to use iptables insert the below rule into your INPUT chain

On nfsclient
This is the place where the magic will happen. But for that we will have to configure autofs.

auto.master file

The primary configuration file for the automounter is /etc/auto.master, also referred to as the master map. The master map lists autofs-controlled mount points on the system, and their corresponding configuration files or network sources known as automount maps. The format of the master map is as shown below

mount-point map-name options
For our case

Description

Using the above line we are giving the default mount point as /mnt and redirecting to different file i.e. auto.master file to look into /etc/auto.misc for further information about the shares and server details we want to mount on /mnt. And lastly we have provided and extra option providing a timeout value to unmount the share in case or any inactivity for 20seconds.
Description
The autofs mount point, /mnt, for example.
The name of a map source which contains a list of mount points, and the file system location from which those mount points should be mounted.
If supplied, these will apply to all entries in the given map provided they don't themselves have options specified. This behavior is different from autofs version 4 where options were cumulative. This has been changed to implement mixed environment compatibility.

auto.misc file

Autofs Nfs Ubuntu

The general format of maps is similar to the master map, however the 'options' appear between the mount point and the location instead of at the end of the entry as in the master map:
mount-point [options] location

Description
This refers to the autofs mount point. This can be a single directory name for an indirect mount or the full path of the mount point for direct mounts. Each direct and indirect map entry key (mount-point above) may be followed by a space separated list of offset directories (sub directory names each beginning with a '/') making them what is known as a multi-mount entry.
Whenever supplied, these are the mount options for the map entries that do not specify their own options.
This refers to the file system location such as a local file system path (preceded with the Sun map format escape character ':' for map names beginning with '/'), an NFS file system or other valid file system location.

Enough with the explanation next edit auto.misc file

Save and exit the file

Description

Here we have defined two different mount points 'deepak' and 'raid' for their respective shares. Now next time as soon as you try to access these shares using 'cd' command the shares will be automatically mounted and when you are done just come out of the share path and after 20 seconds the share would be unmounted. We have specified the filesystem type for both the shares along with the original share location on our NFS server.

Its time to reload our autofs services

Verify if autofs is running

Reloading maps
Make sure the NFS shares are not already mounted

So none of the NFS shares are mounted still lets try to access them

Nfs
As you see the files under 'deepak' share on NFS server are accessible from the nfsclient just by doing 'cd' to the share

Notebook 4 0 6. Similarly you can try to access another share i.e. 'raid'

IMPORTANT NOTE : If you do not know the names of the share used under auto.misc then you won't be able to access the NFS shares as be defualt /mnt would be shown as empty. The shares are mounted only when you 'cd' into the share directory.

You can use the watch command to verify if the shares automatically gets unmounted.

After few seconds the mount point 'work' is automatically unmounted as you can see below

Nfs4
As you see the files under 'deepak' share on NFS server are accessible from the nfsclient just by doing 'cd' to the share

Notebook 4 0 6. Similarly you can try to access another share i.e. 'raid'

IMPORTANT NOTE : If you do not know the names of the share used under auto.misc then you won't be able to access the NFS shares as be defualt /mnt would be shown as empty. The shares are mounted only when you 'cd' into the share directory.

You can use the watch command to verify if the shares automatically gets unmounted.

After few seconds the mount point 'work' is automatically unmounted as you can see below

Autofs Nfs Example

Related Articles:





broken image