Setting Up an NFS Client


This section covers setting up an NFS client, mounting remote directory hierarchies, and improving NFS performance.

Prerequisites

Install the following packages:

  • nfs-utils

  • system-config-nfs (optional)

The portmap utility (part of the portmap package; refer to "RPC Network Services" on page 377) must be running to enable reliable file locking.

There are no daemons to start for NFS clients.

JumpStart: Mounting a Remote Directory Hierarchy

To set up an NFS client, mount the remote directory hierarchy the same way you mount a local directory hierarchy (page 466). The following sections detail this process.

mount: Mounts a Remote Directory Hierarchy

The following examples show two ways to mount a remote directory hierarchy, assuming that speedy is on the same network as the local system and is sharing /home and /export with the local system. The /export directory on speedy holds two directory hierarchies that you want to mount: /export/progs and /export/oracle.

The example mounts speedy's /home directory on /speedy.home on the local system, /export/progs on /apps, and /export/oracle on /oracle.

First use mkdir to create the directories that are the mount points for the remote directory hierarchies:

# mkdir /speedy.home /apps /oracle


You can mount any directory from an exported directory hierarchy. In this example, speedy exports /export and the local system mounts /export/progs and /export/oracle. The following commands manually mount the directory hierarchies one time:

# mount speedy:/home /speedy.home # mount -o ro,nosuid speedy:/export/progs /apps # mount -o ro speedy:/export/oracle /oracle


If you receive the error mount: RPC: Program not registered, it may mean NFS is not running on the server.

By default, directory hierarchies are mounted read-write, assuming the NFS server is exporting them with read-write permissions. The first of the preceding commands mounts the /home directory hierarchy from speedy on the local directory /speedy.home. The second and third commands use the o ro option to force a readonly mount. The second command adds the nosuid option, which forces setuid (page 183) executables in the mounted directory hierarchy to run with regular permissions on the local system.

nosuid option


If a user has the ability to run a setuid program, that user has the power of Superuser. This ability should be limited. Unless you know that a user will need to run a program with setuid permissions from a mounted directory hierarchy, always mount a directory hierarchy with the nosuid option. For example, you would need to mount a directory hierarchy with setuid privileges when a diskless workstation has its root partition mounted using NFS.

nodev option


Mounting a device file creates another potential security hole. Although the best policy is not to mount untrustworthy directory hierarchies, it is not always possible to implement this policy. Unless a user needs to use a device on a mounted directory hierarchy, mount directory hierarchies with the nodev option, which prevents character and block special files (page 463) on the mounted directory hierarchy from being used as devices.

fstab file


If you mount directory hierarchies frequently, you can add entries for the directory hierarchies to the /etc/fstab file (page 681). (Alternatively, you can use automount; see page 690.) The following /etc/fstab entries automatically mount the same directory hierarchies as in the previous example at the same time as the system mounts the local filesystems:

$ cat /etc/fstab ... speedy:/home          /speedy.home   nfs  -         0 0 speedy:/export/progs   /apps         nfs  r,nosuid  0 0 speedy:/export/oracle  /oracle       nfs  r         0 0


A file that is mounted using NFS is always type nfs on the local system, regardless of what type it is on the remote system. Typically you do not run fsck on or back up an NFS directory hierarchy. The entries in the third, fifth, and sixth columns of fstab are usually nfs (filesystem type), 0 (do not back up this directory hierarchy with dump [page 545]), and 0 (do not run fsck [page 470] on this directory hierarchy). The options for mounting an NFS directory hierarchy differ from those for mounting an ext3 or other type of filesystem. See the next section for details.

umount: Unmounts a Remote Directory Hierarchy

Use umount to unmount a remote directory hierarchy the same way you would unmount a local filesystem (page 469).

mount: Mounts a Directory Hierarchy

The mount utility (page 466) associates a directory hierarchy with a mount point (a directory). You can use mount to mount an NFS (remote) directory hierarchy. This section describes some mount options. It lists default options first, followed by non-default options (enclosed in parentheses). You can use these options on the command line or in /etc/fstab (page 681). For a complete list of options, refer to the mount and nfs man pages.

