Difference between revisions of "NFS (简体中文)"

From ArchWiki
Jump to: navigation, search
(Clients: Update translation)
Line 2: Line 2:
 
[[Category:简体中文]]
 
[[Category:简体中文]]
 
[[en:NFS]]
 
[[en:NFS]]
 +
 +
[[de:Network File System]]
 
[[it:NFSv4]]
 
[[it:NFSv4]]
 +
{{Article summary start}}
 +
{{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}}
 
{{translateme (简体中文)}}
 
{{translateme (简体中文)}}
=目标=
+
From [[Wikipedia: Network File System|Wikipedia]]: Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.
这篇文章的目标是让<span title="Network File System version 4" style="border-bottom:1px dotted">NFSv4</span> 运行在Arch Linux.上
+
<br>NFSv4 是 NFS 的一个新版本(对旧的NFSv3来说, see [[Nfs]]) with new features like strong authentication and integrity via Kerberos and SPKM-3, improved performance,  safe file caching, lock migration, UTF-8, ACLs and better support for Windows file sharing semantics.
+
  
=必须的软件包=
+
This article covers the installation of NFSv4.
服务器端和客户端都需要的软件包(from AUR):
+
==Installing==
# [https://aur.archlinux.org/packages.php?do_Details=1&ID=13630 librpcsecgss]
+
Both client and server only require the [[Pacman|installation]] of the {{Pkg|nfs-utils}} package.
# [https://aur.archlinux.org/packages.php?do_Details=1&ID=13625 nfs4-utils]
+
下载软件,编译和安装它们。
+
<br>'''Note: currently pacman doesn't seem to handle replacing when invoked with pacman -U.'''
+
'''Therefore, you'll need to remove nfs-utils before installing nfs4-utils''' (which is a complete drop-in replacement).
+
  
