RHEL6–36–AUTOFS
WHAT IS AUTOFS?
Mounted partition is a dedicated resource in NFS whereas in autofs
mount & unmount are not permanent. They automatically mounted whenever
accessed and unmounted if not used for certain time.
WHY /WHEN /WHERE AUTOFS?
If we want to save precious bandwidth & system resources then we
should opt for autofs.
Still not clear…?
Let’s have an example,
Suppose you have a suitcase filled with imp file and docs, which are
mandatory for you to carry all the times and you are a frequent traveller also
and at after reaching at each destination you are supposed to edit some of your
imp docs/files.
Hence my native place is A, and I need to frequently go to
B…C…D…E…F…G. At all destinations you have a room booked on your name. Reached
the room at “B”, open the suitcase, do your task edit and save the docs, pack
the suitcase and move to “C” do the same and move on….
THAT’s It…!!!
Easy naa… what is the big deal in this…?
We all are doing same. Great… you caught it. We all are doing same,
Now let’s make it little technical.
Consider your native place “A” and all the rooms at destinations “B…C…D…E…F…G”
as servers.
Your “Suitcase” as “HOME” directory on each servers.
The entire imp Files & Docs are saved at the home dir of your
native place “A”.
Again … That’s it!!!
Now please show me how you will move with your suitcase from “A” to
all the destinations and edit/save your imp docs.
Confused… LL
Here comes the “AUTOFS”
Actually what autofs will do is, it will mount your native home dir
to all destinations wherever you go. Not only for “HOME” dirs, we can use it
with any “NFS” mount. But this is most useful in case of “home” directories.
[root@rhel6-test1 ~]# rpm -qa |grep -i autofs
[root@rhel6-test1 ~]# yum install -y autofs*
Main config file is, /etc/auto.master è Here
we specify the directories to be automounted and are monitored by “automount”.
To control global behavior of autofs, /etc/sysconfig/autofs
/etc/auto.master is default map. The auto_master map associates a
directory with a map. It is a master list specifying all the maps that autofs
should check.
Example,
+auto_master
/net -hosts è Special Map
/home auto_home è Indirect
Map
/-
auto_direct è Direct
Map
SYNTAX: mount-point map-name [ mount-options ]
mount-point:
mount-point is the full (absolute) path name of a directory. If the
directory does not exist, autofs creates it if possible. If the directory
exists and is not empty, mounting on it hides its contents. In this case,
autofs issues a warning.
The notation /- as a mount point indicates that the map in question
is a direct map, and no particular mount point is associated with the map as a
whole.
map-name:
map-name is the map autofs uses to find directions to locations, or
mount information. If the name is preceded by a slash (/), autofs interprets
the name as a local file. Otherwise, autofs searches for the mount information
using the search specified in the name service switch configuration file
(/etc/nsswitch.conf). Special maps are also used for /net
mount-options:
mount-options is an optional, comma-separated list of options that
apply to the mounting of the entries specified in map-name, unless the entries
in map-name list other options.
/net -hosts è Special Map
Autofs mounts under the directory /net all the entries in the special
map -hosts. This is a built-in map
that uses only the /etc/hosts database.
/home auto_home è Indirect Map
An indirect map uses a substitution value of a key to establish the
association between a mount point on the client and a directory on the server.
Indirect maps are useful for accessing specific file systems, like home
directories.
SYNTAX: key [ mount-options ] location
Key:
Key is a simple name (no slashes) in an indirect map.
Mount-options:
Mount-options is the options you want to apply to this particular
mount. They are required only if they differ from the map default. Options for
each specific type of file system are listed in the mount man page for that
file system.
Location:
Location is the location of the file system, specified (one or more)
as server:pathname.
/- auto_direct è Direct Map
The notation /- as a mount point indicates that the map in question
is a direct map, and no particular mount point is associated with the map as a
whole.
A direct map is an automount point. With a direct map, there is a
direct association between a mount point on the client and a directory on the
server. Direct maps have a full path name and indicate the relationship
explicitly.
SYNTAX: key [ mount-options ] location
key:
key is the path name of the mount point in a direct map.
mount-options:
mount-options is the options you want to apply to this particular
mount. They are required only if they differ from the map default.
location:
location is the location of the file system, specified (one or more)
as server:pathname for NFS file systems or :devicename for High Sierra file
systems (HSFS).
There is one very interesting share specified at “/etc/auto.master”.
SPECIAL MAP:
/net -hosts
This share is always ready, provided both/several machines have entry
in their “/etc/hosts” file.
I have 2 machines right now, “rhel6-server” & “rhel6-test1”, both
have entries of each other in their /etc/hosts.
There are 2 shared directories on “rhel6-server”
[root@rhel6-server ~]# exportfs -v
/testnfs
<world>(rw,wdelay,root_squash,no_subtree_check)
/nfstest1
<world>(rw,wdelay,no_root_squash,no_subtree_check)
These are not mounted anywhere, let’s check.
[root@rhel6-test1 /]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 6.3G
8.5G 43% /
tmpfs 370M 76K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 85M
1.8G 5% /home
.host:/ 108G 99G
8.5G 93% /mnt/hgfs
/dev/sr0 3.5G 3.5G
0 100% /media/RHEL_6.4 x86_64 Disc 1
And I want to access these directories from “rhel6-test1” without
being mounted.
[root@rhel6-test1 net]# cd /net/rhel6-server
-bash: cd: /net/rhel6-server: No such file or directory
I am unable to access, Why…??
The directories are well shared by “rhel6-server”,
Service “nfs” is started on both servers. Let’s check for service
“autofs”
[root@rhel6-server ~]# service autofs status
automount (pid 2778) is
running...
[root@rhel6-test1 net]# service autofs status
automount is stopped
This was the problem, let’s start the service.
[root@rhel6-test1 net]# service autofs start
Loading autofs4:
[ OK ]
Starting automount: [ OK ]
Now, check it again.
[root@rhel6-test1 net]# cd /net/rhel6-server
[root@rhel6-test1 rhel6-server]# ls -l
total 0
drwxr-xr-x. 2 root root 0 Jul 27 14:04 nfstest1
drwxr-xr-x. 2 root root 0 Jul 27 14:04 testnfs
[root@rhel6-test1 rhel6-server]# cd nfstest1
[root@rhel6-test1 nfstest1]# ls -ltr
total 0
-rw-r--r--. 1 root root 0 May 22 17:20 f1
-rw-rw-r--. 1 raman raman 0 May 22 18:23 f2
-rw-r--r--. 1 root root 0 May 23 18:33 f3
[root@rhel6-test1 nfstest1]# cd ../testnfs
[root@rhel6-test1 testnfs]# ls -l
total 8
-rw-r--r--. 1 nfsnobody nfsnobody
0 Apr 15 17:04 f2
-rw-rw-r--. 1 nfsnobody nfsnobody
0 Apr 15 16:55 r1
-rw-r--r--. 1 root
root 0 Apr 15 11:36 test1
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 15 16:54 testdir
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 15 17:01 testdir2
[root@rhel6-test1 testnfs]# touch testfile
[root@rhel6-test1 testnfs]# ls -l
total 8
-rw-r--r--. 1 nfsnobody nfsnobody
0 Apr 15 17:04 f2
-rw-rw-r--. 1 nfsnobody nfsnobody
0 Apr 15 16:55 r1
-rw-r--r--. 1 root root 0 Apr 15 11:36 test1
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 15 16:54 testdir
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 15 17:01 testdir2
-rw-r--r--. 1 nfsnobody nfsnobody
0 Jul 27 14:12 testfile
[root@rhel6-test1 testnfs]# cd
[root@rhel6-test1 ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 6.3G
8.5G 43% /
tmpfs 370M 76K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 85M 1.8G
5% /home
.host:/ 108G 99G
8.5G 93% /mnt/hgfs
/dev/sr0 3.5G 3.5G
0 100% /media/RHEL_6.4 x86_64 Disc 1
192.168.234.206:/nfstest1
16G 2.9G
12G 20%
/net/rhel6-server/nfstest1
192.168.234.205:/testnfs
16G 2.9G
12G 20% /net/rhel6-server/testnfs
Now, we can access all shared directories, shared at “rhel6-server”.
These directories are automatically mounted at “rhel6-test1”, just by
providing
/net/<hostname>. Now I am out of these directories but still it
is showing in o/p of “df –kh”.
Why…………??
There is idle timeout of 300 seconds/5M, after that it will be
automatically unmount.
[root@rhel6-test1 ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 6.3G
8.5G 43% /
tmpfs 370M 76K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 85M
1.8G 5% /home
.host:/ 108G 99G
8.5G 93% /mnt/hgfs
/dev/sr0 3.5G 3.5G
0 100% /media/RHEL_6.4 x86_64 Disc 1
DIRECT MAP:
Let’s create a new share at “rhel6-server”.
[root@rhel6-server ~]# mkdir /autofs-test
[root@rhel6-server ~]# vi /etc/exports
#/testnfs *(rw,sync)
#/nfstest1 *(rw,sync,no_root_squash,no_all_squash)
/autofs-test *(rw,sync)
[root@rhel6-server ~]# export all
[root@rhel6-server ~]# exportfs -v
/testnfs
<world>(rw,wdelay,root_squash,no_subtree_check)
/nfstest1
<world>(rw,wdelay,no_root_squash,no_subtree_check)
[root@rhel6-server ~]# exportfs
/nfstest1 <world>
/testnfs <world>
Still my new share is not showing,
[root@rhel6-server ~]# service nfs restart
[root@rhel6-server ~]# exportfs -v
/autofs-test
<world>(rw,wdelay,root_squash,no_subtree_check)
Now Good…
Let’s check this share at client server,
[root@rhel6-test1 ~]# showmount -e rhel6-server
Export list for rhel6-server:
/autofs-test *
Create a dir, on client to mount this shared dir.
AT AUTOMOUNT SERVER,
[root@rhel6-test1 ~]# mkdir /autofs-test-at_client
[root@rhel6-test1 ~]# chmod 777 /autofs-test-at_client
[root@rhel6-test1 ~]# mount -v rhel6-server:/autofs-test
/autofs-test-at_client
mount: no type was given - I'll assume nfs because of the colon
mount.nfs: timeout set for Thu Jul 27 15:33:16 2017
mount.nfs: trying text-based options
'vers=4,addr=192.168.234.146,clientaddr=192.168.234.200'
rhel6-server:/autofs-test on /autofs-test-at_client type nfs (rw)
[root@rhel6-test1 ~]# df -kh
Filesystem Size
Used Avail Use% Mounted on
/dev/sda3 16G 6.3G
8.5G 43% /
tmpfs 370M 72K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 85M
1.8G 5% /home
.host:/ 108G
99G 8.5G 93% /mnt/hgfs
rhel6-server:/autofs-test
16G 2.9G
12G 20% /autofs-test-at_client
Ok, now it is mounted. Let’s unmount it.
[root@rhel6-test1 ~]# umount /autofs-test-at_client
We have to do the same via “automount”.
Let’s start our “automount” configuration.
AT AUTOMOUNT CLIENT,
Here we are using “Direct Map” for the config,
[root@rhel6-test1 ~]# vi /etc/auto.master
/- /etc/auto.direct ç added
this line at end of file
[root@rhel6-test1 ~]# ls -l /etc/auto.direct
ls: cannot access /etc/auto.direct: No such file or directory
[root@rhel6-test1 ~]# vi /etc/auto.direct
/autofs-test-at_client
rhel6-server:/autofs-test ç added this entry
Here we can use, IP also instead of hostname.
[root@rhel6-test1 ~]# service autofs restart è Do
this at Client & Server
Stopping automount: [ OK ]
Starting automount: [ OK ]
[root@rhel6-test1 /]# service autofs reload è Do this at Client & Server
Reloading maps
[root@rhel6-test1 ~]# cd /autofs-test-at_client
[root@rhel6-test1 autofs-test-at_client]# ls -l
total 0
[root@rhel6-test1 autofs-test-at_client]# touch file1
[root@rhel6-test1 autofs-test-at_client]# ls -l
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Jul 27 16:23 file1
[root@rhel6-test1 autofs-test-at_client]# cd /
[root@rhel6-test1 /]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 6.3G
8.5G 43% /
tmpfs 370M
72K 370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 85M
1.8G 5% /home
.host:/ 108G 99G
8.5G 93% /mnt/hgfs
rhel6-server:/autofs-test
16G 2.9G
12G 20% /autofs-test-at_client
After 300S / 5M this will automatically unmount, we can control the
umount time by editing “TIMEOUT=300” value at /etc/sysconfig/autofs.
Continued……
Very good information on Auto-FS.
ReplyDeleteThanks to appreciate my work Dear, request to share if possible so that others can also be benefited
Delete