NFS (Network File System) service configuration and use

Source: Internet
Author: User

Sun's development of the NFS (Network file system) was designed to share files or folders between different Linux/unix systems. The remote host's shared files can be mounted locally over the network, interacting with the remote host. NFS shared storage is not very good for beginners, I have seen a good example, if there are three machines A, B, C, they need to access the same directory, the directory is a picture, the traditional practice is to put these pictures in a, B, C. But using NFS only needs to be placed on a, then A is shared with B and C. At the time of the visit, B and C go through the network to access the directory on a.

First, the Advantages of NFS
    • Allow local access to remote files
    • NFS uses standard CS architecture to share files on Linux/unix machines
    • NFS does not require that all machines are the same operating system.
    • You can configure a centralized storage solution with NFS.
    • The user gets data that is independent of the physical location.
    • Adding a new file does not require a manual refresh.
    • The new version of NFS also supports Acl,pseudo root mount.
    • Security protection can be enhanced through firewalls and certifications.
Ii. NFS configuration-related files
    • /ETC/EXPORTS:NFS Service Core configuration file, all shared files and directories on server side of NFS are defined in this file.
    • /etc/fstab: To mount an NFS directory in the system and to take effect after reboot, add the appropriate configuration in/etc/fstab.
    • A/ETC/SYSCONFIG/NFS:NFS configuration file that controls which ports RPC or other services are listening to.
Third, the configuration and use of NFS1, environment

The Linux environment configures the NFS service to require at least 2 Linux machines and is guaranteed to ping.

NFS Server ip:10.1.101.188

NFS Client ip:10.1.101.189

2. Installing NFS Server and NFS Client

NFS packages are required for NFS Server and NFS client two machines. (Red Hat Linux uses "yum") Debian and Ubuntu environments with "Apt-get". "Take server side as an example"

# apt-get Install Nfs-common Nfs-kernel-server

NFS Server and NFS client two machines all start NFS services.

To start the Portmap and NFS two services, and the Portmap service must be started before NFS. "Take server side as an example"

[Email protected]:~#/etc/init.d/portmap startrather than invoking init scripts through/etc/init.d, use the service (8) UTI  Lity, e.g. service Portmap startsince The script you is attempting to invoke have been converted to Anupstart job, your may Also use the Start (8) utility, e.g. start portmap [email protected]:~#/etc/init.d/nfs-kernel-server start * exporting di Rectories for NFS kernel daemon                                                            ... [OK]  
3. Server-side Configuration for NFS

To share a directory, first add it to the/etc/exports. We create a new directory in the root directory/nfsshare, shared to the client.