=配置=
+
{{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.
===Exports===
+
  
首先我们需要编辑文件 /etc/exports.
+
==Configuration==
一个典型的 NFSv4 export 应该象这样:
+
/export    192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
+
/export/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
+
  
/export 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 /export.
+
===Server===
<br>For exporting directories outside the NFS root, see below.
+
==== ID mapping ====
<br>'''Note: the 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 don't need it.'''
+
Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name.
<br><br>
+
====Exporting directories outside your NFS root====
+
To do this, you'll need to use bind mounts. For example, to bind /home/john to /export/john:
+
mount --bind /home/john /export/john
+
Then, /export/john needs to be added to /etc/exports:
+
/export    192.168.0.12(rw,fsid=0,no_subtree_check,async,no_root_squash)
+
/export/music 192.168.0.12(rw,no_subtree_check,async,no_root_squash)
+
/export/john 192.168.12(rw,no_subtree_check,async,no_root_squash,'''nohide''')
+
The nohide option is '''required''', because the kernel NFS server automatically hides mounted directories.  
+
To add the bind mount to /etc/fstab:
+
/home/john    /export/john    none    bind  0 0
+
  
===ID mapping===
+
{{hc|/etc/idmapd.conf|<nowiki>
 
+
[General]
Then, /etc/idmapd.conf needs to be edited. You'll need to at the very least specify your Domain there. Example:
+
[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]
+
 
Nobody-User = nobody
+
Nobody-User = nobody
Nobody-Group = nobody
+
Nobody-Group = nobody
 +
</nowiki>}}
 +
==== 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 {{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}}.
 +
 
 +
{{bc|# 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, {{ic|/mnt/music}} to the NFS share via the mount command:
 +
 
 +
{{bc|# mount --bind /mnt/music /srv/nfs4/music}}
 +
 
 +
To make it stick across server reboots, add the bind mount to {{ic|fstab}}:
 +
{{hc|/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 {{ic|exports}}:
 +
{{hc|/etc/exports|<nowiki>
 +
/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 file system.
 +
</nowiki>}}
 +
 
 +
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.
 +
 
 +
See {{ic|man exports}} for detailed settings information.
 +
 
 +
{{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.}}
 +
For more information about all available options see {{ic|man 5 exports}}.
 +
 
 +
If you modify {{ic|/etc/exports}} while the server is running, you must reexport them for changes to take effect:
 +
{{bc|# exportfs -ra}}
 +
 
 +
====Starting the server====
 +
 
 +
The services for the NFS server are {{ic|rpc-idmapd.service}} and {{ic|rpc-mountd.service}}.
 +
 
 +
Start them and configure them to start at boot. Read [[Daemons]] for more details.
 +
 
 +
Note that these units require others, which are launched automatically by [[systemd]].
 +
 
 +
===Client===
 +
Clients need {{Pkg|nfs-utils}} to connect, but no special setup is required when connecting to NFS 4 servers.
 +
 
 +
====Mounting from Linux====
 +
Show the server's exported filesystems:
 +
{{bc|$ showmount -e servername}}
 +
 
 +
Then just mount as normal:
 +
{{bc|# mount -t nfs4 servername:/music /mountpoint/on/client}}
 +
 
 +
=====/etc/fstab Settings=====
 +
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.
 +
{{hc|/etc/fstab|<nowiki>
 +
servername:/music  /mountpoint/on/client  nfs4  rsize=8192,wsize=8192,timeo=14,intr 0 0
 +
</nowiki>}}
 +
 
 +
{{Note|Additional mount options can be specified here. Consult the NFS man page for further information.}}
 +
Some additional mount options to consider are include:
 +
 
 +
* {{ic|1=rsize=8192}} and {{ic|1=wsize=8192}}
 +
* {{ic|1=timeo=14}}
 +
* {{ic|1=intr}}
 +
 
 +
The {{ic|rsize}} value is the number of bytes used when reading from the server. The {{ic|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 {{ic|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 {{ic|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.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}}
 +
{{note|Only the Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 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 {{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:
  
===Filesystems===
+
{{ic|Go}} > {{ic|Connect to Server}} > {{ic|nfs://servername/}}
Add the following lines to /etc/fstab:
+
rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0
+
nfsd /proc/fs/nfsd nfsd rw,nodev,noexec,nosuid 0 0
+
  
===Starting the server===
+
Or, mount the share using a secure port using the terminal:
 +
{{bc|# sudo mount -t nfs -o resvport servername:/ /Volumes/servername/}}
  
To start the NFS server, just
+
{{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}}
/etc/rc.d/portmap start
+
/etc/rc.d/nfs-common start
+
/etc/rc.d/nfs-server start
+
If you want to tweak the configuration, feel free to edit /etc/conf.d/nfs-server.conf to your needs.
+
  
==Clients==
+
== Troubleshooting ==
客户端无需特别设置。
+
''There is a dedicated article [[NFS Troubleshooting]].''

Revision as of 06:56, 17 January 2013

Summary help replacing me
Article covers configuration of NFSv4 which is an open standard network file sharing protocol.
Related
NFS Troubleshooting - Dedicated article for common problems and solutions.
NFSv3 - Deprecated v3 format.

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

From Wikipedia: Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.

This article covers the installation of NFSv4.

Installing

Both client and server only require the installation of 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.

Configuration

Server

ID mapping

Edit /etc/idmapd.conf and set the Domain field to your domain name.

/etc/idmapd.conf
[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 fstab:

/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 exports:

/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 file system.

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

See man exports for detailed settings information.

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.

If you modify /etc/exports while the server is running, you must reexport them for changes to take effect:

# exportfs -ra

Starting the server

The services for the NFS server are rpc-idmapd.service and rpc-mountd.service.

Start them and configure them to start at boot. Read Daemons for more details.

Note that these units require others, which are launched automatically by systemd.

Client

Clients need nfs-utils to connect, but no special setup is required when connecting to NFS 4 servers.

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
/etc/fstab Settings

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.

/etc/fstab
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 Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 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

Troubleshooting

There is a dedicated article NFS Troubleshooting.