Article title: Linux Network Administrator Manual (11 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Chapter 4 Network File System
Network filesystem (NFS) is perhaps the most prominent network service using RPC. It allows
You can access files on the remote host in the same way as accessing any local files. This is through the kernel function of the client
(It uses a remote file system) and the NFS server function on the server side (it provides file data ).
. This type of file access is completely transparent to customers and can work on a variety of servers and host structures.
NFS provides many advantages:
? Data accessed by all users can be stored on a central host, which is loaded by the customer during boot.
For example, you can store accounts of all users on one host so that all users on your network can
Load the/home directory. If NIS is also installed, you can log on to any system and always log on to a group of files.
.
? Data that consumes a lot of disk space can be stored on a host. For example, all
T files and programs can be saved and maintained in one place.
? Management data can be stored on a single host. You no longer need to use rcp to install the same file on 20 different hosts.
.
NFS is largely made by Rick Sladkey. [1] It compiled the NFS kernel code and most of the NFS server
Points. The latter is derived from the unfsd user-space NFS server compiled by Mark Shand and the h compiled by Donald Becker.
Nfs Harris NFS server.
Now let's take a look at how NFS works: a customer can request to load the directory of a remote host to
The local directory is the same as loading a physical device. However, the syntax used to specify remote directories is different.
. For example, to load the/home of the vlager host to the/users of vale, the administrator needs
Order: [2]
# Mount? T nfs vlager:/home/users
In this case, mount tries to contact the mountd mount background program on vlager through RPC. The server will check whether vale is
The directory to be loaded is allowed. if the row is used, a file handle (file handle) is returned ). File Handle
It will be used for all subsequent requests to files under/users.
When someone accesses a file through NFS, the kernel sends an RPC call to the nfsd (NFS backend
). This call takes the file handle, the file name to be accessed, and the user and group id as parameters. These are used
Determine the access permission for the specified file. To prevent unauthorized users from reading or modifying files
The host must be the same.
In many UN * X implementations, NFS customers and servers are implemented as kernel-layer background programs and are guided by the system.
Started from the user space. NFS background program (nfsd) on the server host, Block I/O background program (biod)
On the client host. To improve throughput, biod uses read-ahead and write-be
Hind) to execute synchronous I/O; similarly, several nfsd background programs are usually run concurrently.
NFS Linux implementation is slightly different. the customer code is tightly integrated into the kernel's virtual file system (VFS) and
You do not need to use biod for additional control. On the other hand, the server code runs completely in the user space.
Several copies of the server are almost impossible-because this will involve synchronization issues. At present, NFS in Linux still lacks
Pre-read and post-write mechanisms, but Rick Sladkey plans to be added in the future. [3]
The biggest problem with Linux's NFS code is that the Linux 1.0 kernel cannot allocate memory blocks larger than 4 K. The result is that the network
The code cannot process a datagram larger than 3500 bytes after removing data such as the header size. This means that the default value is large.
UDP datagram system (for example, 8 K in SunOS), the NFS backend program running on the system needs
Cut the human site into small pieces. In some environments, this seriously damages system performance. [4] This restriction is applied in the latest Linux-
The 1.1 Kernel no longer exists, and the customer code has been modified to overcome this problem.
11.1 prepare NFS
Before you can use NFS, whether as a server or a customer, you must be sure that your kernel has compiled NFS support
Go in. In this regard, the newer kernel has a simple interface on the proc file system, that is, the/proc/filesystems file.
You can use cat to display it:
$ Cat/proc/filesystems
Minix
Ext2
Msdos
Nodev proc
Nodev nfs
If the list does not contain nfs, you must compile your own NFS-enabled kernel. Configure the kernel network option in
In chapter 3, "kernel configuration" is explained.
For kernels earlier than Linux 1.1, the easiest way to find out whether your kernel has enabled NFS support is to try it out.
To load an NFS file system. You can create a directory under/tmp and try to load a local directory
Directory:
# Mkdir/tmp/test
# Mount localhost:/etc/tmp/test
If this loading attempt fails, an error message indicates "fs type nfs no supported by kernel ".
", You must create a new kernel with NFS enabled. Any other error information is completely irrelevant because
You have not configured the NFS background program on your host.
11.2 load an NFS volume
NFS volumes [5] are loaded in the same way as normal file systems. You use the following syntax to call mount:
# Mount? T nfs nfs_volume local_dir options
Nfs_volume is provided in the form of remote_host: remote_dir. This representation is unique to the NFS file system.
1. you can omit the-t nfs option.
When loading an NFS volume, you can specify many other options. These options can be provided after the-o switch on the command line.
Or in the option field of/etc/fstab. In both cases, multiple options are separated by commas (,).
Separated. The options on the command line always overwrite the options in the fstab file.
A sample entry in/etc/fstab can be
# Volume mount point type options
News:/usr/spool/news nfs timeo = 14, intr
Then, the volume can be loaded using the following command:
# Mount news:/usr/spool/news
If there is no corresponding entry in fstab, the NFS mount call looks messy. For example
Load your main directory for the moonshot machine. the moonshot machine uses a default 4 K block.
Read/write operations. You can run the following command to reduce the block size to 2 K to meet the Linux datagram size limit.
# Mount moonshot:/home-o rsize = 2048, wsize = 2048
In the NFS-based mount tool with Rick Sladkey (which can be found in the util-linux package of Rik Faith ),
The nfs (5) manual page provides a complete description of the list of all valid options. Below are some of the things you may need
An incomplete list of options:
Rsize = n and wsize = n
This indicates the size of the datagram used for NFS client read/write requests. Due to the above UDP datagram size limit, it
The default value is 1024 bytes.
Timeo = n this is used to set the waiting time (in seconds) that NFS customers will wait for a request to complete ). The default value is
0.7 seconds.
Hard indicates that the volume is hard-mounted ). The default value is on.
Soft-mount driver (opposite to hard-load ).
Intr allows a notification to interrupt an NFS call. It is useful for abnormal suspension when the server does not respond.
Except rsize and wsize, all these options apply to the actions of the customer when the server temporarily becomes inaccessible.
. They act in the following way: whenever a customer wants the NFS server to send a request, it expects the operation
Within a given interval (specified by the timeout option. If no confirmation is received within this time period
A so-called time-out (minor timeout), the operation is retried and the time-out interval doubles. Within 60 seconds
A master timeout occurs (major timeout ).
By default, a master timeout will cause the client program to print a message on the console and start again.
, The time value doubles again. Potentially, this will continue. Repeat one operation until the server is ready again.
The volume used is called hard-mounted ). Conversely, when a master times out, soft loading (soft-m
Ounted) generates an I/O error message for the calling process. Since the buffer is introduced with post-write, the next time in the process
Before calling the write (2) function, the error is not transmitted to the process itself, so a program is completely uncertain.
Determines whether the write operation on a soft-loaded volume has been completed.
Hard loading or soft loading a volume is not only a matter of feeling (habit), but also a problem with what you want to access from the volume
Information. For example, if you load your X program through NFS, you certainly do not want your X session to be
When 7 xv is enabled, the network is almost interrupted, or the X session is temporarily stopped due to a transient plugging of the ethernet plug.
. By hard loading this volume, you can be sure that your computer will wait until it can be re-built with your NFS server
Establish a connection. On the other hand, non-critical data, such as the news partition loaded by NFS or the FTP documentation program, can also be soft loaded.
Your session will not be suspended when the remote machine cannot be connected or closed for the moment. If the network connection to the server is brittle
If it is weak or requires a heavy-duty router, you can use the timeo option to increase the initial timeout value, or
Attach the volume hard, but allow the signal to interrupt the NFS call, so that you can still terminate any pending file access.
In general, the mountd background program maintains the path of the directory loaded by the host in some way. This information enables
It is displayed using the showmount program, which is also included in the NFS server package. However, now Linux mountd still
This cannot be done.
11.3 NFS background program (Daemons)
If you want to provide NFS services for other hosts, you must run nfsd and mountd background programs on your machine. As
RPC-based programs are not managed by inetd, but started during boot and registered with portmapper
Its own. Therefore, you must be sure to run them only after rpc. portmap runs. Normally, in your rc. inet
2 The script should include the following two lines:
If [-x/usr/sbin/rpc. mountd];
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service