Linux Beginner-nfs Network File System Chapter

Source: Internet
Author: User

Linux Beginner-nfs Network File system Chapter

In the previous Samba article, we described the network file system CIFS that is shared between Linux and Windows systems, primarily for clients that are windows. Between Linux systems, the network file system used is NFS. Some of the configuration and usage of NFS are described below.

1. Installation and Configuration of NFS

"Yum install Nfs-utils-y". Install the NFS service, "Systemctl start NFS", "Systemctl enable Nfs-server", turn on the service and set the boot to start automatically. "Systemctl Stop Firewalld", turn off the firewall or configure the firewall.

"Vim/etc/exports". This is the file that writes the shared directory, this file is empty and needs to be filled out by itself. As shown, create a shared directory "/sharedir", in which three files "sharefile{1..3}" are created, and "/sharedir * (Sync)" is written in the "/etc/exports" file, which means sharing "/sharedir", "*" Indicates that all master and all can be used, (sync) is the share permission for file synchronization. After saving exit, enter "EXPORTFS-RV" refresh, it is recommended not to restart the service, because the restart speed is slow.

"Showmount-e IP". You can see if this IP has shared files, for example, enter "Showmount-e 172.25.254.202" to see the shared directory "/sharedir" for the above settings.

"Mount 172.25.254.202/sharedir/mnt". Unlike CIFS Network file systems, NFS cannot log on to view shared content and can only be mounted.

2. Authority and document owner

In the configuration file "Vim/etc/exports", you can set some or some hosts can be shared directory mount, as shown, enter "/sharedir 172.25.254.2 (Sync)" means only "172.25.254.2" this host can be mounted.

In the configuration file, enter "Sync" for file synchronization, or "RW" for Read and write access, and "RO" for reading only. More permission settings can be viewed through "man 5 exports".

As shown, after the shared directory is mounted, in which a file "File1" is created, and the owner of the file is "Nfsnobody", which is an anonymous user of NFS.

You can change the owner of the file by making the following settings for the configuration file:

A. Change the file owner to root.

Enter "No_root_squash" within the permissions in the configuration file, as shown, after mounting a file "File2", you can see that all the files "File2" and all the groups are root.

B. The owner of the specified file and all groups

Enter "Anonuid=xxxx,anongid=xxxx" within the permissions in the configuration file and include the input "anonuid=1000,anongid=1001". After the reload, the file "File4" is created, and the client can see that the file owner is "1000" and all the groups are "kiosks" because the GID of the Kiosk user group is 1001. On the server side you can see the file's owner as "uid=1000" student users, all groups are "gid=1001" class groups.

3. Auto-mount and auto-cancel of client

Mounting is usually required to manually mount and cancel the mount, after the use of the need to cancel the mount, which undoubtedly increased the complexity of the operation, if you forget to cancel the mount will also occupy the system resources, causing trouble. This problem can be avoided if you can mount and cancel automatically.

This functionality can be achieved by loading the software on the client. "Yum Install AutoFS", the installation of AutoFS software on the client will enable automatic mounting of shared directories and automatic cancellation of mounts.

"Systemctl start AutoFS", when this service is started, a "/net" directory is automatically generated and "cd/net/172.25.254.202" can see the shared directory directly. You can also see that it is automatically mounted under the directory "/net".

"Vim/etc/sysconfig/autofs". The value after "timeout" in line 15th indicates the time to automatically cancel the mount, as shown, set to "3", which means that the directory is automatically canceled after 3 seconds of exiting.

4, the client's designated mount Directory

The auto mount of the client can not only be mounted under "/net", but also can set the directory mount point yourself.

For example, to mount the shared directory "/sharedir" in the client's "/nfs/sharedir" directory. First set up a "/nfs" directory, in the configuration file "/etc/auto.master" edit "/nfs/etc/auto.nfs", as shown, "/nfs" target mount point of the ancestor directory, "/etc/auto.nfs" Configures the shared directory destination mount point file for the record.

"Vim/etc/auto.nfs". Write "Sharedir 172.25.254.202:/sharedir" in this file. This is the configuration shared directory destination mount point. After restarting the service, enter "/nfs/sharedir" can be automatically mounted, leaving this directory after 3 seconds will automatically cancel the mount.

5. Storage separation

Storage separation is to mount the shared directory on the client and store the file in a shared directory, so that if there is a problem with the client's host, it will not result in data loss.

For example, the shared directory is mounted in the client's student user home directory, then student user login, will automatically mount the shared directory, and student the user stored files will exist in this shared directory, exit student users can also see these files. Specific practices are:

Create a "/sharedir/student" shared directory on the server. Edit/sharedir/student 172.25.254.0/24 (rw,anonuid=1000,anongid=1000) in the configuration file "/etc/exports". Share this directory.

Edit "/etc/auto.master" in the client, and edit "/home/etc/auto.home" in it.

"Vim/etc/auto.home". Edit "Student 172.25.254.202:/sharedir/student". You can also edit "* 172.25.254.202:/sharedir/&", "*" for any shared directory, "&" for directories that match "*", used when there are many directories in the shared directory.

After restarting the service, switch to the student user, then automatically mount the home directory, the establishment of "file{1..5}" 5 files, 3 seconds after the exit automatically cancel mount, in the server side of the shared directory can see the 5 files.

Linux Beginner-nfs Network File System Chapter

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.