特殊:Badtitle/NS100:Autofs
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Autofs }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/af | • {{#if: UbuntuHelp:Autofs|Afrikaans| [[::Autofs/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ar | • {{#if: UbuntuHelp:Autofs|العربية| [[::Autofs/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/az | • {{#if: UbuntuHelp:Autofs|azərbaycanca| [[::Autofs/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/bcc | • {{#if: UbuntuHelp:Autofs|جهلسری بلوچی| [[::Autofs/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/bg | • {{#if: UbuntuHelp:Autofs|български| [[::Autofs/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/br | • {{#if: UbuntuHelp:Autofs|brezhoneg| [[::Autofs/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ca | • {{#if: UbuntuHelp:Autofs|català| [[::Autofs/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/cs | • {{#if: UbuntuHelp:Autofs|čeština| [[::Autofs/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/de | • {{#if: UbuntuHelp:Autofs|Deutsch| [[::Autofs/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/el | • {{#if: UbuntuHelp:Autofs|Ελληνικά| [[::Autofs/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/es | • {{#if: UbuntuHelp:Autofs|español| [[::Autofs/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/fa | • {{#if: UbuntuHelp:Autofs|فارسی| [[::Autofs/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/fi | • {{#if: UbuntuHelp:Autofs|suomi| [[::Autofs/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/fr | • {{#if: UbuntuHelp:Autofs|français| [[::Autofs/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/gu | • {{#if: UbuntuHelp:Autofs|ગુજરાતી| [[::Autofs/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/he | • {{#if: UbuntuHelp:Autofs|עברית| [[::Autofs/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/hu | • {{#if: UbuntuHelp:Autofs|magyar| [[::Autofs/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/id | • {{#if: UbuntuHelp:Autofs|Bahasa Indonesia| [[::Autofs/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/it | • {{#if: UbuntuHelp:Autofs|italiano| [[::Autofs/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ja | • {{#if: UbuntuHelp:Autofs|日本語| [[::Autofs/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ko | • {{#if: UbuntuHelp:Autofs|한국어| [[::Autofs/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ksh | • {{#if: UbuntuHelp:Autofs|Ripoarisch| [[::Autofs/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/mr | • {{#if: UbuntuHelp:Autofs|मराठी| [[::Autofs/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ms | • {{#if: UbuntuHelp:Autofs|Bahasa Melayu| [[::Autofs/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/nl | • {{#if: UbuntuHelp:Autofs|Nederlands| [[::Autofs/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/no | • {{#if: UbuntuHelp:Autofs|norsk| [[::Autofs/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/oc | • {{#if: UbuntuHelp:Autofs|occitan| [[::Autofs/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/pl | • {{#if: UbuntuHelp:Autofs|polski| [[::Autofs/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/pt | • {{#if: UbuntuHelp:Autofs|português| [[::Autofs/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ro | • {{#if: UbuntuHelp:Autofs|română| [[::Autofs/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/ru | • {{#if: UbuntuHelp:Autofs|русский| [[::Autofs/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/si | • {{#if: UbuntuHelp:Autofs|සිංහල| [[::Autofs/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/sq | • {{#if: UbuntuHelp:Autofs|shqip| [[::Autofs/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/sr | • {{#if: UbuntuHelp:Autofs|српски / srpski| [[::Autofs/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/sv | • {{#if: UbuntuHelp:Autofs|svenska| [[::Autofs/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/th | • {{#if: UbuntuHelp:Autofs|ไทย| [[::Autofs/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/tr | • {{#if: UbuntuHelp:Autofs|Türkçe| [[::Autofs/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/vi | • {{#if: UbuntuHelp:Autofs|Tiếng Việt| [[::Autofs/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/yue | • {{#if: UbuntuHelp:Autofs|粵語| [[::Autofs/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/zh | • {{#if: UbuntuHelp:Autofs|中文| [[::Autofs/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/zh-hans | • {{#if: UbuntuHelp:Autofs|中文(简体)| [[::Autofs/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Autofs | UbuntuHelp:Autofs | {{#if: | :}}Autofs}}/zh-hant | • {{#if: UbuntuHelp:Autofs|中文(繁體)| [[::Autofs/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Autofs|:Autofs|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Autofs/zh | | {{#ifexist: Autofs/zh | | {{#ifeq: {{#titleparts:Autofs|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Autofs|1|-1|}} | zh | | }}
Introduction
Automount (or autofs) is a way to mount directories on an as-needed basis. Automounts are mounted only as they are accessed, and they are unmounted after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab
.
In this howto, we will configure autofs to automount an NFS share, using a set of config files. There are other ways to configure autofs on a network (see AutofsLDAP), but config files provide the simplest setup.
This howto assumes that you are already familiar with NFS exports, and that you already have a properly-functioning NFS share on your network. See NFSServerHowTo to learn how to set up such a server.
Quick note on terms
Put simply, automount and autofs are two separate technologies working in tandem to provide automatic filesystem mounting. However, for our purposes there is little need to distinguish between the two, and as such, they are used interchangeably in this howto.
Installation
Install the autofs package:
$ sudo apt-get install autofs
Configuration
Edit /etc/auto.master
To configure autofs we will edit /etc/auto.master
.
$ sudo nano /etc/auto.master
Here is the sample file provided by Ubuntu:
# # $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $ # # Sample auto.master file # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # For details of the format look at autofs(5). #/misc /etc/auto.misc --timeout=60 #/smb /etc/auto.smb #/misc /etc/auto.misc #/net /etc/auto.net
As you can see, everything is commented out. Take note of the format used by the examples. Each mount point is associated with another configuration file. We will create a new configuration file for our NFS share(s).
Add the following line at the end of /etc/auto.master
:
/nfs /etc/auto.nfs
This creates a mount point at /nfs
and configures it according to the settings specified in /etc/auto.nfs
(which we are about to create).
Create /etc/auto.nfs
Now we will create the file which countains our automounter map:
$ sudo nano /etc/auto.nfs
This file should contain a separate line for each NFS share. The format for a line is {mount point} [{mount options}] {location}. If you have previously configured static mounts in /etc/fstab
, it may be helpful to refer to those. Remember, the mount points specified here will be relative to the mount point given in /etc/auto.master
.
The following line is for shares using older versions of NFS (prior to version 4):
server server:/
This creates a new mount point at /nfs/server/
and mounts the NFS root directory exported by the machine whose hostname is server
.
NFSv4
If your NFS shares use NFSv4, you need to tell autofs about that. In such a case, the above line would appear as follows:
server -fstype=nfs4 server:/
Unmount static mounts and edit /etc/fstab
If you have previously configured the NFS shares as static mounts, now is the time to unmount them.
$ sudo umount /server
Next, remove (or comment out) their respective entries in /etc/fstab
.
#server:/ /server/ nfs defaults 0 0
Reload /etc/init.d/autofs
After entering your changes, run the following command to reload autofs:
$ sudo /etc/init.d/autofs reload
Make sure it works
In order to access the share and verify that it is working properly, enter the following into a shell:
$ ls /nfs/server
If you see your NFS share listed, congratulations! You have a functioning NFS mount via autofs! If you want to learn some more advanced information, keep reading.
Advanced Information
Following the example directory structure above, if you were to enter ls /nfs
into a shell, you might be surprised to see nothing listed. But remember that you need to access a directory before it is automounted. To access the share, enter ls /nfs/server
. Once it has been accessed, your share will be listed only until it times out. This is good to keep in mind, as it could save you time diagnosing an autofs problem that isn't really there.
Note on /net and /smb
These two default configurations may be useful for your setup. If you have a lot of NFS or Samba shares, you may want to uncomment these lines. /net
enables automounting of file systems elsewhere on the network which are exported by NFS. For example, if you have a server named fileserver
with an NFS export directory called /export
, you can mount it by typing in a shell command line cd /net/fileserver/export
. In an environment with NFS file servers, such a configuration can be useful. /smb
functions the same way but is for Samba file systems. However, if you need to authenticate before accessing the Samba share, automount will not function.
Wildcard characters
Let's say you have a directory with a number of subdirectories which you want to have automounted individually. An example of this is the /home
directory, in which case /etc/auto.master
might contain the following line:
/home /etc/auto.home
If user1 is logged in, you will want to automount his home directory. However, if you create a mount point for the whole /home
directory, you will also mount the home directories of every other user at the same time, thus wasting bandwidth. One solution to this would be to create separate entries for each directory, as follows:
# /etc/auto.home user1 server:/home/user1 user2 server:/home/user2 user3 server:/home/user3
This works, but is cumbersome. Instead, you can use wildcard characters, as follows:
* server:/home/&
The asterisk (*) is used in place of the mount point and the ampersand (&) in place of the directory to be mounted. For more detail on the use of wildcards see Using Wildcard Characters as Shortcuts in AutoFS Maps.