Open lihongjie0209 opened 3 years ago
The mount
command mounts NFS shares on the client side. Its format is as follows:
# mount -t nfs -o _options_ _server_:_/remote/export_ _/local/directory_
This command uses the following variables: options A comma-delimited list of mount options; for more information on valid NFS mount options, see Section 8.4, “Common NFS Mount Options”.
The hostname, IP address, or fully qualified domain name of the server exporting the file system you wish to mount
The file system or directory being exported from the server, that is, the directory you wish to mount /### local/directory The client location where /remote/export is mounted
The NFS protocol version used in Red Hat Enterprise Linux 7 is identified by the mount options nfsvers or vers. By default, mount uses NFSv4 with mount -t nfs. If the server does not support NFSv4, the client automatically steps down to a version supported by the server. If the nfsvers/vers option is used to pass a particular version not supported by the server, the mount fails. The file system type nfs4 is also available for legacy reasons; this is equivalent to running mount -t nfs -o nfsvers=4 host:/remote/export /local/directory
.
An alternate way to mount an NFS share from another machine is to add a line to the /etc/fstab file. The line must state the hostname of the NFS server, the directory on the server being exported, and the directory on the local machine where the NFS share is to be mounted. You must be root to modify the /etc/fstab file. Example 8.1. Syntax Example
The general syntax for the line in /etc/fstab is as follows:
server:/usr/local/pub /pub nfs defaults 0 0
The mount point /pub must exist on the client machine before this command can be executed. After adding this line to /etc/fstab on the client system, use the command mount /pub, and the mount point /pub is mounted from the server. A valid /etc/fstab entry to mount an NFS export should contain the following information:
server:/remote/export /local/directory nfs options 0 0
rpcbind
[1] service must be running. To verify that rpcbind
is active, use the following command:
$
systemctl status rpcbind
rpcbind
, see Section 8.6.7, “Configuring an NFSv4-only Server”.
nfs-lock
service:
#
systemctl start nfs-lock
#
systemctl enable nfs-lock
nfs-lock
starts automatically if needed, and an attempt to enable it manually fails.
# systemctl start nfs
# systemctl enable nfs
# systemctl stop nfs
restart
option is a shorthand way of stopping and then starting NFS. This is the most efficient way to make configuration changes take effect after editing the configuration file for NFS. To restart the server type:
# systemctl restart nfs
/etc/sysconfig/nfs
file, restart the nfs-config service by running the following command for the new values to take effect:
# systemctl restart nfs-config
try-restart
command only starts nfs
if it is currently running. This command is the equivalent of condrestart
(conditional restart) in Red Hat init scripts and is useful because it does not start the daemon if NFS is not running.
# systemctl try-restart nfs
# systemctl reload nfs
/etc/exports
, and
exportfs
/etc/exports
Configuration File/etc/exports
file controls which file systems are exported to remote hosts and specifies options. It follows the following syntax rules:
#
).
\
).
export host(options)
export host1(options1) host2(options2) host3(options3)
/etc/exports
file only specifies the exported directory and the hosts permitted to access it, as in the following example:
Example 8.6. The /etc/exports
File
/exported/directory bob.example.com
bob.example.com
can mount /exported/directory/
from the NFS server. Because no options are specified in this example, NFS uses default settings.
rw
option.
async
.
no_wdelay
. no_wdelay
is only available if the default sync
option is also specified.
nfsnobody
. This effectively "squashes" the power of the remote root user to the lowest local user, preventing possible unauthorized writes on the remote server. To disable root squashing, specify no_root_squash
.
all_squash
. To specify the user and group IDs that the NFS server should assign to remote users from a particular host, use the anonuid
and anongid
options, respectively, as in:
export host(anonuid=uid,anongid=gid)
anonuid
and anongid
options allow you to create a special user and group account for remote NFS users to share.
no_acl
option when exporting the file system.
rw
option is not specified, then the exported file system is shared as read-only. The following is a sample line from /etc/exports
which overrides two default options:
/another/exported/directory 192.168.0.3(rw,async)
192.168.0.3
can mount /another/exported/directory/
read and write and all writes to disk are asynchronous. For more information on exporting options, see man exportfs
.
man exports
.
Important
/etc/exports
file is very precise, particularly in regards to use of the space character. Remember to always separate exported file systems from hosts and hosts from one another with a space character. However, there should be no other space characters in the file except on comment lines.
/home bob.example.com(rw) /home bob.example.com (rw)
bob.example.com
read and write access to the /home
directory. The second line allows users from bob.example.com
to mount the directory as read-only (the default), while the rest of the world can mount it read/write.
exportfs
Command/etc/exports
file. When the nfs
service starts, the /usr/sbin/exportfs
command launches and reads this file, passes control to rpc.mountd
(if NFSv3) for the actual mounting process, then to rpc.nfsd
where the file systems are then available to remote users.
/usr/sbin/exportfs
command allows the root user to selectively export or unexport directories without restarting the NFS service. When given the proper options, the /usr/sbin/exportfs
command writes the exported file systems to /var/lib/nfs/xtab
. Since rpc.mountd
refers to the xtab
file when deciding access privileges to a file system, changes to the list of exported file systems take effect immediately.
/usr/sbin/exportfs
:
/etc/exports
to be exported by constructing a new export list in /etc/lib/nfs/xtab
. This option effectively refreshes the export list with any changes made to /etc/exports
.
/usr/sbin/exportfs
. If no other options are specified, /usr/sbin/exportfs
exports all file systems specified in /etc/exports
.
/etc/exports
. Replace file-systems with additional file systems to be exported. These file systems must be formatted in the same way they are specified in /etc/exports
. This option is often used to test an exported file system before adding it permanently to the list of file systems to be exported. For more information on /etc/exports
syntax, see Section 8.6.1, “The /etc/exports
Configuration File”.
/etc/exports
; only options given from the command line are used to define exported file systems.
/usr/sbin/exportfs -ua
suspends NFS file sharing while keeping all NFS daemons up. To re-enable NFS sharing, use exportfs -r
.
exportfs
command is executed.
exportfs
command, it displays a list of currently exported file systems. For more information about the exportfs
command, see man exportfs
.
exportfs
with NFSv4RPCNFSDARGS= -N 4
in /etc/sysconfig/nfs
.
rpcbind
, which dynamically assigns ports for RPC services and can cause issues for configuring firewall rules. To allow clients to access NFS shares behind a firewall, edit the /etc/sysconfig/nfs
file to set which ports the RPC services run on. To allow clients to access RPC Quota through a firewall, see Section 8.6.4, “Accessing RPC Quota through a Firewall”.
/etc/sysconfig/nfs
file does not exist by default on all systems. If /etc/sysconfig/nfs
does not exist, create it and specify the following:
rpc.mount -p port
.
nlockmgr
service, set the port number for the nlm_tcpport
and nlm_udpport
options in the /etc/modprobe.d/lockd.conf
file.
/var/log/messages
. Commonly, NFS fails to start if you specify a port number that is already in use. After editing /etc/sysconfig/nfs
, you need to restart the nfs-config
service for the new values to take effect in Red Hat Enterprise Linux 7.2 and prior by running:
Then, restart the NFS server:#
systemctl restart nfs-config
Run#
systemctl restart nfs-server
rpcinfo -p
to confirm the changes have taken effect.
Note
/proc/sys/fs/nfs/nfs_callback_tcpport
and allow the server to connect to that port on the client.
mountd
, statd
, and lockd
are not required in a pure NFSv4 environment.
showmount
command:
$
showmount -e myserver
Export list for mysever /exports/foo /exports/bar
mount
the root directory and look around.
#
mount myserver:/ /mnt/
#
cd /mnt/
exports#
ls exports
foo bar
Note
Procedure 8.1. Making RPC Quota Accessible Behind a Firewall
rpc-rquotad
service, use the following command:
#
systemctl enable rpc-rquotad
rpc-rquotad
service, use the following command:
Note that#
systemctl start rpc-rquotad
rpc-rquotad
is, if enabled, started automatically after starting the nfs-server
service.
875
need to be open. The default port number is defined in the /etc/services
file.
-p port-number
to the RPCRQUOTADOPTS
variable in the /etc/sysconfig/rpc-rquotad
file.
rpc-rquotad
for changes in the /etc/sysconfig/rpc-rquotad
file to take effect:
#
systemctl restart rpc-rquotad
-S
option to the RPCRQUOTADOPTS
variable in the /etc/sysconfig/rpc-rquotad
file.
rpc-rquotad
for changes in the /etc/sysconfig/rpc-rquotad
file to take effect:
#
systemctl restart rpc-rquotad
*
or ?
character to specify a string match. Wildcards are not to be used with IP addresses; however, they may accidentally work if reverse DNS lookups fail. When specifying wildcards in fully qualified domain names, dots (.
) are not included in the wildcard. For example, *.example.com
includes one.example.com
but does not include one.two.example.com
.
/etc/rdma/rdma.conf
file contains a line that sets XPRTRDMA_LOAD=yes
by default, which requests the rdma
service to load the NFSoRDMA client module.
SVCRDMA_LOAD=yes
on a new line in /etc/rdma/rdma.conf
.
RPCNFSDARGS="--rdma=20049"
in the /etc/sysconfig/nfs
file specifies the port number on which the NFSoRDMA service listens for clients. RFC 5667 specifies that servers must listen on port 20049
when providing NFSv4 services over RDMA.
nfs
service after editing the /etc/rdma/rdma.conf
file:
#
systemctl restart nfs
/etc/rdma/rdma.conf
for the changes to take effect.
rpcbind
service to listen on the network.
Requested NFS version or transport protocol is not supported.
Procedure 8.2. Configuring an NFSv4-only Server
/etc/sysconfig/nfs
configuration file:
RPCNFSDARGS="-N 2 -N 3 -U"
RPCBIND
, MOUNT
, and NSM
protocol calls, which are not necessary in the NFSv4-only case.
/etc/sysconfig/nfs
file:
RPCMOUNTDOPTS="-N 2 -N 3"
#
systemctl mask --now rpc-statd.service rpcbind.service rpcbind.socket
#
systemctl restart nfs
netstat
utility.
netstat
output on an NFSv4-only server; listening for RPCBIND
, MOUNT
, and NSM
is also disabled. Here, nfs
is the only listening NFS service:
#
netstat -ltu
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:nfs 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN tcp6 0 0 [::]:nfs [::]:* LISTEN tcp6 0 0 [::]:12432 [::]:* LISTEN tcp6 0 0 [::]:12434 [::]:* LISTEN tcp6 0 0 localhost:7092 [::]:* LISTEN tcp6 0 0 [::]:ssh [::]:* LISTEN udp 0 0 localhost:323 0.0.0.0:* udp 0 0 0.0.0.0:bootpc 0.0.0.0:* udp6 0 0 localhost:323 [::]:*
netstat
output before configuring an NFSv4-only server includes the sunrpc
and mountd
services:
#
netstat -ltu
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:nfs 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:36069 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:52364 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:sunrpc 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:mountd 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN tcp6 0 0 [::]:34941 [::]:* LISTEN tcp6 0 0 [::]:nfs [::]:* LISTEN tcp6 0 0 [::]:sunrpc [::]:* LISTEN tcp6 0 0 [::]:mountd [::]:* LISTEN tcp6 0 0 [::]:12432 [::]:* LISTEN tcp6 0 0 [::]:56881 [::]:* LISTEN tcp6 0 0 [::]:12434 [::]:* LISTEN tcp6 0 0 localhost:7092 [::]:* LISTEN tcp6 0 0 [::]:ssh [::]:* LISTEN udp 0 0 localhost:323 0.0.0.0:* udp 0 0 0.0.0.0:37190 0.0.0.0:* udp 0 0 0.0.0.0:876 0.0.0.0:* udp 0 0 localhost:877 0.0.0.0:* udp 0 0 0.0.0.0:mountd 0.0.0.0:* udp 0 0 0.0.0.0:38588 0.0.0.0:* udp 0 0 0.0.0.0:nfs 0.0.0.0:* udp 0 0 0.0.0.0:bootpc 0.0.0.0:* udp 0 0 0.0.0.0:sunrpc 0.0.0.0:* udp6 0 0 localhost:323 [::]:* udp6 0 0 [::]:57683 [::]:* udp6 0 0 [::]:876 [::]:* udp6 0 0 [::]:mountd [::]:* udp6 0 0 [::]:40874 [::]:* udp6 0 0 [::]:nfs [::]:* udp6 0 0 [::]:sunrpc [::]:*
A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. This enables system administrators to consolidate resources onto centralized servers on the network.
nfs
systemctl start nfs starts the NFS server and the appropriate RPC processes to service requests for shared NFS file systems.
nfslock
systemctl start nfs-lock activates a mandatory service that starts the appropriate RPC processes allowing NFS clients to lock files on the server.
rpcbind
rpcbind accepts port reservations from local RPC services. These ports are then made available (or advertised) so the corresponding remote RPC services can access them. rpcbind responds to requests for RPC services and sets up connections to the requested RPC service. This is not used with NFSv4. The following RPC processes facilitate NFS services:
rpc.mountd
This process is used by an NFS server to process MOUNT requests from NFSv3 clients. It checks that the requested NFS share is currently exported by the NFS server, and that the client is allowed to access it. If the mount request is allowed, the rpc.mountd server replies with a Success status and provides the File-Handle for this NFS share back to the NFS client.
rpc.nfsd
rpc.nfsd allows explicit NFS versions and protocols the server advertises to be defined. It works with the Linux kernel to meet the dynamic demands of NFS clients, such as providing server threads each time an NFS client connects. This process corresponds to the nfs service.
lockd
lockd is a kernel thread which runs on both clients and servers. It implements the Network Lock Manager (NLM) protocol, which allows NFSv3 clients to lock files on the server. It is started automatically whenever the NFS server is run and whenever an NFS file system is mounted.
rpc.statd
This process implements the Network Status Monitor (NSM) RPC protocol, which notifies NFS clients when an NFS server is restarted without being gracefully brought down. rpc.statd is started automatically by the nfslock service, and does not require user configuration. This is not used with NFSv4.
rpc.rquotad
This process provides user quota information for remote users. rpc.rquotad is started automatically by the nfs service and does not require user configuration.
rpc.idmapd
rpc.idmapd provides NFSv4 client and server upcalls, which map between on-the-wire NFSv4 names (strings in the form of user@domain) and local UIDs and GIDs. For idmapd to function with NFSv4, the /etc/idmapd.conf file must be configured. At a minimum, the "Domain" parameter should be specified, which defines the NFSv4 mapping domain. If the NFSv4 mapping domain is the same as the DNS domain name, this parameter can be skipped. The client and server must agree on the NFSv4 mapping domain for ID mapping to function properly.