Linux NFS Network File System and nfs Network File System
I. Introduction to the NFS service
NFS is short for Network File System, that is, Network File System. An agreement for the use of distributed file systems, developed by sun, was published on April 9, 1984. Function: allows different machines and operating systems to share individual data over the network, allowing applications to access data on the server disk over the network, it is a way to share disk files between Unix-like systems.
The basic principle of NFS is to "allow different clients and servers to share the same file system through a group of RPC", which is independent of the operating system, allows different hardware and operating system systems to share files.
NFS depends on the RPC protocol during file transfer or information transfer. RPC: Remote Procedure Call is a mechanism that enables the client to execute other system programs. NFS itself does not provide information transmission protocols and functions, but NFS allows us to share data over the network, because NFS uses some other transmission protocols. These transmission protocols use this RPC function. NFS itself is a program that uses RPC. Or NFS is an rpc server. Therefore, the RPC service must be started wherever NFS is located. Summary: NFS is only a file system, while rpc is responsible for information transmission.
Ii. Install the NFS service
Two software packages are required for NFS.
Nfs-utils-* includes basic NFS commands and monitoring programs
Rpcbind-* supports Secure nfs rpc service connections
1. Check whether NFS is installed in the system.
Rpm-qa | grep nfs
Rpm-qa | grep rpcbind
If not, yum grouplist and yum groupinstall "NFS"
Iii. NFS server configuration
Common NFS directories
Main configuration file of/etc/exports NFS service
/Usr/sbin/exportfs NFS service management command
/Usr/sbin/showmount client view command
/Var/lib/nfs/etab records the complete permission settings for the directories shared by NFS.
/Var/lib/nfs/xtab records client information that has been logged on
The NFS service configuration file is/etc/exports, and the system does not have the default value. Therefore, this file may not exist. You can use vim to manually create it and then write the configuration content in the file.
/Etc/exports file content format:
<Output directory> [client 1 option (access permission, user ing, and others)] [client 2 Option (access permission, user ing, and others )]
A. output directory: the output directory is the directory that needs to be shared to the client in the NFS system.
B. Client: computer that can access the NFS output directory in the Network
Common Methods for specifying a client:
Host with the specified IP Address: 192.168.0.200
All hosts in the specified subnet: 192.168.0.0/24 192.168.0.0/255.255.255.0
Host for the specified domain name: David .bsmart.cn
All hosts in the specified domain name: * .bsmart.cn
All Hosts :*
C. Option: used to set the access permission and user ing of the output directory.
NFS has three main options:
Access permission options
Set output directory read-only: ro
Set output directory read/write: rw
User ing options
All_squash: maps all common users and groups remotely accessed to anonymous users or user groups (nfsnobody)
No_all_squash: opposite to all_squash (default)
Root_squash: maps root users and their groups to anonymous users or user groups.
No_root_squash: opposite to top
Anonuid = xxx: maps all remotely accessed users to anonymous users and specifies the user as a local user.
Anongid = xxx: maps all remotely accessed user groups to anonymous user group accounts, and specifies that the anonymous user group account is a local user group account.
Other options (ignore, use the default value)
Iv. Start and Stop an NFS server
After correctly configuring the/etc/exports file, you can start the NFS server.
1. Start the NFS server
To enable the nfs server to work properly, you need to start the rpcbind and nfs services, and the rpcbind must be started before nfs.
Service rpcbind start
Service nfs start
2. query the nfs server status
Service rpcbind status
Service nfs status
3. Stop the nfs server
To stop nfs, stop nfs and then stop the rpcbind service. If there are other services in the system (such as nis) that need to be used, you do not need to stop the rpcbind service.
Service nfs stop
Service rpcbind stop
4. Set the Automatic startup status of the nfs server
Chkconfig -- add
Chkconfig -- level 35
V. Instances
1. Share the/home/cairui of the NFS server to 192.168.66.128 for read and write permissions.
# Vim/etc/exports
/Home/cairui 192.168.66.128/24 (rw)
2. Restart the rpcbind and nfs services.
Service rpcbind restart
Service nfs restart
Exportfs
3. The server uses the showmount command to query the NFS sharing status.
Showmount-e
Showmount-a: displays the directory information that has been connected to the client.
4. The client uses the showmount command to query the nfs sharing status.
Showmount-e Server ip Address
5. Mount the shared directory in the nfs server on the client.
Command Format: mount NFS server IP Address: shared directory local mount point directory
Check whether the mounting is successful: mount | grep nfs
Check whether the file is consistent with the server
6. NFS share permission and Access Control
Modify permissions on the server/home/cairui to make the client writable and readable.
Chmod 777-R/home/cairui
6. unmount the mounted NFS shared directory
Format: umount/tmp/cai
8. Start automatic mounting of the nfs File System
Format: <server >:< remote/export>
</Local/directory> nfs <option> 0 0
# Vim/etc/fstab
The last line is the appended
Save and exit. restart the system.