This is a simple and small guide on how to set up an Automount mapping and feature on RHEL 6.x. It basically covers:
- Installing autofs
- Configuring autofs to target the NFS defined mount point
- Utilizing the defined mount point
- Installing NFS
- Configuring NFS
- Defining a mount point
- Automount
- NFS
Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984,[1] allowing a user on a client computer to access files over a computer network much like local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The NFS is an open standard defined in Request for Comments (RFC), allowing anyone to implement the protocol.
Read more on Wikipedia.
An automounter is any program or software facility which automatically mounts filesystems in response to access operations by user programs. An automounter system utility (daemon under Unix), when notified of file and directory access attempts under selectively monitored subdirectory trees, dynamically and transparently makes local or remote devices accessible.
Read more on Wikipedia.
This example definition will use a defined user called mycooluser. Create the user on the targeted host:
sudo useradd -b /export/home -c "Mimics random cool user" -m -U mycooluser
When this is done, create the following folder structure as well in order to properly share a folder:
sudo mkdir /usr/cool
sudo mkdir /usr/cool/users
cd /usr
sudo chown -R mycooluser:mycooluser cool
ls -la
# ensure correct ownership
In order to enable sharing a specific folder, some kind of software must be installed locally on the server, and this is typically some NFS based utilities.
yum install nfs-utils nfs-utils-lib
After this is done, just start the service:
sudo service nfs start
sudo chkconfig --level 35 nfs on
Now the service related to the NFS stuff should be started and running. Next up is to actually configure NFS to share the folder(s) that should be marked for sharing. Edit the file named /etc/exports and insert something similar to this configuration:
sudo vi /etc/exports
/usr/cool/users *(rw,sync,no_root_squash)
/usr/cool/users 10.10.10.16(rw,sync,no_root_squash)
# see man for export for more features (rw = readwrite, ro = readonly, sync = duh..)
After this is done, just restart the NFS server:
sudo service nfs restart
Remove the configuration that is defined in the hosts.deny file for mountd. Perform the following:
sudo vi /etc/hosts.deny
# (remove mountd blockades)
Remove the configuration that is defined in the hosts.allow file for mountd. Perform the following:
sudo vi /etc/hosts.allow
# (remove mountd blockades OR mountd: 10.10.10./255.0.0.0)
Note: You can actually also allow the IPs that should be able to connect to the service itself (mountd). See above for example.
You are now ready to accept requests from a client - wihu! :-)
If you do not have autofs installed, run the following stuff below:
sudo yum install autofs
Run the following command in order to verify that some mounts is exposed/exported (through the use of e.g NFS):
sudo showmount -e 10.10.10.26
# Export list for 10.10.10.26:
# /usr/cool/users 10.10.10.16
This is quite simple and includes changing the file called auto.master. Perform the following:
sudo vi /etc/auto.master
# MOUNTPATH CONFIGURATION PARAMETERS
/cooltransfer /etc/auto.fs-cool --timeout 60
Now, copy the existing file "auto.misc"-file (you're just as lazy as me, so just do it :-)) and modify the contents to conform with the remote server / fileshare
sudo cp /etc/auto.misc /etc/auto.fs-cool
sudo vi /etc/auto.fs-cool
# add the following stuff the last line
user -fstype=nfs 10.10.10.26:/usr/cool/users
Now restart automount/autofs to reflect the mounting configuration. Issue the following commands:
sudo service autofs stop
sudo service autofs start
Execute the following commands to verify that the mountpoint is properly defined:
ls -la /cooltransfer
# should output (nothing)
ls -la /cooltransfer/user
# should output whatever is defined in the mapped NFS directory (here: /usr/cool/users)
You can even change the ownership to the (other) local user on the directory that contains the NFS. Perform the following:
cd /cooltransfer/user
sudo mkdir whatever
sudo chown 501:504 whatever
CONGRATS! All should be working! :-) Unless..you've effed up. Then, try again :-P.
This indicates that something is wrong with your permissions. It can be any of the following configurations:
- /etc/hosts.allow
- marked for depricatation. use firewall stuff instead (https://linux.die.net/man/5/hosts.allow)
- /etc/hosts.deny
- marked for depricatation. use firewall stuff instead (https://linux.die.net/man/5/hosts.deny)
- /etc/exports
Verify the following:
- hosts can contain ALL - verify that this should be the case
- exports may contain either wrong dns-entry/alias or wrong ip/sub - verify this :-)