Attribute Caching

File attributes, which are stored in a file's inode (page 460), provide information about a file, such as file modification time, size, links, and owner. File attributes do not include the data stored in a file. Typically file attributes do not change very often for an ordinary file; they change even less often for a directory file. Even the size attribute does not change with every write instruction: When a client is writing to an NFS-mounted file, several write instructions may be given before the data is actually transferred to the server. In addition, many file accesses, such as that performed by ls, are readonly operations and do not change the file's attributes or its contents. Thus a client can cache attributes and avoid costly network reads.

The kernel uses the modification time of the file to determine when its cache is out-of-date. If the time the attribute cache was saved is later than the modification time of the file itself, the data in the cache is current. The attribute cache of an NFS-mounted file must be periodically refreshed from the server to determine whether another process has modified the file. This period is specified as a minimum and maximum number of seconds for ordinary and directory files. Following is a list of options that affect attribute caching:

ac (noac)


(attribute cache) Permits attribute caching (default). The noac option disables attribute caching. Although noac slows the server, it avoids stale attributes when two NFS clients actively write to a common directory hierarchy.

acdirmax=n


(attribute cache directory file maximum) The n is the number of seconds, at a maximum, that NFS waits before refreshing directory file attributes (default is 60 seconds).

acdirmin=n


(attribute cache directory file minimum) The n is the number of seconds, at a minimum, that NFS waits before refreshing directory file attributes (default is 30 seconds).

acregmax=n


(attribute cache regular file maximum) The n is the number of seconds, at a maximum, that NFS waits before refreshing regular file attributes (default is 60 seconds).

acregmin=n


(attribute cache regular file minimum) The n is the number of seconds, at a minimum, that NFS waits before refreshing regular file attributes (default is 3 seconds).

actimeo=n


(attribute cache timeout) Sets acregmin, acregmax, acdirmin, and acdirmax to n seconds (without this option, each individual option takes on its assigned or default value).

Error Handling

The following options control what NFS does when the server does not respond or when an I/O error occurs. To allow for a mount point located on a mounted device, a missing mount point is treated as a timeout.

fg (bg)


(foreground) Retries failed NFS mount attempts in the foreground (default). The bg (background) option retries failed NFS mount attempts in the background.

hard (soft)


Displays server not responding on the console on a major timeout and keeps retrying (default). The soft option reports an I/O error to the calling program on a major timeout. In general, it is not advisable to use soft. As the mount man page says of soft, "Usually it just causes lots of trouble." For more information refer to "Improving Performance" on page 680.

nointr (intr)


(no interrupt) Does not allow a signal to interrupt a file operation on a hard-mounted directory hierarchy when a major timeout occurs (default). The intr option allows this type of interrupt.

retrans=n


(retransmission value) After n minor timeouts, NFS generates a major timeout (default is 3). A major timeout aborts the operation or displays server not responding on the console, depending on whether hard or soft is set.

retry=n


(retry value) The number of minutes that NFS retries a mount operation before giving up (default is 10,000).

timeo=n


(timeout value) The n is the number of tenths of a second that NFS waits before retransmitting following an RPC, or minor, timeout (default is 7). The value is increased at each timeout to a maximum of 60 seconds or until a major timeout occurs (see retrans). On a busy network, in case of a slow server, or when the request passes through multiple routers/gateways, increasing this value may improve performance.

Miscellaneous Options

Following are additional useful options:

lock (nolock)


Permits NFS locking (default). The nolock option disables NFS locking (does not start the lockd daemon) and is useful with older servers that do not support NFS locking.

mounthost=name


The name of the host running mountd, the NFS mount daemon.

mountport=n


The port used by mountd.

nodev


(no device) Causes mounted device files not to function as devices (page 677).

port=n


The port used to connect to the NFS server (defaults to 2049 if the NFS daemon is not registered with portmap). When n=0 (default), NFS queries portmap on the server to determine the port.

rsize=n


(read block size) The number of bytes read at one time from an NFS server. The default block size is 4096. Refer to "Improving Performance."

wsize=n


(write block size) The number of bytes written at one time to an NFS server. The default block size is 4096. Refer to "Improving Performance".

