NFS(Network File System) Configuration

来源:互联网 发布:托业网络课程 编辑:程序博客网 时间:2024/05/17 09:10

1. A Glance at NFS

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a computer network much like local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The NFS is an open standard defined in Request for Comments (RFC), allowing anyone to implement the protocol.

2. Versions and variations

这里写图片描述
Sun used version 1 only for in-house experimental purposes. When the development team added substantial changes to NFS version 1 and released it outside of Sun, they decided to release the new version as v2, so that version interoperation and RPC version fallback could be tested.
NFSv2

This section needs expansion. You can help by adding to it. Version 2 of the protocol (defined in RFC 1094, March 1989) originally operated only over User Datagram Protocol (UDP). Its designers meant to keep the server side stateless, with locking (for example) implemented outside of the core protocol. People involved in the creation of NFS version 2 include Russel Sandberg, Bob Lyon, Bill Joy, Steve Kleiman, and others.The Virtual File System interface allows a modular implementation, reflected in a simple protocol. By February 1986, implementations were demonstrated for operating systems such as System V release 2, DOS, and VAX/VMS using Eunice. NFSv2 only allows the first 2 GB of a file to be read due to 32-bit limitations.

NFSv3

Version 3 (RFC 1813, June 1995) added:

support for 64-bit file sizes and offsets, to handle files larger than 2 gigabytes (GB);support for asynchronous writes on the server, to improve write performance;additional file attributes in many replies, to avoid the need to re-fetch them;a READDIRPLUS operation, to get file handles and attributes along with file names when scanning a directory;assorted other improvements.The first NFS Version 3 proposal within Sun Microsystems was created not long after the release of NFS Version 2. The principal motivation was an attempt to mitigate the performance issue of the synchronous write operation in NFS Version 2.[5] By July 1992, implementation practice had solved many shortcomings of NFS Version 2, leaving only lack of large file support (64-bit file sizes and offsets) a pressing issue. This became an acute pain point for Digital Equipment Corporation with the introduction of a 64-bit version of Ultrix to support their newly released 64-bit RISC processor, the Alpha 21064. At the time of introduction of Version 3, vendor support for TCP as a transport-layer protocol began increasing. While several vendors had already added support for NFS Version 2 with TCP as a transport, Sun Microsystems added support for TCP as a transport for NFS at the same time it added support for Version 3. Using TCP as a transport made using NFS over a WAN more feasible, and allowed the use of larger read and write transfer sizes beyond the 8 KB limit imposed by User Datagram Protocol (UDP).

NFSv4

Version 4 (RFC 3010, December 2000; revised in RFC 3530, April 2003 and again in RFC 7530, March 2015), influenced by Andrew File System (AFS) and Server Message Block (SMB, also termed CIFS), includes performance improvements, mandates strong security, and introduces a stateful protocol. Version 4 became the first version developed with the Internet Engineering Task Force (IETF) after Sun Microsystems handed over the development of the NFS protocols.NFS version 4.1 (RFC 5661, January 2010) aims to provide protocol support to take advantage of clustered server deployments including the ability to provide scalable parallel access to files distributed among multiple servers (pNFS extension). NFS version 4.2 (RFC 7862) was published in November 2016.

3. Practical Configuration

3.1 Installation( by yum sources )

yum install nfs-utils -y

3.2 Starting service and setting it to autostart

[root@localhost ~]# systemctl start nfs-server[root@localhost ~]# systemctl enable nfs-serverln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'[root@localhost ~]# systemctl status nfs-server

这里写图片描述

3.3 Editing exports config file to add shareing files or directories
[root@localhost ~]# vim /etc/exports

/lockey 172.25.254.36(rw,sync)#to share directory /lockey to host 172.25.254.36 only with the rights(write and sync)

3.4 Show shared files or directories
[root@localhost ~]# exportfs -rv
###refresh share
[root@localhost ~]# showmount -e localhost

[root@localhost ~]# showmount -e localhostExport list for localhost:/lockey 172.25.254.36[root@localhost ~]#

3.5 Mounting and accessing

[root@foundation /]# mount 172.25.254.136:/lockey /mnt[root@foundation /]# dfFilesystem             1K-blocks     Used Available Use% Mounted on/dev/sda3              120529408 32585552  87943856  28% /devtmpfs                 1868044        0   1868044   0% /devtmpfs                    1881152      488   1880664   1% /dev/shmtmpfs                    1881152     9068   1872084   1% /runtmpfs                    1881152        0   1881152   0% /sys/fs/cgroup/dev/sda1                 508588   149440    359148  30% /boottmpfs                     376232       28    376204   1% /run/user/1000tmpfs                     376232        0    376232   0% /run/user/0172.25.254.136:/lockey  10473984  3183872   7290112  31% /mnt[root@foundation /]# cd /mnt/[root@foundation mnt]# lshalo  halo5  halo6  haloo  student[root@foundation mnt]# 

Results show:
这里写图片描述
3.6 Permanant mounting NFS
vim /etc/fstab
#add follow:

172.25.254.136:/lockey /mnt/ nfs defaults 0 0

4. Auto-mounting an NFS share (autofs)

autofs is a program for automatically mounting directories on an as-needed basis. Auto-mounts are mounted only as they are accessed, and are unmounted after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab 

4.1 Installation

yum install autofs -y

4.2 Configuration

The master configuration file for autofs is /etc/auto.master ,then we should firstly edit the master configurationEach of the lines in auto.master describes a mount and the location of its map. These lines have the following format:mount-point [map-type[,format]:] map [options]

4.2.1 Edit /etc/auto.master
这里写图片描述

automount maps can be direct or indirect. Indirect maps, such as those in the auto.master file shown above, create-mount points as subdirectories inside the main mount-point. For example, consider the following master map entry:

/autofs  /etc/auto.fs

This entry in auto.master tells autofs to look in /etc/auto.fs and create mount-points in the /autofs directory.

4.2.2 Create /etc/auto.nfs
[root@foundation /]# cat /etc/auto.nfs
* 172.25.254.136:/lockey/&
[root@foundation /]#

这里写图片描述
4.3 Testing
Now you can remove (or comment out) their respective entries in /etc/fstab.
Then excute:

    systemctl restart autofs

这里写图片描述

Extension

Once you set your mount-point as “/home”, you will find there will be an error when you try to add a system user:

[root@foundation /]# useradd halo"useradd: cannot create directory /home/halo" 

All this happened because that rhel autofs deamon was mounted on the /home directory and hid your /home directory. If you really want to add a user, you should firstly umount shared directory, and then everthing will be OK!

原创粉丝点击