https://wiki.archlinux.org/api.php?action=feedcontributions&user=Badook&feedformat=atomArchWiki - User contributions [en]2024-03-28T23:38:42ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=NFS&diff=229936NFS2012-10-20T10:25:12Z<p>Badook: /* Exports */</p>
<hr />
<div>[[Category:Networking]]<br />
[[it:NFSv4]]<br />
[[zh-CN:NFS]]<br />
{{Article summary start}}<br />
{{Article summary text|Article covers configuration of NFSv4 which is an open standard network file sharing protocol.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|NFSv3}} - Depreciated v3 format.<br />
{{Article summary end}}<br />
<br />
==Installing==<br />
Both client and server only require the {{Pkg|nfs-utils}} package.<br />
<br />
{{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!}}<br />
<br />
The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet. <br />
<br />
==Configuring==<br />
<br />
===Server===<br />
==== ID Mapping ====<br />
Edit {{ic|/etc/idmapd.conf}} and define a Domain.<br />
<br />
Example:<br />
[General]<br />
<br />
Verbosity = 1<br />
Pipefs-Directory = /var/lib/nfs/rpc_pipefs<br />
'''Domain = atomic'''<br />
<br />
[Mapping]<br />
<br />
Nobody-User = nobody<br />
Nobody-Group = nobody<br />
<br />
==== Filesystem ====<br />
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.<br />
<br />
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}}.<br />
<br />
# mkdir -p /srv/nfs4/music<br />
<br />
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command:<br />
<br />
# mount --bind /mnt/music /srv/nfs4/music<br />
<br />
To make it stick across server reboots, add the bind mount to {{ic|/etc/fstab}}:<br />
/mnt/music /srv/nfs4/music none bind 0 0<br />
<br />
==== Exports ====<br />
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}}:<br />
/srv/nfs4/ 192.168.0.0/24(rw,fsid=0,no_subtree_check)<br />
/srv/nfs4/music 192.168.0.0/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the filesystem<br />
<br />
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.<br />
<br />
{{Note|The {{ic|1=fsid=0}} is required for the root filesystem 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.}}<br />
For more information about all available options see {{ic|man 5 exports}}.<br />
<br />
====Starting the Server====<br />
<br />
To start the NFS server, use:<br />
# systemctl start nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service<br />
<br />
===Client===<br />
The client configuration only involves the {{ic|/etc/idmapd.conf}} file.<br />
<br />
==== ID Mapping====<br />
Edit {{ic|/etc/idmapd.conf}} and define the same Domain specified in the server's config:<br />
<br />
Example:<br />
[General]<br />
<br />
Verbosity = 1<br />
Pipefs-Directory = /var/lib/nfs/rpc_pipefs<br />
'''Domain = atomic'''<br />
<br />
[Mapping]<br />
<br />
Nobody-User = nobody<br />
Nobody-Group = nobody<br />
<br />
[Translation]<br />
Method = nsswitch<br />
<br />
====Starting the client====<br />
To start the NFS client:<br />
# systemctl start nfsd.service rpc-idmapd.service<br />
<br />
====Mounting NFS shares on the client====<br />
Show the server's exported filesystems:<br />
showmount -e servername<br />
<br />
Then just mount as normal: <br />
# mount -t nfs4 servername:/music /mountpoint/on/client<br />
<br />
====Auto mounting====<br />
Consult the [[Systemd#Remote_filesystem_mounts|Systemd/RemoteFilesystem page]] and make sure to enable rpc-idmapd.service for user id mapping.<br />
<br />
After adding the daemons, auto mounting of NFS shares can be handled in one of two ways:<br />
=====Using fstab=====<br />
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.<br />
Example:<br />
servername:/music /mountpoint/on/client nfs4 defaults 0 0<br />
<br />
{{Note|Additional mount options can be specified here. Consult the NFS man page for further information.}}<br />
<br />
=====Using autofs=====<br />
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.<br />
<br />
== Mounting from Windows ==<br />
{{note|only the Enterprise and Ultimate versions of Windows 7 include "Client for NFS"}}<br />
NFS shares can be mounted from windows if the "Client for NFS" service is actived (which it is not by default).<br />
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").<br />
<br />
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. <br />
<br />
{{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}}<br />
<br />
== Mounting from OS X ==<br />
{{note|OS X by default uses a insecure (>1024) port to mount a share.}}<br />
Either export the share with the {{ic|insecure}} flag, and mount using Finder:<br />
: Go > Connect to Server > {{ic|nfs://server/}}<br />
<br />
Or, mount the share using a secure port using the terminal:<br />
# sudo mount -t nfs -o resvport server:/ /Volumes/server/<br />
<br />
==Troubleshooting==<br />
===exportfs: /etc/exports:2: syntax error: bad option list===<br />
Delete all space from the option list in {{ic|/etc/exports}}<br />
<br />
===mount.nfs4: No such device===<br />
Check that you have loaded the {{ic|nfs}} module<br />
lsmod | grep nfs<br />
and if previous returns empty or only nfsd-stuff, do<br />
modprobe nfs<br />
<br />
===mount.nfs4: access denied by server while mounting===<br />
Check that the permissions on your client's folder are correct. Try using 755.<br />
<br />
=== permissions issues ===<br />
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.<br />
If that does not help, try modifying these lines in {{ic|/etc/conf.d/nfs-common.conf}}<br />
{{bc|<nowiki><br />
# /etc/conf.d/nfs-common.conf<br />
<br />
# Do you want to start the statd daemon? It is not needed for NFSv4.<br />
NEED_STATD="no"<br />
<br />
# Do you want to start the idmapd daemon? It is only needed for NFSv4.<br />
NEED_IDMAPD="yes"<br />
</nowiki>}}<br />
Restart the nfs-common daemon for the changes to take effect.<br />
I restarted all the other daemons as well, just to be sure.<br />
<br />
=== group/gid permissions issues ===<br />
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.<br />
<br />
/etc/conf.d/nfs-server.conf<br />
<br />
# Options for rpc.mountd.<br />
# If you have a port-based firewall, you might want to set up<br />
# a fixed port here using the --port option.<br />
# See rpc.mountd(8) for more details.<br />
<br />
MOUNTD_OPTS="--manage-gids"<br />
<br />
=== lock problems ===<br />
If you got error such as this:<br />
mount.nfs: rpc.statd is not running but is required for remote locking.<br />
mount.nfs: Either use '-o nolock' to keep locks local, or start statd.<br />
mount.nfs: an incorrect mount option was specified<br />
<br />
To fix this, you need to change the "NEED_STATD" value in:<br />
<br />
/etc/conf.d/nfs-common.conf<br />
<br />
NEED_STATD="no"<br />
<br />
Remember to start all the services - ''nfsd.service rpc-idmapd.service rpc-mountd.service rpcbind.service'', not just the nfsd.</div>Badook