Then restart the service for the configuration to take effect (or use command #exportfs-rv).

 [email protected]:~# mkdir/nfsshare 
[email protected]:~# cat/etc/exports
#/etc/exports:the Access control list for filesystems which is exported
#         & nbsp;     to NFS clients.  See exports (5).
#
# Example for NFSv2 and NFSv3:
#/srv/homes       Hostname1 (rw,sync,no_ Subtree_check) hostname2 (Ro,sync,no_subtree_check)
#
# Example for NFSv4:
#/srv/nfs4         gss/krb5i (Rw,sync,fsid=0,crossmnt,no_subtree_check)
#/srv/nfs4/homes  gss/krb5i (Rw,sync,no_subtree_check)
#
/nfsshare 10.1.101.189 (rw,sync,no_root_squash)
[email protected]:~#/etc/init.d/ Nfs-kernel-server Restart
/nfsshare 10.1.101.189 (Rw,sync,no_root_squash) This means that the/nfsshare directory under the root partition is shared with the IP "10.1.101.189" and has read and write(rw) permissions, the host name (hostname) can also be used instead of IP.

Client host address in exports file

The Client host address field can represent host addresses in multiple forms

10.1.101.189: Specifies the IP address of the host

Nfsclient.test.com: Specifies the host of the domain name

10.1.101.0/24: Specify all hosts in the network segment

*.test.com: All hosts under the specified domain

*: All Hosts

Configuration options in the exports file

The "configuration options" in the exports file are enclosed in parentheses, and the options are separated by commas.

    • RO: This option indicates that read only, the client only allows reading shared files.
    • RW: This option indicates the shared directory readable (read)write (wirte)of the output, and the client has permission to read the file as well as to write the file.
    • Sync: It is inefficient to write data synchronously to the buffer and disk , but to ensure consistency of data, it is recommended that all NFS shared directories use this option.
    • Async: The data is saved in the memory buffer first, and is written to disk if necessary.
    • Wdelay (default): Check for related write operations, and if so, perform these writes together, which can improve efficiency.
    • No_wdelay: If a write operation is performed immediately, it should be used in conjunction with sync.
    • All_squash: All access users are mapped to anonymous users or groups of users.
    • No_all_squash (default): The access user is first matched to the native user, and the match fails before it is mapped to an anonymous user or user group.
    • Subtree_check (default): If the output directory is a subdirectory, Server for NFS will check the permissions of its parent directory.
    • No_subtree_check: Indicates that subtree checking is disabled . Disabling subtree checking can improve efficiency, but it can reduce its security.
    • Root_squash (default): The visiting root user is mapped to an anonymous user or user group.
    • No_root_squash: The root user remains rooted, as is the case with local directory operations, unsafe and not recommended.
    • ANONUID=<UID>: Specifies the local user UID of the anonymous access user, which defaults to Nfsnobody (65534).
    • Anongid=<gid>: Specifies the local user group GID for the anonymous access user, which defaults to Nfsnobody (65534).
    • Secure (Default): Restricts clients from connecting to the server only from TCP/IP ports less than 1024.
    • Insecure: Allows the client to connect to the server with a TCP/IP port greater than 1024.
4. NFS Client Configuration

After the server side is configured, mount the shared directory or partition on the client.

First step: View shared files for NFS server

[Email protected]:~# showmount-e 10.1.101.188Export list for 10.1.101.188:/nfsshare 10.1.101.189

Step two: New mount point

[Email protected]:~# mkdir-p/mnt/nfsshare

The third step: mount, pay attention to the permissions.

[Email protected]:~# mount-t NFS 10.1.101.188:/nfsshare/mnt/nfsshare   mount.nfs:access denied by server while Mounti Ng 10.1.101.188:/nfsshare
[Email protected]:/# chmod 777-r/nfsshare/
[Email protected]:/#/etc/init.d/nfs-kernel-server Restart * Stopping NFS kernel daemon [OK] * unexporting Direc Tories for NFS kernel daemon ... [OK] * Exporting directories for NFS kernel daemon ... Exportfs:/etc/exports [1]: Neither ' subtree_check ' or ' no_subtree_check ' specified for export ' 10.1.101.189:/nfsshare '. Assuming default behaviour (' No_subtree_check '). Note:this default has changed since Nfs-utils version 1.0.x [OK] * Starting NFS Kernel daemon
[Email protected]:~# mount-t NFS 10.1.101.188:/nfsshare/mnt/nfsshare  

Fourth step, check whether the mount is successful:

[Email protected]:~# mount |grep nfs10.1.101.188:/nfsshare on/mnt/nfsshare type NFS (rw,vers=4,addr=10.1.101.188, clientaddr=10.1.101.189)

The above mount is only temporary, after the machine restarts there is no. To mount permanently, you can configure it in "/etc/fsab".

That is, add a line to the/etc/fstab:

10.1.101.188:/nfsshare/mnt/nfsshare NFS Defaults 0 0

[Email protected]:~# cat/etc/fstab#/etc/fstab:static file system information.## use ' Blkid ' to print the universally UN Ique identifier for a# device; This May is used with uuid= as a more robust-to-name devices# that works even if disks is added and removed. See Fstab (5). # <file system> <mount point>   <type>  <options>       <dump>  <pass>proc            /proc           proc    nodev,noexec,nosuid 0       0#/was on/dev/xvda1 during installationuuid= 0c681b37-97ed-4d10-bd79-8d5931c443f8/               Ext4    errors=remount-ro 0 #       swap was on/dev/xvda5 during Installationuuid=9e2efc1b-ef13-4b7c-b616-34d2a62f04ea none            swap    SW              0       010.1.101.188:/ Nfsshare/mnt/nfsshare NFS Defaults 0 0

Then execute the command: mount-a

[Email protected]:~# mount-a
[Email protected]:~# Mount |grep NFS
10.1.101.188:/nfsshare On/mnt/nfsshare type NFS (rw,vers=4,addr=10.1.101.188,clientaddr=10.1.101.189)
5. Test NFS Configuration

Create a new test file on the NFS server side to check if the NFS client side is available and vice versa.

The first step is to create a new file "NfsTestServer.txt" in the shared Directory of NFS server.

[Email protected]:/nfsshare# cat NfsTestServer.txt This was a test file to test the working of NFS Server Setup. This file is created at NFS server end.

In the second step, you can see the "nfsTestServer.txt" file without a refresh on the NFS client side.

[Email protected]:/mnt/nfsshare# lsnfstest.txt

This was a test file to test the working of NFS Server Setup.
This file is created at NFS server end.

The third step is to create a new test file "NfsTestClient.txt" on the NFS client side.

[Email protected]:/mnt/nfsshare# cat NfsTestClient.txt This was a test file to test the working of NFS Server Setup. This file is created at NFS client end.

Fourth step, you can see the "nfsTestClient.txt" file without refreshing on the nfsserver side.

[Email protected]:/nfsshare# cat NfsTestClient.txt This was a test file to test the working of NFS Server Setup. This file is created at NFS client end.
6. Uninstall

After the file share is finished, perform the umount command uninstall.

[Email protected]:~# df-h-F NFS
Filesystem Size used Avail use% mounted on
10.1.101.188:/nfsshare 19G 1.7G 17G 10%/mnt/nfsshare

[Email protected]:~# df-h-F NFS
Df:no File Systems processed
7. Unloading and troubleshooting
[Email protected]:/mnt/nfsshare# umount/mnt/nfsshareumount.nfs:/mnt/nfsshare:device is busy

First: Be careful not to execute umount in the current directory, otherwise you will get an error.

[Email protected]:~# umount/mnt/nfsshareumount.nfs:/mnt/nfsshare:device is busy

If exiting the directory is still not possible, then it is determined that there is a process in use for that directory to find out.

[Email protected]:~# fuser-m/mnt/nfsshare/mnt/nfsshare:         923c

Locate the process that uses the directory:

[Email protected]:~# PS aux |grep 923root       923  0.0  0.3  21452   4036 pts/0 ss+ 10:12 0:00-bashroot      1323  0.0  0.0   8104   924 pts/1    s+   11:22   0:00 grep--color=auto 923

Kill process

[Email protected]:~# kill-9 923

Then you can uninstall it.

[Email protected]:~# umount/mnt/nfsshare
Iv. NFS Commands

Showmount

    • SHOWMOUNT-E <server-ip or hostname>: Displays a list of host NFS server outputs. -E or--exports
    • showmount-d <server-ip or hostname> : Displays the directory that is mounted by the client. -D or--directories
    • Showmount-a <server-ip or hostname>: Lists all client hosts for the NFS server and the connected directories, that is, mount points

EXPORTFS management tool to manage "exports" files

    • EXPORTFS-V: Output host shared files and options to the screen:
[Email protected]:~# exportfs-v/nfsshare       10.1.101.188 (Rw,wdelay,no_root_squash,no_subtree_check)
    • Exportfs-a: Mount or unload all content in/etc/exports, output all shared files set in/etc/exports file
[Email protected]:~# exportfs-aexportfs:/etc/exports [1]: Neither ' subtree_check ' or ' no_subtree_check ' specified for ex Port "10.1.101.189:/nfsshare".  Assuming default behaviour (' No_subtree_check ').  Note:this default has changed since Nfs-utils version 1.0.x
    • Exportfs-u: Uninstalling a single directory (used together with-A to unload directories in all/etc/exports files)
    • Exportfs-r: Re-read the settings of the/etc/exports file and make the settings effective immediately without restarting the service. and synchronize Updates/var/lib/nfs/xtab
    • EXPORTFS-RV: Re-export the shared directory.

Set up automatic start of NFS service

Chkconfig--level Portmap on

Chkconfig--level NFS On

Rpcinfo: View RPC Service registration status

-P: Displays all port and program information:

View Code

Recommended Resource Links

Https://help.ubuntu.com/community/SettingUpNFSHowTo

NFS (Network File System) service configuration and use

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.