Difference between revisions of "NFS"

From ArchWiki
Jump to: navigation, search
(Manual Mounting)
m (Editing language)
(41 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 
[[Category:Networking]]
 
[[Category:Networking]]
 +
[[de:Network File System]]
 
[[it:NFSv4]]
 
[[it:NFSv4]]
[[zh-CN:NFSv4]]
+
[[zh-CN:NFS]]
{{note|this article covers NFSv4, for the older version 3 see [[NFSv3]]}}
+
{{Article summary start}}
'''Network File System (NFS)''', is an open standard network file sharing protocol.
+
{{Article summary text|Article covers configuration of NFSv4 which is an open standard network file sharing protocol.}}
 +
{{Article summary heading|Related}}
 +
{{Article summary wiki|NFS_Troubleshooting}} - Dedicated article for common problems and solutions.
 +
{{Article summary wiki|NFSv3}} - Deprecated v3 format.
 +
{{Article summary end}}
  
 
==Installing==
 
==Installing==
Both client and server only require {{Pkg|nfs-utils}} from the [[official repositories]].
+
Both client and server only require the {{Pkg|nfs-utils}} package.
  
==Configuring==
+
{{Note|It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in syncWithout accurate clocks on all nodes, NFS can introduce unwanted delays!}}
===Time synchronization===
+
In order for NFS to function properly, both server and client must have closely matching time values.  If the clocks on the clients differ from the server too much, then basic functions like file copy operations may hang for a very long time leaving the system unusable until they resumeThe clocks do not have to match to micro/nano second accuracies, but ideally they should be within 1 second of each other. 
+
  
The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet. For a small system like a home network, the ntpdate utility may be used to sync both servers and clients to the same time.  For a larger installation, it may be desirable to install an OpenNTP server (see [[NTP]]) onto the same machine acting as the NFS server, and then all clients on the network would sync time values from the server.  This has the advantage of lowering the stress on the external NTP servers, and in assuring that the NFS clients will use the exact time that the NFS server has, even if the NFS server experiences some drift.
+
The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.  
 +
 
 +
==Configuring==
  
 
===Server===
 
===Server===
The server configuration involves the {{ic|/etc/idmapd.conf}} file and the {{ic|/etc/exports}} file to export shares shares.
+
==== ID mapping ====
 +
Edit {{ic|/etc/idmapd.conf}} and define a Domain.
  
====Server ID mapping====
+
Example:
{{ic|/etc/idmapd.conf}} needs to be edited. You'll need to at the very least specify your Domain there. Example:
+
 
  [General]
 
  [General]
 
   
 
   
 
  Verbosity = 1
 
  Verbosity = 1
 
  Pipefs-Directory = /var/lib/nfs/rpc_pipefs
 
  Pipefs-Directory = /var/lib/nfs/rpc_pipefs
  '''Domain = archlinux.org'''
+
  '''Domain = atomic'''
 
   
 
   
 
  [Mapping]
 
  [Mapping]
Line 30: Line 35:
 
  Nobody-Group = nobody
 
  Nobody-Group = nobody
  
====Exports====
+
==== File system ====
All the NFS shares are defined in {{ic|/etc/exports}}. See {{ic|man 5 exports}} for more information. A typical NFSv4 export would look like this:
+
{{Note|For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point onlyThe following example illustrates this concept.}}
/mnt      192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
+
  /mnt/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
+
  
{{Note|The {{ic|1=fsid=0}} is required for the root filesystem being exported. {{ic|/mnt}} is the NFS root here (due to the {{ic|1=fsid=0}} entry). Everything else that you want to be shared over NFS must be accessible under {{ic|/mnt}}. Setting an NFS root is required. For exporting directories outside the NFS root, see below.}}
+
Define any NFS shares in {{ic|/etc/exports}} which are relative to the NFS root. In this example, the NFS root will be {{ic|/srv/nfs4}} and we will be sharing {{ic|/mnt/music}}.
{{Note|The IP address or range of IP address defined is the client's IP. To allow ranges of addresses, the old-style 192.168.0.*-scheme is ''no longer'' supported with NFSv4. Use 192.168.0.0/24 or similar to specify such exports.}}
+
  
{{Note|The {{ic|no_root_squash}} option means that root on the client is also considered root on the server. This is of course a security risk. Remove it if you do not need it.}}
+
# mkdir -p /srv/nfs4/music
  
=====Exporting directories outside your NFS root=====
+
Read/Write permissions must be set on the music directory so clients may write to it.
To do this, you will need to use bind mounts. For example, to bind {{ic|/home/john}} to {{ic|/mnt/john}}:
+
# mount --bind /home/john /mnt/john
+
Then, {{ic|/mnt/john}} needs to be added to {{ic|/etc/exports}}:
+
/mnt      192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
+
/mnt/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
+
/mnt/john  192.168.0.12(rw,no_subtree_check,async,no_root_squash,'''nohide''')
+
The {{ic|nohide}} option is '''required''', because the kernel NFS server automatically hides mounted directories.
+
Add the bind mount to {{ic|/etc/fstab}} so that it sticks across boots of the server machine:
+
/home/john    /mnt/john    none    bind  0 0
+
  
====Starting the server====
+
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command:
To start the NFS server, just do:
+
# rc.d start rpcbind nfs-common nfs-server
+
  
To start the NFS server when you are using systemd, use:
+
  # mount --bind /mnt/music /srv/nfs4/music
  # systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service
+
  
If you want to tweak the configuration, feel free to edit {{ic|/etc/conf.d/nfs-server.conf}} to fit your needs.
+
To make it stick across server reboots, add the bind mount to {{ic|/etc/fstab}}:
 +
/mnt/music /srv/nfs4/music  none  bind  0  0
  
===Client===
+
==== Exports ====
The client configuration only involves the {{ic|/etc/idmapd.conf}} file. If your client also acts as a server for other machines on the network, then you will still have to configure the files covered in the server section.
+
Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in {{ic|/etc/exports}}:
 +
/srv/nfs4/ 192.168.0.1/24(rw,fsid=0,no_subtree_check)
 +
/srv/nfs4/music 192.168.0.1/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the filesystem
  
====Client ID mapping====
+
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.
{{ic|/etc/idmapd.conf}} needs to be edited on all clients. '''The Domain entry should be identical to the one on the server''' (see the ''Server ID mapping'' section). Example:
+
[General]
+
+
Verbosity = 1
+
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
+
'''Domain = archlinux.org'''
+
+
[Mapping]
+
+
Nobody-User = nobody
+
Nobody-Group = nobody
+
+
[Translation]
+
Method = nsswitch
+
  
{{note | On a client only setup make sure rpc.idmapd is running. The nfs-common daemon usually auto-detects whether rpc.idmapd has to be started, but it might fail if there aren't any nfs4 mount entries in {{ic|/etc/fstab}} or if {{ic|/etc/exports}} is empty (which both might be the case if you are using [[autofs]] to mount the nfs4 shares).
+
{{Note|The {{ic|1=fsid=0}} is required for the root file system being exported. {{ic|/srv/nfs4}} is the NFS root here (due to the {{ic|1=fsid=0}} entry). Everything else that you want to be shared over NFS must be accessible under {{ic|/srv/nfs4}}. Setting an NFS root is required. For exporting directories outside the NFS root, see below.}}
In this case set '''NEED_IDMAPD="yes"''' in {{ic|/etc/conf.d/nfs-common.conf}}. }}
+
For more information about all available options see {{ic|man 5 exports}}.
  
==Mounting NFS Shares on the client==
+
====Starting the server====
===Manual Mounting===
+
Make sure that nfs module is loaded on the client: {{ic|lsmod <nowiki>|</nowiki> grep nfs}}. If not, execute {{ic|modprobe nfs}}.
+
  
Show the server's exported filesystems:
+
To start the NFS server, use:
showmount -e server
+
  # systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service
Then just mount as normal:  
+
  # rc.d start rpcbind nfs-common
+
# mount -t nfs4 server:/ /mnt/server/
+
# mount -t nfs4 server:/music /mnt/music/
+
# mount -t nfs4 server:/john /mnt/john
+
Replacing 'server' with the hostname or IP address of your NFS server and of course 'server', 'music' and 'john' with the names of whatever directories you exported on the server.
+
{{note|The root of the path on the server is the NFS root specified; all paths must be specified relative to it.}}
+
  
===Auto Mounting===
+
===Client===
*With Initscripts: If you want to auto mount the NFS shares on boot, you will have to make sure that the network(or any other networking daemon that you use), rpcbind, nfs-common daemons are started up and also in that order. Do NOT background the daemons since the order in which they start up is important. Additionally you will also want to start netfs daemon which handles the clean unmount of NFS shares while shutting down the client machine. The netfs daemon can be backgrounded without any issues.
+
No special setup is required on the client-side when connecting to NFS 4 servers.
DAEMONS=(... network rpcbind nfs-common @netfs ...)
+
  
*With Systemd: [[Systemd#Remote_filesystem_mounts|Systemd/RemoteFilesystem page]] and make sure to enable rpc-idmapd.service for user id mapping.
+
For NFS 2 or 3 servers see [[NFSv3|the NFSv3 article]].
  
After you have added the daemons in {{ic|/etc/rc.conf}}, auto mounting of NFS shares can be handled in one of two ways:
+
==Mounting from Linux==
====Adding suitable entries in /etc/fstab====
+
Show the server's exported filesystems:
Using {{ic|/etc/[[fstab]]}} is useful when you have a server which is always on, and the NFS shares are available whenever your client boots up. Edit your {{ic|/etc/fstab}} file, and add an appropriate line in there reflecting your setup.
+
$ showmount -e servername
server:/ /mnt/nfsshare nfs4 defaults 0 0
+
{{note| where ''server'' is the server hostname or IP address}}
+
If you wish to specify a packet size for read and write packets, specify them in your {{ic|/etc/fstab}} entry. Read the NFS man page for further information, including all available mount options.
+
  
====Using [[autofs]]====
+
Then just mount as normal:
This option is useful when you have multiple machines that you want to connect via NFS and they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if one of the machine(server) is switched off, the client will not throw errors about being unable to find NFS shares. Please see the relevant section on the [[autofs#NFS_Network_mounts]] page for setting up NFS shares.
+
# mount -t nfs4 servername:/music /mountpoint/on/client
  
==Troubleshooting==
+
===Using fstab===
 +
Using [[fstab]] is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit {{ic|/etc/fstab}} file, and add an appropriate line reflecting the setup setup.
 +
Example:
 +
servername:/music  /mountpoint/on/client  nfs4  rsize=8192,wsize=8192,timeo=14,intr 0 0
  
===exportfs: /etc/exports:2: syntax error: bad option list===
+
{{Note|Additional mount options can be specified here. Consult the NFS man page for further information.}}
Delete all space from the option list in {{ic|/etc/exports}}
+
Some additional mount options to consider are include:
  
===mount.nfs4: No such device===
+
*rsize=8192 and wsize=8192
Check that you have loaded the {{ic|nfs}} module
+
*timeo=14
lsmod | grep nfs
+
*intr
and if previous returns empty or only nfsd-stuff, do
+
modprobe nfs
+
  
===mount.nfs4: access denied by server while mounting===
+
The rsize value is the number of bytes used when reading from the server. The wsize value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput.  This is not universal.  It is recommended to test after making this change.
Check that the permissions on your client's folder are correct. Try using 755.
+
  
=== Permissions issues ===
+
The timeo value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value.  
If you find that you cannot set the permissions on files properly, make sure the user/group you are chowning are on both the client and server.
+
If that does not help, try modifying these lines in {{ic|/etc/conf.d/nfs-common.conf}}
+
{{bc|<nowiki>
+
# /etc/conf.d/nfs-common.conf
+
  
# Do you want to start the statd daemon? It is not needed for NFSv4.
+
The intr option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.
NEED_STATD="no"
+
  
# Do you want to start the idmapd daemon? It is only needed for NFSv4.
+
===Using autofs===
NEED_IDMAPD="yes"
+
Using [[autofs]] is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See [[autofs#NFS Network mounts]] for details.
</nowiki>}}
+
Restart the nfs-common daemon for the changes to take effect.
+
I restarted all the other daemons as well, just to be sure.
+
  
=== Group/gid Permissions issues ===
+
== Mounting from Windows ==
If NFS shares mount fine, and are fully accessible to the owner, but not to group members; check the number of groups that user belongs to. NFS has a limit of 16 on the number of groups a user can belong to. If you have users with more then this, you need to enable the {{ic|--manage-gids}} start-up flag for {{ic|rpc.mountd}} on the NFS server.
+
{{Warning|Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}}
 
+
{{note|Only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"}}
/etc/conf.d/nfs-server.conf
+
+
# Options for rpc.mountd.
+
# If you have a port-based firewall, you might want to set up
+
# a fixed port here using the --port option.
+
# See rpc.mountd(8) for more details.
+
+
MOUNTD_OPTS="--manage-gids"
+
 
+
=== Mounting from Windows ===
+
{{note|only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"}}
+
 
NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default).
 
NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default).
 
To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").
 
To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").
Line 160: Line 107:
 
Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right clicking on the client->properties.  
 
Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right clicking on the client->properties.  
  
{{Warning|under Windows the share is addressed by it's full path on the server, not just the path relative to the nfsroot!! If in doubt run {{ic|showmount -e servername}} from cmd.exe}}
+
{{Warning|Under Windows the share is addressed by its full path on the server, not just the path relative to the nfsroot! If in doubt run {{ic|showmount -e servername}} from cmd.exe}}
 +
 
 +
== Mounting from OS X ==
 +
{{note|OS X by default uses an insecure (>1024) port to mount a share.}}
 +
Either export the share with the {{ic|insecure}} flag, and mount using Finder:
 +
: Go > Connect to Server > {{ic|nfs://servername/}}
 +
 
 +
Or, mount the share using a secure port using the terminal:
 +
# sudo mount -t nfs -o resvport servername:/ /Volumes/servername/
 +
 
 +
{{Warning|Under OS X the share is addressed by its full path on the server, not just the path relative to the nfsroot! If in doubt run {{ic|showmount -e servername}} from the terminal}}

Revision as of 10:47, 4 December 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki - Dedicated article for common problems and solutions. Template:Article summary wiki - Deprecated v3 format. Template:Article summary end

Installing

Both client and server only require the nfs-utils package.

Note: It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in sync. Without accurate clocks on all nodes, NFS can introduce unwanted delays!

The NTP system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.

Configuring

Server

ID mapping

Edit /etc/idmapd.conf and define a Domain.

Example:

[General]

Verbosity = 1
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = atomic

[Mapping]

Nobody-User = nobody
Nobody-Group = nobody

File system

Note: For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point only. The following example illustrates this concept.

Define any NFS shares in /etc/exports which are relative to the NFS root. In this example, the NFS root will be /srv/nfs4 and we will be sharing /mnt/music.

# mkdir -p /srv/nfs4/music

Read/Write permissions must be set on the music directory so clients may write to it.

Now mount the actual target share, /mnt/music to the NFS share via the mount command:

# mount --bind /mnt/music /srv/nfs4/music

To make it stick across server reboots, add the bind mount to /etc/fstab:

/mnt/music /srv/nfs4/music  none   bind   0   0

Exports

Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in /etc/exports:

/srv/nfs4/ 192.168.0.1/24(rw,fsid=0,no_subtree_check)
/srv/nfs4/music 192.168.0.1/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the filesystem

Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.

Note: The fsid=0 is required for the root file system being exported. /srv/nfs4 is the NFS root here (due to the fsid=0 entry). Everything else that you want to be shared over NFS must be accessible under /srv/nfs4. Setting an NFS root is required. For exporting directories outside the NFS root, see below.

For more information about all available options see man 5 exports.

Starting the server

To start the NFS server, use:

# systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service

Client

No special setup is required on the client-side when connecting to NFS 4 servers.

For NFS 2 or 3 servers see the NFSv3 article.

Mounting from Linux

Show the server's exported filesystems:

$ showmount -e servername

Then just mount as normal:

# mount -t nfs4 servername:/music /mountpoint/on/client

Using fstab

Using fstab is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit /etc/fstab file, and add an appropriate line reflecting the setup setup. Example:

servername:/music   /mountpoint/on/client   nfs4   rsize=8192,wsize=8192,timeo=14,intr	0 0
Note: Additional mount options can be specified here. Consult the NFS man page for further information.

Some additional mount options to consider are include:

  • rsize=8192 and wsize=8192
  • timeo=14
  • intr

The rsize value is the number of bytes used when reading from the server. The wsize value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput. This is not universal. It is recommended to test after making this change.

The timeo value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value.

The intr option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.

Using autofs

Using autofs is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See autofs#NFS Network mounts for details.

Mounting from Windows

Warning: Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[1]
Note: Only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"

NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default). To install the service go to "Programs and features" either through the control panel or by typing it in the search box from the start menu and click on "Turn Windows features on or off". Locate the "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").

Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right clicking on the client->properties.

Warning: Under Windows the share is addressed by its full path on the server, not just the path relative to the nfsroot! If in doubt run showmount -e servername from cmd.exe

Mounting from OS X

Note: OS X by default uses an insecure (>1024) port to mount a share.

Either export the share with the insecure flag, and mount using Finder:

Go > Connect to Server > nfs://servername/

Or, mount the share using a secure port using the terminal:

# sudo mount -t nfs -o resvport servername:/ /Volumes/servername/
Warning: Under OS X the share is addressed by its full path on the server, not just the path relative to the nfsroot! If in doubt run showmount -e servername from the terminal