I. Introduction to NFS servers
What is NFS? It is short for Network File system, that is, Network File system.
NFS is an RPC service system developed by Sun and launched in 1984. It enables file sharing between different systems, therefore, its communication protocol design has nothing to do with the host and operating system. When you want to use remote files, you only need to run the "mount" command to connect the Remote File System to your own file system, so that the remote files are the same as files on the local computer.
For example, to mount/usr/man on computer B to/usr/man on computer A, run the following command:
Mount B:/usr/man
You can not only mount the mounted directory, but also mount a file. After mounting, the user can only read or write the file), but cannot move or delete the file or directory on a remote computer. However, after mounting/usr/man, you cannot mount the directory under/usr/man. Otherwise, an error occurs.
NFS is a kind of network file system that enables servers to connect files to other computers to share resources. The computers that use these files can be called Client clients ), A client can mount a file or a hierarchical directory on the server. However, in fact, any computer can be an NFS server or NFS client, or even both an NFS server and an NFS client.
All files or directories shared by the NFS server are recorded in the/etc/exports file. When the NFS server is started, the script/etc/rc. d/rc will automatically start the exportfs program to search for the existence of the/etc/exports file and grant the correct permission to all the shared files or directories.
However, it should be noted that only the files or directories shared by the server can be mounted by the NFS client. Similarly, when the client is started, the system will automatically mount all directories or files shared by the server, and all the paths attached will be recorded in/etc/fstab.
When a client mounts a directory or file, it does not mean that the directory or file on the server is copied to the local computer, instead, you can read files from the server to the local memory during use. Therefore, you can use cd to enter the directory to which the files are attached, just as you enter the local directory.
II. Key Points of NFS server configuration
To configure an NFS server, follow these steps:
1) determine that the computer is the server of the NFS file system.
2) partition the hard disk on the server and determine which partitions are used as the file system shared by the client.
3) determine the access parameters of each client, that is, the read and write permissions ).
4) create a/etc/exports file. Generally, the system has a default exports file, which can be directly modified. If not, create one by yourself)
5) restart the NFS server or use the command exportfs-a to output all directories and use nfsd to start the nfsd daemon.
Precautions for Configuration:
1) Check the permissions of the/etc/exports output path. Make sure that only the root user can modify the path. Other users can only read the path.
2) If the computer does not have the NIS service, modify the following files when changing the data:
/Etc/passwd
/Etc/group
/Etc/hosts
/Etc/ethers
3) set security for your network.
Example of the/etc/exports file
/Master (rw) trusty (rw, no_root_squash)
/Projects proj *. local. domain (rw)
/Home/joe pc001 (rw, all_squash, anonuid = 150, anongid = 100)
The format of the exports file is:
Shared directory host option)
Note:
Ro this host has read-only permission
Rw this host has the read and write permissions on the shared directory.
Root_squash maps the root user to the nobody user when the root user accesses the shared folder.
When the no_root_squash client uses the root user to access the shared folder, the root user is not mapped.
Any user on the all_squash client accesses the shared directory and maps it to a nobody user.
Anonuid maps the user on the client to the user of the specified uid.
In the example File above:
/Zhang (rw) wang (rw, no_root_squash)
The command line indicates the/directory on the shared server. Only two hosts, zhang and wang, can access the shared directory. Both hosts have the readable and writable permissions; when the zhangr host uses the root identity for access, It maps the root user of the client to the nobody user root_squash parameter on the server. This parameter is the default parameter ), it is equivalent to using the nobody user on the server to access this directory. When the wang host uses the root user to access this shared directory, the root user no_root_squash parameter is not mapped ), it is equivalent to accessing the directory as a root on the server.
/Projects proj *. local. domain (rw)
The command line indicates the shared/projects directory, local. all Hosts starting with proj in the domain can access this directory and have the read and write permissions. Any user on the client maps to the nobody user all_squash parameter during access, this parameter is the default parameter ). Note that if the client wants to save files in the shared directory, the nobody user on the server must have the write permission on the/projects directory.
/Home/joe pc001 (rw, all_squash, anonuid = 150, anongid = 100)
The command line indicates the shared/home/joe directory. Only the host named pc001 can access the directory. The host named pc001 has the permission to read and write the directory, all users are mapped to users with uid 150 and gid 100 on the server.
Procedure
1) edit the/etc/fstab file and make sure that all the paths to be attached are in fstab.
2) set the mount point on the client according to the content set by fstab ). Mount_points is to use mkdir to set the output path of exports)
3) determining the path to be attached will all appear in the/etc/exports file.
4) run the mount command to link the shared directory mount-a on the server)
For temporary use, run the mount command:
Mount servername: local directory of the shared directory, for example:
Mount 192.168.100.1:/share/mnt
This command uploads the/share directory on 192.168.100.1 to the local/mnt directory. Of course, the server must first set the share directory ).
Example of the/etc/fstab file
192.168.100.1:/home/joe/mnt nfs rw 0 0
Mount syntax
Mount-t type [-rv]-o [option] server: pathname mount_point
Mount:
Mount-a hangs all the paths listed in/etc/fstab
Mount myhost:/usr/local/myshare
Mount the/usr/local directory of myhost to the/usr/local/myshare directory of the client and the directory is readonly.
-T type: the type of the file system to be mounted, such as nfs
-R: The mounted path is readonly.
-V: each action in the mounting process has a message sent back to the screen.
Umount command:
If you do not use this shared directory, You can uninstall it.
Umount mount_point, for example:
Umount/mnt
Umount-a unmount all mounted paths
NFS server configuration instance
A company needs to share a folder on the network. Everyone has only the read-only permission and only users in the 192.168.1.0/24 subnet can access it. Try to share the folder through NFS. The IP address of the NFS server is 192.168.1.1.
The procedure is as follows:
1) Log On As root and create a directory share under the/directory.
[Root @ bearzhang/] # mkdir share
2) edit the/etc/exports file and add the following command line to the file.
/Share 192.168.1.0/24ro, root_squash)
"/Share" indicates the directory to be shared, and 192.168.1.0/24 indicates the host that is allowed to be accessed. Here it is a subnet host ), ro in parentheses indicates that the user on the client has only read-only permission on the shared directory. root_squash indicates that when the root user on the client accesses the shared directory, the user is mapped to an anonymous user, that is, when the root user on the client accesses the shared directory, it is equivalent to the anonymousnobody on the server.
3) install the shared directory on any client on the 192.168.1.0/24 subnet.
[Root @ bearzhang root] # mount 192.168.1.1:/share/mnt
The command line above indicates that the/share directory on 192.168.1.1 is mounted to the/mnt directory of the local machine as a partition.
4) test permissions.