"yum install autofs" as needed, use your package manager of choice. Once you fire up the automount daemon, you can poke around in the configuration.
First thing you'll want to try with is in auto.master enabling the net (or nfs) -hosts line. This will create a multi-mount in /net where you can access shares via /net/<hostname>/<share path>.
That's really it. You can directly access files, for example in /net/homefs/data/home/username. Automount will automatically mount that share when it is accessed and remove it after it's been left idle.
What's it doing?
First, it will look up shares for you. When you do `ls /net/hostname`, it will return a list of shares available from the server "hostname". It's really that easy.
Any access to a share is automatically mounted. A shared folder, call it "work", will be mounted on the first user request for a file from that share. Whether that's someone using 'ls' or else writing a file to a specified path.
For convenience, my first tip is that you use symlinks to point to specific shares or locations. Rather than using the path "/net/workfs/export/work", do something like `ln -s /net/workfs/export/work $HOME/work`. Another example is for shared home directories, super common in UNIX environments. So link /home to /net/<server>/path/to/shared/home. It will bring up the shared home directories when a user tries to logon and will unmount the home share after the users are logged out.
This brings me to my next tip: the automatic timeout. Autofs will un-mount the share after an idle period. 10 minutes by default (depending on your platform). This may cause you some grief, for example if you have a job that runs every 10 minutes. You should adjust this timeout based on your needs (either up or down) but unless your running something on a schedule every 10 minutes, you probably won't have much of a problem with this default.
You can also tune your NFS settings in your auto.master config file. The defaults should work for most systems but if you do have to do NFS tuning, you can do this with autofs either for all NFS mounts or you can create specific mounts as needed.
The interesting thing with autofs is you don't have to use it just for network shares. You can use it for regular devices as well. One of the main things is that again, anything in automount will be mounted on demand and not at boot time. So if you have a large data volume, you can add it specifically to the auto.misc file instead of fstab.
From time to time autofs can get a bit mucked up. Usually when "you screw around too much". If stopping autofs and umounting any left-over shares doesn't work, remember "umount -f -l" which is force lazy unmount. Very useful. If the folders don't go away, like /net/server/path/to/share, try doing umount on them and then you can remove them (rm -Rf), just be careful. It depends whether rebooting is more risky than an rm -Rf.
Here's an off the wall question:
ReplyDeleteCan I mount a share from a host "out in the wild", and then share it again to my local network?
Re-share an NFS share as NFS again? No idea, that's pretty uncommon compared connecting all the other clients to the same share in the first place.
ReplyDeleteIn general though, it's all files so you can do whatever you want with them. Point your webserver, your Samba server, any other application at that path. Can't say I've tried putting /net/somehost/someshare in the NFS exports file.