tcp


Use TCP in place of the default UDP protocol for an NFS mount. This option may improve performance on a congested network; however, some NFS servers support UDP only.

udp


Use the default UDP protocol for an NFS mount.

Improving Performance

hard/soft


Several parameters can affect the performance of NFS, especially over slow connections such as a line with a lot of traffic or one controlled by a modem. If you have a slow connection, make sure hard (page 679) is set (this is the default) so that timeouts do not abort program execution.

Block size


One of the easiest ways to improve NFS performance is to increase the block sizethat is, the number of bytes NFS transfers at a time. The default of 4096 is low for a fast connection using modern hardware. Try increasing rsize [page 756] and wsize to 8192 or higher. Experiment until you find the optimal block size. Unmount and mount the directory hierarchy each time you change an option. See the NFS HOWTO for more information on testing different block sizes.

Timeouts


NFS waits the amount of time specified by the timeo (timeout, page 679) option for a response to a transmission. If it does not receive a response in this amount of time, it sends another transmission. The second transmission uses bandwidth that, over a slow connection, may slow things down further. You may be able to increase performance by increasing timeo.

The default value of timeo is seven-tenths of a second (700 milliseconds). After a timeout, NFS doubles the time it waits to 1400 milliseconds. On each timeout it doubles the amount of time it waits to a maximum of 60 seconds. You can test the speed of a connection with the size packets you are sending (rsize and wsize) by using ping with the s (size) option:

$ ping -s 4096 speedy PING speedy.tcorp.com (192.168.0.1) 4096(4124) bytes of data. 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=0 ttl=64 time=1.43 ms 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=1 ttl=64 time=1.17 ms 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=2 ttl=64 time=1.17 ms ... 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=26 ttl=64 time=1.16 ms 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=27 ttl=64 time=1.16 ms 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=28 ttl=64 time=1.16 ms 4104 bytes from speedy.tcorp.com (192.168.0.1): icmp_seq=29 ttl=64 time=1.26 ms --- speedy.tcorp.com ping statistics --- 30 packets transmitted, 30 received, 0% packet loss, time 29281ms rtt min/avg/max/mdev = 1.154/1.192/1.431/0.067 ms


The preceding example uses Red Hat Linux's default packet size of 4096 bytes and shows a fast average packet round-trip time of slightly more than 1 millisecond. Over a modem line, you can expect times of several seconds. If the connection is dealing with other traffic, the time will be longer. Run the test during a period of heavy traffic. Try increasing timeo to three or four times the average round-trip time (to allow for unusually bad network conditions, as when the connection is made) and see whether performance improves. Remember that the timeo value is given in tenths of a second (100 milliseconds = one-tenth of a second).

/etc/fstab: Mounts Directory Hierarchies Automatically

The /etc/fstab file (page 469) lists directory hierarchies that the system mounts automatically as it comes up. You can use the options discussed in the preceding section on the command line or in the fstab file.

The first example line from fstab mounts grape's /gc1 filesystem on the /grape.gc1 mount point:

grape:/gc1       /grape.gc1   nfs   rsize=8192,wsize=8192      0 0


A mount point should be an empty, local directory. (Files in a mount point are hidden when a directory hierarchy is mounted on it.) The type of a filesystem mounted using NFS is always nfs, regardless of its type on the local system. You can increase the rsize and wsize options to improve performance. Refer to "Improving Performance" on page 680.

The next example from fstab mounts a filesystem from speedy:

speedy:/export     /speedy.export nfs   timeo=50,hard          0 0


Because the local system connects to speedy over a slow connection, timeo is increased to 5 seconds (50 tenths of a second). Refer to "Timeouts" on page 680. In addition, hard is set to make sure that NFS keeps trying to communicate with the server after a major timeout. Refer to "hard/soft" on page 680.

The final example from fstab shows a remote-mounted home directory. Because speedy is a local server and is connected via a reliable, high-speed connection, timeo is decreased and rsize and wsize are increased substantially:

speedy:/export/home   /home                nfs     timeo=4,rsize=16384,wsize=16384 0 0





A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net