The configuration file/etc/exports of the NFS server:
Meanings of some options in the exports file
Option description
RO this host has read-only permission on the shared directory
RW this host has read and write permissions on the shared directory
Root_squash maps the root user to an anonymous user when the root user accesses the shared folder.
When the no_root_squash client accesses the shared folder with the root user, the root user is not mapped.
All users on the all_squash client map to anonymous users when accessing the shared directory.
Anonuid maps the user on the client to the user of the specified local user ID
Anongid maps the user on the client to the specified local user group ID
Sync data is synchronously written to memory and Hard Disk
The async data will be saved to the memory first, rather than directly written to the hard disk.
Insecure allows unauthorized access from this machine
Example/Zhang (RW) Wang (RW, no_root_squash) indicates that only the root directory (/) on the Shared Server can be accessed by the Zhang and Wang hosts and has read and write permissions; when using the root user identity to access host Zhang, the root user of the client is mapped to an anonymous user on the server (root_squash, this parameter is the default parameter), which is equivalent to using the nobody user to access the directory on the server; when the Wang host accesses the shared directory as the root user, it does not map the root user (no_root_squash), that is, it is equivalent to accessing the directory as the root user on the server.
/Root/share/192.168.1.20 (RW, insecure, sync, all_squash) indicates that the/root/share/directory on the shared server is accessible only to the host 192.168.1.20 and has the read and write permissions; this host maps all client users to anonymous users (all_squash) on the server when accessing it with any identity ), it is equivalent to accessing this directory with the nobody user on the server (if the client wants to save the file (that is, write operation) on this shared directory ), the nobody user on the server must have the write permission on the directory)
/Home/LJM/* .gdfs.edu.cn (RW, insecure, sync, all_squash) indicates the shared/home/LJM/directory. All hosts in the * .gdfs.edu.cn domain can access this directory, and have read and write permissions
/Home/share/.gdfs.edu.cn (RO, sync, all_squash, anonuid = student, anongid = math) indicates that all hosts in the/home/share/* .gdfs.edu.cn domain can access the shared directory, however, only read-only permissions are available. All users are mapped to student and math users on the server.
After NFS is started,/etc/exports is modified. You do not need to restart the service. Run the exports command:
Exports [-aruv]
-A: All content in Mount or umount file/etc/exports
-R: Re-mount the shared content in the file/etc/exports.
-U umount directory
-V outputs detailed information to the screen during the export operation.
Example:
[Root @ localhost ~] #/Usr/sbin/exportfs-RV all re-export once
[Root @ localhost ~] #/Usr/sbin/exportfs-Au unmount all
NFS client Configuration:
For temporary use, run the mount command: Mount servername (or IP ):
Shared directory local Mount directory
If the shared directory of the server is automatically mounted when the client starts, you need to modify the/etc/fstab file on the client.
/Etc/fstab format: (192.168.233.139:/share/mnt NFS defaults 0 2)
Fs_spec fs_file fs_type fs_options fs_dump fs_pass
Fs_spec: defines the device or remote file system where the file system to be loaded is located. For NFS, set it to IP:/shared directory.
Fs_file: Local mount point
Fs_type: Mount type
Fs_options: Mount Parameters
Fs_dump: This option is used by the "dump" command to check how often a file system is dumped. If it is not required to be dumped, It is 0.
Fs_pass: this field is used by The fsck command to determine the sequence of the file system to be scanned at startup. The "/" field value of the root file system should be 1, other file systems are 2. If the file system does not need to be scanned at startup, It is 0.
Security reminder: Ensure network security. When using NFS, use TCP_WRAPPERS to restrict the scope of use (for example, only the 192.168.5.123 host can mount the shared directory on the NFS server). You can also use iptables to enhance security.
[Root @ localhost ~] # Vi/etc/hosts. Allow
Portmap: 192.168.5.123: Allow
[Root @ localhost ~] # Vi/etc/hosts. Deny
Portmap: All: deny
When the NFS server is shut down, if a client is online, the system services Portmap and NFS are disabled first. If the two services cannot be switched off correctly, use netstat
-Utlp: Find the PID and kill the process to shut down.
Nfsstat is helpful to check the running status of NFS and adjust the running status of NFS.
Rpcinfo: displays RPC execution information, used to detect RPC operation
Mount format: Mount-t nfs hostname (or IP):/directory/mount point
Unmount: umount/local Mount directory (local client unmount method, but use exports-AU to unmount the server)
Showmount-e IP address (view the directories shared by the NFS server)
Showmount-a ip address (used on the NFS server to display the client (client) that has mounted the local NFS server ))