Note:This document is based on CentOS 6.3. For the 5 Series, see other documents.
1. Install the NFS service 1. Install the NFS suite
First install the NFS suite. The command is as follows:
Yum install nfs-utils.x86_64 (64-bit System)
Yum install nfs-utils (32-bit System)
2. Install the RPC service (note ①)
Yum install rpcbind (centos6)
Ii. Start NFS1. start the RPC service
Service rpcbind start
2. Start the NFS service
Service nfs start
3. Configure NFS Server 1. Set the shared directory
Create a shared directory or use an existing Directory. In this document, create/data/nfsshare as the shared directory.
Return to the root directory CD/
Create the mkdir-p/data/nfsshare-p directory.
2. Edit the/etc/exports file.
A) # vi/etc/exports note ②
B) press the keyboard [I] to enter the editing status.
C) enter the nfs address. The command format is [directory path]… [Target host name or IP address (parameter…)]…
Example:
/Data/nfsshare 10.10.225. * (rw, all_squash, anonuid = 504, anongid = 504) Note ③
[Shared directory] [first host (permission)]
D) save the file and Press esc and enter w to save the file.
E) Exit vi and enter [: q] to exit Vi.
3. Reload the exports file
Enter the exportfs-rv command. Note ④
4. view the nfs Directory released by the Local Machine
Showmount-e Note ⑤
Iv. Set the client 1. view the mounted directory
Showmount-e ip
2. Mount the Server Directory
Mount-t nfs-o nolock [host name or IP address]: [server directory path] [client directory path]
Example:
Mount-t nfs-o nolock
10.10.225.178:/data/nfsshare/data/clientshare
5. Test
Create a file in the shared directory of the server and check whether the client exists.
Problem: 1. RPC: Port mapper failure-RPC: Unable to receive
The iptable is not closed. The port of portmap is blocked. Disable the port and stop the service iptables. Everything is OK!
2. mount. nfs: access denied by server while mounting
Check whether the/etc/exports file settings on the NFS Server are correct.
3. the NFS client cannot write files.
The reason is that the server does not have the read/write permission for the NFS shared directory. You can use chmod to change the folder permission.
Note: Note ① why RPC (Remote Procedure Call) should be installed)
NFS supports many functions, and different functions are started using different programs, each time you start a function, some ports that are not occupied and smaller than 1024 are randomly started to transmit data, because NFS does not support fixed ports.
In this case, a service is required to obtain the corresponding port number, and this service is the RPC service. When the server starts NFS, it automatically registers the randomly obtained port to the RPC service. Therefore, RPC can know the port number corresponding to each NFS function, and the RPC service uses a fixed port number of 111.
This indirectly requires that the RPC service be started before the NFS service.
For details, refer to [Linux private dish of elder brother ------ chapter 13th, one of the Case servers: NFS server]
Http://linux.vbird.org/linux_server/0330nfs.php
Note ② simple operations of Vi
Vi has three modes: Command mode, insert mode, and baseline mode. The command mode is used when the screen is started. At this time, only a variety of commands can be entered, but not input. Therefore, you need to press the [I] key to enter the insert mode and enter the text, then press [Esc] to exit the insert mode and enter the command mode. Input: qw to save and exit.
Note ③ permission Parameters
Parameter Value |
Description |
Rw Ro |
The directory sharing permission is read-write or read-only, but whether the permission can be read or written is related to the rwx and identity of the file system. |
Sync Async |
Sync data is synchronized to the memory and hard disk. async data is first stored in the memory instead of directly written to the hard disk. |
No_root_squash Root_squash |
If the NFS account used by the client is root, how does the system determine the identity of this account? By default, the root identity of the client is reduced from root_squash to nfsnobody to ensure the security of the server system. If you want to enable the root identity of the client to operate the Server File System, you need to set no_root_squash |
All_squash |
No matter what the NFS client identity is, it will be reduced to an anonymous user, that is, nobody (nfsnobody) |
Anonuid Anongid |
Anon stands for anonymous (anonymous user). The UID setting value of the anonymous user mentioned in * _ squash is usually nobody (nfsnobody), but you can set the UID value on your own! Of course, this UID must exist in your/etc/passwd! Anongid is the group's GID. |
Note ④ Exportfs command
The Exportfs command enables the local directory to be installed by the NFS client. By default/Etc/exportsFile to export one or more directories.
Parameters:
-R: re-read the settings in the etc/exports file and make the settings take effect. Instead of restarting the NFS service,-v displays the current shared directory and detailed options.
For details about other settings, refer to the exportfs command.
Note ⑤ command for querying server shared resources on the user end:/usr/sbin/showmount
This is another important NFS command. Exportfs is used for setting and querying on the NFS Server. Showmount is mainly used on the Client side to view the directory resources shared by NFS.
-E: All file systems on the exported server are displayed.
-A displays all Network File System (NFS) clients and directories installed on the server.
-D: displays all directories on the server that is currently loading the NFS client.