Resolution: NFS server configuration command

Source: Internet
Author: User

In the NFS service settings, we can find that two adjustments are required. On the one hand, it is the server, and on the other hand, it is the setting and use of the client. In this case, we will first look at the server configuration details. Let's take a look at the specific steps for creating the NFS service.

Server Configuration

1. Create a shared directory

 
 
  1. # mkdir /home/share  
  2. # chown nobody.nogroup /home/share 

2. Create or modify the/etc/exports configuration file

The content of this file is very simple. Each row consists of the throw path, the list of Customer names, and access options followed by each customer name: [shared directory] [host name or IP address (parameter, parameters)]

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. when the same directory is shared to multiple clients but the permissions provided to each client are not the same, 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:

 
 
  1. Ro read-only access
  2. Rw read/write access
  3. Sync all data written for sharing upon request
  4. Async NFS can request data before writing data
  5. Secure NFS is sent through the secure TCP/IP ports below 1024
  6. Insecure NFS is sent over port 1024
  7. Wdelay if multiple users want to write data to the NFS Directory, write data to the group by default)
  8. 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.
  9. Hide does not share its subdirectories in the NFS shared directory.
  10. No_hide shares the subdirectory of the NFS Directory
  11. Subtree_check if sub-directories such as/usr/bin are shared, force NFS to check the permission of the parent directory by default)
  12. No_subtree_check is opposite to the above. The parent directory permission is not checked.
  13. All_squash: The UID and GID of the shared file are mapped to the anonymous user anonymous, which is suitable for public directories.
  14. No_all_squash retains the UID and GID of the shared file by default)
  15. Root_squash all requests of the root user are mapped to the same permissions as those of the anonymous user by default)
  16. The no_root_squas root user has full management access permissions to the root directory.
  17. Anonuid = xxx specifies the UID of an anonymous user in the NFS server/etc/passwd file
  18. Anongid = xxx specifies the GID of anonymous users in the NFS server/etc/passwd file

The configuration file/etc/exports is as follows:

 
 
  1. $ cat /etc/exports  
  2. /home/share 192.168.102.15(rw,sync) *(ro) 

Configuration Description: grant read and write permissions to 192.168.102.15. Other machines only have read-only permissions.

3. Restart the NFS service.

 
 
  1. # /etc/init.d/nfs-kernel-server restart 

4. View NFS resource sharing on the client

 
 
  1. # showmount -e 192.168.102.47  
  2. Export list for 192.168.102.47:  
  3. /home/share (everyone) 

5. Use the mount command to mount shared resources.

Load shared resources on client 192.168.102.15

 
 
  1. # Mount 192.168.102.47:/home/share/mnt
  2. # Cd/mnt
  3. # Echo '000000'> 12345
  4. You can find that the shared directory on the server is writable.
  5. # Umount/mnt
  6. Load shared resources on client 192.168.102.61
  7. # Mount 192.168.102.47:/home/share/mnt
  8. # Cd/mnt
  9. # Ls
  10. 123
  11. # Touch321
  12. Touch: cannot touch '000000': Permission denied
  13. # Echo '000000'> 123455
  14. -Bash: 123: Permission denied

You can find that only the read permission is available for the server shared directory, which is consistent with the permission settings on the server. Do we need to restart the nfs service every time we modify the configuration file? At this time, we can use the exportfs command to re-scan the/etc/exports file to make the change take effect immediately.

For example:

 
 
  1. # Exportfs-au Uninstall all shared directories
  2. # Exportfs-rv share all directories again and output details

The exportfs command is provided by the software package nfs-kernel-server. For more information about the exportfs command, see:

Man exportfs

For instructions on the Chinese manual, see here: How do we know what permissions are released when resources are shared? In this case, we can view the/var/lib/nfs/etab file, which is generated by the exportfs command according to/etc/exports.

 
 
  1. # cat /var/lib/nfs/etab  
  2. /home/share     192.168.102.15(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)  
  3. /home/share     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534) 

Now let's check which ports are enabled on the NFS server:

 
 
  1. tonybox:/home/share# lsof -i|grep rpc  
  2. portmap   1931 daemon    3u  IPv4   4289       UDP *:sunrpc  
  3. portmap   1931 daemon    4u  IPv4   4290       TCP *:sunrpc (LISTEN)  
  4. rpc.statd 3206  statd    3u  IPv4   7081       UDP *:1029  
  5. rpc.statd 3206  statd    6u  IPv4   7072       UDP *:838  
  6. rpc.statd 3206  statd    7u  IPv4   7085       TCP *:1031 (LISTEN)  
  7. rpc.mount 3483   root    6u  IPv4   7934       UDP *:691  
  8. rpc.mount 3483   root    7u  IPv4   7937       TCP *:694 (LISTEN) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.