AutoFS on CENTOS 7

Posted: July 19, 2015 in Linux

This is extension of my prevoius article.In this one we will configure client computer  (192.168.122.80) to automount folder located on remote computer (192.168.122.90)

AutoFS service is alternative to /etc/fstab mount points.Unlike /etc/fstab method, AutoFS mounts filesystem when user access it and unmount them after a period of inactivity.

On server side (192.168.122.90) we installed nfs-util package.

We will create folder which will be accessible to remote system

mkdir /myfolder

Add this folder to /etc/export file:

/sharenfs 192.168.122.200(rw,no_root_squash,no_all_squash)

/sharenfs 192.168.122.100(rw,no_root_squash,no_all_squash,insecure)

/myfolder 192.168.122.80(rw)

/myfolder is exported to 192.168.122.80 as read-write

Export the entries defined in the /etc/exports file and pass them to to rpc.mountd (if NFSv2 or NFSv3) for the  mounting process, then to rpc.nfsd where the file systems are made available to remote users.

exportfs -avr

exportfs command  writes filesystems to  /var/lib/nfs/etab file

[root@squid myfolder]# cat /var/lib/nfs/etab
/myfolder 192.168.122.80(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)
/sharenfs 192.168.122.200(rw,sync,wdelay,hide,nocrossmnt,secure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,secure,no_root_squash,no_all_squash)
/sharenfs 192.168.122.100(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,insecure,no_root_squash,no_all_squash)

Restart nfs service (firewall port was opened in previous article)

Client configuration:

On client (192.168.122.80) install autofs package

yum install autofs -y

By default,autofs configuration file is empty,add followowing entries to /etc/sysconfig/autofs file:

# Init syatem options
#
# If the kernel supports using the autofs miscellanous device
# and you wish to use it you must set this configuration option
# to "yes" otherwise it will not be used.
#
USE_MISC_DEVICE="yes"
#
# Use OPTIONS to add automount(8) command line options that
# will be used when the daemon is started.
#
OPTIONS=""
#

MASTER_MAP_NAME="auto.master"  #defines default primary configuration file
TIMEOUT=300 #the maximum idle time (in seconds) after which filesystem is unmounted
NEGATIVE_TIMEOUT=60 #negative timeout for failed mount attempts (default 60)
LOGGING="verbose" #enable logging (read logs to /var/log/messages 
MOUNT_NFS_DEFAULT_PROTOCOL=4 #default protocol used by mount.nfs
BROWSE_MODE="yes" #set to yes by default. Set it to NO and autofs only creates mount points when something is actually mounted on them

Remote shares must be configured in /etc/auto.master  file

# Sample auto.master file
# This is a ‘master’ automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/- /etc/auto.direct  #add this line to tell autofs service where to look up for mounting entries
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# “nosuid” and “nodev” options unless the “suid” and “dev”
# options are explicitly given.
#
/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
#+auto.master #comment this line for NFS shares or you’ll get “unable to read auto.master file”

Create directory named /folder on client.Create /etc/auto.direct file to define our share from 192.168.122.90

/folder -fstype=nfs,rw 192.168.122.90:/myfolder

In local directory (/folder) will be mounted folder from remote machine (192.168.122.90:/myfolder) as read write (rw) as nfs file system

Start autofs service and check if mount was successful:

systemctl start autofs;mount | grep "folder"
/etc/auto.direct on /folder type autofs (rw,relatime,fd=7,pgrp=4064,timeout=300,minproto=5,maxproto=5,direct)
192.168.122.90:/myfolder on /folder type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.80,local_lock=none,addr=192.168.122.90)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s