NFS introduction:
NFS is a network file system. It is mainly used in linux or unix environments. It was developed by sun and launched in 1984.
NFS features:
It can publish multiple directories or a single directory. For example, we can use NFS to share the disk image during the online engraving system. NFS publishes files in the publishing directory, the client is accessed by means of mounting. The client can save local space and store data on the nfs server. NFS can also set different access permissions for individual users and multiple users.
Detailed configuration steps:
To install NFS, you must enable the following services: nfs, portmap,
NFS configuration is relatively simple than other services. We still need to pay attention to the firewall and SElinux.
[Root @ huyb ~] # Rpm-qa | grep nfs-utils
Nfs-utils-1.0.9-16.el5
Nfs-utils-lib-1.0.8-7.2 // nfs-utils is installed by default;
[Root @ huyb ~] # Rpm-qa | grep portmap
Portmap-4.0-65.2.2.1 // portmap is installed by default;
If the system does not install the required software, you can manually install it;
[Root @ huyb ~] # Mount/dev/cdrom/mnt // mount/dev/cdrom/mnt to/mnt of the system;
[Root @ huyb ~] # Cd/mnt/Server // switch the working directory to/mnt/Server;
[Root @ huyb Server] # ls | grep nfs // list nfs-related software packages;
[Root @ huyb Server] # rpm-ivh nfs-utils-1.0.9-16.el5.i386.rpm // install the nfs-utils package;
Create or modify the/etc/exports configuration file
The content of this file is very simple. Each line consists of the throw path, the list of Customer names, and the Access Options followed by each customer name:
[Shared directory] [host name or IP address (parameter, parameter)]
The parameters are optional. If no parameter is specified, nfs uses the default option. The default sharing options are sync, ro, root_squash, and no_delay.
If the host name or IP address is empty, it indicates that the shared IP address is used to provide services to any client.
If you share the same directory with multiple clients but have different permissions for each client, you can:
[Shared directory] [host name 1 or IP1 (parameter 1, parameter 2)] [host name 2 or IP2 (parameter 3, parameter 4)]
Below are some common NFS sharing parameters:
Ro read-only access
Rw read/write access
Sync all data written for sharing upon request
Async NFS can request data before writing data
Secure NFS is sent through the secure TCP/IP ports below 1024
Insecure NFS is sent over port 1024
Wdelay if multiple users want to write data to the NFS Directory, group write (default)
No_wdelay if multiple users want to write data to the NFS Directory, write the data immediately. This setting is not required when async is used.
Hide does not share its subdirectories in the NFS shared directory.
No_hide shares the subdirectory of the NFS Directory
Subtree_check if sub-directories such as/usr/bin are shared, force NFS to check the permissions of the parent directory (default)
No_subtree_check is opposite to the above. The parent directory permission is not checked.
All_squash: The UID and GID of the shared file are mapped to the anonymous user anonymous, which is suitable for public directories.
No_all_squash retains the UID and GID of the shared file (default)
Root_squash all requests of the root user are mapped to the same permissions as those of the anonymous user (default)
The no_root_squas root user has full management access permissions to the root directory.
Anonuid = xxx specifies the UID of an anonymous user in the NFS server/etc/passwd file
Anongid = xxx specifies the GID of anonymous users in the NFS server/etc/passwd file
The configuration file/etc/exports is as follows:
$ Cat/etc/exports
/Home/share 192.168.102.15 (rw, sync) * (ro)
Configuration Description: grant the read and write permissions to 192.168.102.15. Other machines only have the read-only permission.
Maintain the output directory list of the NFS service
Command exportfs
-A outputs all directories defined in the/etc/exports file;
-R re-reads the/etc/exports file and does not need to restart the service;
-U stops outputting a directory;
-V display on the screen;
1. output the shared directory again.
[Root @ huyb ~] # Exportfs-rv
Exporting 192.168.1.0/24:/nfs/public
Exporting 192.168.1.253:/nfs/huyb
Exporting * .wn.com:/nfs/users
Exporting 192.168.1. *:/mnt/cdrom
Exporting * .wn.net:/nfs/root
Exporting *:/nfs/public
2. view the shared directory output by the NFS service
[Root @ huyb ~] # Showmount-e 192.168.1.102
Export list for 192.168.1.102:
/Nfs/root * .wn.net
/Mnt/cdrom 192.168.1 .*
/Nfs/users * .wn.com
/Nfs/huyb 192.168.1.253
/Nfs/public (everyone)
3. Stop outputting all shared directories
[Root @ huyb ~] # Exportfs-auv
[Root @ huyb ~] # Showmount-e 192.168.1.102
Export list for 192.168.1.102: // The result is empty;
4. start or stop the NFS server
[Root @ huyb ~] # Sevice nfs start | stop | restart
[Root @ huyb ~] # Chkconfig -- level 35 nfs on // sets the automatic NFS startup mode;
5. query the nfs status
[Root @ huyb ~] # Service portmap status
[Root @ huyb ~] # Service nfs status
6. query the shared directory of the nfs server
Showmount 192.168.1.111
Showmount
-A: displays all client hosts of the specified nfs server and Their Connected Directories;
-D: displays all output directories connected to clients in the specified nfs server;
-E: displays all output directories on the specified nfs server;
Author: "nilm"