How to configure an NFS server and mount NFS shares on Ubuntu 14.04
Version: 1.0
Last Edited: July 7th, 2014
Contents
- 1.1: NFS- An Overview
- 1.2 Preconditions
- 1.3 Downloading and Installing the Components
- 1.4 Creating the Share Directory on the Host Server
- 1.5 Configuring the NFS Exports on the Host Server
- 1.6 Creating the Mount Points and Mount Remote Shares on the Client Server
- 1.7 Testing NFS Access
- 1.8 Making Remote NFS Directory Mounting Automatic
- 1.9 Unmounting an NFS Remote Share
- 1.10 Wrap Up
1.1 NFS-An Overview
Network File System (NFS) is a popular distributed filesystem protocol that enables users to mount remote directories on their server. The system lets you leverage storage space in a different location and write onto the same space from multiple servers in an effortless manner. It, thus, works fairly well for directories that users need to access frequently. This tutorial explains the process of mounting NFS share on an Ubuntu 14.04 server in an simple and easy-to-follow steps.
1.2 Preliminary Information
1. For the purpose of this tutorial, there would be a directory sharing configuration between two Ubuntu 14.04 servers, which could be of any size. However, for each of these servers, you would need an account that has been set up with sudo privileges. 2. For the purposes of this tutorial, the server that shall share its directories would be referred to as the host, while the server that shall mount these directories would be termed as the client. 3. For the purposes of uniformity and simplicity, the following IP addresses shall be used to refer to the host and server values throughout the tutorial:
- Host: 5.6.7.8
- Client: 333. 333. 333. 333
Users must substitute the aforementioned values with their distinct host and client values.. We are now all set to learn the steps in mounting an NFS share on Ubuntu 14.04
1.3 Downloading and Installing the Components
At the outset, it is essential to install the necessary components on both the host and client servers. Expressly on the host server, you would be required to install the nfs-kernel-server package, which will enable you to share your directories. As this is the first step that you’ll be performing with apt in this session, you must begin by refreshing the local package index before the installation (as given below):
sudo apt-get update
sudo apt-get install nfs-kernel-server
Upon installation of these packages, you may make the switch to the client computer. On the client computer, you would be required to install a package called nfs-common, that offers NFS functionality without the need to include the server components. Here again, you need to refresh the local package index prior to installation to ensure that you have updated information (as shown below):
sudo apt-get update
sudo apt-get install nfs-common
This brings you to the end of this step, and you may now move on to the next one.
1.4 Creating the Share Directory on the Host Server
For the purpose of this tutorial, there would be an experiment involving sharing two distinct directories. The first directory for sharing happens to be the /home directory containing user data. The second one would be a general purpose directory that would be created particularly for NFS so as to demonstrate the proper settings and processes. The same would be located at /var/nfs As the /home directory already exists, let us simply go ahead and begin by creating the /var/nfsdirectory, using the following command:
sudo mkdir /var/nfs
We now have a new directory expressly designated for sharing with remote hosts. However, the ownership of this directory is not yet ideal. We must assign user ownership to a user on our system named noone. We must also assign the group ownership to a group on the system named anygroup. This can be done by keying in the following command:
sudo chown noone:anygroup /var/nfs
It is important to note here that we must carefully change the ownership on only those directories that are particularly used for sharing. For instance, the ownership of the home directory (/home directory) must not be changed as it would cause numerous problems for users present on the host server.
1.5 Configuring the NFS Exports on the Host Server
With the directories created and assigned, we can now take a plunge into the NFS configuration file in order to set up the sharing of these resources. For that, you must open the /etc/exports file in the text editor with root privileges using the following command:
sudo nano /etc/exports
The files that will appear would contain a few comments to apprise you of the general structure of each configuration line. Essentially, the syntax would be similar to the following::
directory_to_share client (share_option2,...,share_optionM)
The aim here is to be able to create a line for each of the directories that must be shared. Since, in our chosen example, the IP happens to be 333.333.333.333, the lines should look something like the following: /home 333.333.333.333(rw,sync,no_root_squash,no_subtree_check) /var/nfs 333.333.333.333(rw,sync,no_subtree_check) Let us now take a while to understand the options given in the lines above.
- rw: This option allows the client computer read as well as write access to the volume.
- sync: It forces NFS to write changes to the disk before replying, thus resulting in a more stable and consistent environment. This is primarily because the reply replicates the actual state of the remote volume.
- nosubtreecheck: This option averts subtree checking, which is a process that compels the host to check if the file is actually still available in the exported tree for each request. It may create problems when a file is renamed while the client has it opened. For the same reason, in roughly all the cases, it is advisable to disable subtree checking.
- norootsquash: By default, the NFS translates requests from a root user remotely into a non-privileged one on the server. This is meant to be a security feature that does not allow a root account on the client to use the filesystem of the host as root. This kind of a directive disables this for a certain lot of shares.
Once you have made all the requisite changes, quite predictably, you must make the changes, and save these changes before closing the file. Subsequently, you must create the NFS table that holds the exports of your shares by using the following command:
sudo exportfs -a
However, the NFS service is not as yet running. You may start the same by typing the following command:
sudo service nfs-kernel-server start
The above command shall make your shares available to the clients that you would have configured. You are now ready to move on to the next step.
1.6 Creating the Mount Points and Mount Remote Shares on the Client Server
With the host server configured and making its directory shares available, you would now need to prep your client. Here, you would be required to mount the remote shares, hence you need to create a few mount points. You would be using the conventional /mnt to begin with, and subsequently create a directory called NFS under it to consolidate the shares. Here, the actual directories shall correspond with their location on the host server. Users can create each directory, and the necessary parent directories, by using the following command:
sudo mkdir -p /mnt/nfs/home
sudo mkdir -p /mnt/nfs/var/nfs
Having created a decent place to house the remote shares, you are now in a position to mount them by addressing the host server, which, for the purpose of this tutorial is 5.6.7.8, as shown below:
sudo mount 5.6.7.8:/home /mnt/nfs/home
sudo mount 5.6.7.8:/var/nfs /mnt/nfs/var/nfs
These should let you mount the shares from the host computer onto the client machine. You may double check this by looking at the available disk space on the client server (as given below):
df -h Filesystem Size Used Avail Use% Mounted on /dev/vda 59G 1.3G 55G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 2.0G 12K 2.0G 1% /dev tmpfs 396M 324K 396M 1% /run none 5.0M 0 5.0M 0% /run/lock none 2.0G 0 2.0G 0% /run/shm none 100M 0 100M 0% /run/user 5.6.7.8:/home 59G 1.3G 55G 3% /mnt/nfs/home
As is evident at the bottom, only one of the intended shares is visible because both of the exported shares exist on the same filesystem on the remote server, which means they share the same pool of storage. For the Avail and Use% columns to be accurate, only one of the shares may be added into the calculations. Nonetheless, if you wish to view all of the NFS shares that you have mounted, you may type the following command:
mount -t nfs 5.6.7.8:/home on /mnt/nfs/home type nfs (rw,vers=4,addr=5.6.7.8,clientaddr=333.333.333.333) 5.6.7.8:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=5.6.7.8,clientaddr=333.333.333.333)
The above command will throw up the entire lot of NFS mounts that are currently accessible on the client machine, which brings you to the end of this step, and it is now time to move on to the next one.
1.7 Testing NFS Access
You may test the shares access by writing something to your shares, for instance, a test file to one of your shares (as shown below):
sudo touch /mnt/nfs/home/test_home
Here, we shall also write test file to the other share to demonstrate an important difference:
sudo touch /mnt/nfs/var/nfs/test_var_nfs
Please look carefully at the ownership of the file in the mounted home directory (as shown below) to understand the difference:
ls -l /mnt/nfs/home/test_home -rw-r--r-- 1 root root 0 Apr 27 12:58 test_home
As is evident, the file is owned by root, the reason being that you.deactivated the root_squash option on this mount, which would have written the file as an unknown, non-root user. On the other test file, which was mounted with the root_squash enabled, you will notice something entirely different (as explained below):
ls -l /mnt/nfs/var/nfs/test_var_nfs -rw-r--r-- 1 noone anybody 0 Apr 27 12:58 test_var_nfs
Clearly, this file was assigned to the noone user and the anybody group. Hence, this conforms to the preset configuration. Let us now move on to the next step.
1.8 Making Remote NFS Directory Mounting Automatic
You enjoy the option of making the remote NFS shares mounting automatic by adding it to the fstabfile on the client. You need to open this file with root privileges in your text editor by using the following command:
sudo nano /etc/fstab
Right at the bottom of the file, you need to add a line for each of the shares, which would look something like what is given below:
5.6.7.8:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0 5.6.7.8:/var/nfs /mnt/nfs/var/nfs nfs auto,noatime,nolock,bg,nfsvers=4,sec=krb5p,intr,tcp,actimeo=1800 0 0
The options specified here may be found in the man page that describes NFS mounting in the fstab file, by using the following command:
man nfs
This will enable you to automatically mount the remote partitions at boot. It may take a while for the connection to be made and the shares to be available (patience is going to be a virtue here!!)
1.9 Unmounting an NFS Remote Share
If you do not require the remote directory to be mounted on your system any longer, you may unmount it easily by moving out of the share's directory structure and unmounting, using the following command:
cd ~
sudo umount /mnt/nfs/home
sudo umount /mnt/nfs/var/nfs
This shall allow you to remove the remote shares, rendering only your local storage accessible:
df -h Filesystem Size Used Avail Use% Mounted on /dev/vda 59G 1.3G 55G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 2.0G 12K 2.0G 1% /dev tmpfs 396M 320K 396M 1% /run none 5.0M 0 5.0M 0% /run/lock none 2.0G 0 2.0G 0% /run/shm none 100M 0 100M 0% /run/user
As is clear, the NFS shares are now not available as storage space. This brings you to the end of the tutorial.
1.10 Wrap Up
NFS offers a simple and swift mechanism to access remote systems over a network. However, the protocol stands unencrypted. If you intend to use this in a production environment, it is advisable to consider routing NFS over SSH or a VPN connection so as to create a far more secure experience.
转载:http://www.howtoforge.com/how-to-configure-a-nfs-server-and-mount-nfs-shares-on-ubuntu-14.04
相关推荐
标题中的"ubuntu14.01.5-16.04.5-18.04.1BT.zip"表明这是一个包含Ubuntu操作系统不同版本的BT种子文件集合,时间跨度从14.01.5到16.04.5再到18.04.1。Ubuntu是一个基于Debian的开源Linux发行版,广泛用于个人电脑、...
Ubuntu 14.01是这个实践的测试环境。 首先,我们需要理解ELF文件结构。ELF文件包含程序头表和节区头表,它们定义了程序的入口点、内存布局以及代码和数据的位置。动态链接库(.so文件)则是在运行时被加载到进程...
Ubuntu配置时候使用。TFTP配资好了,挂在好了才能在开发板上传输数据
ubuntu14.01镜像
SIMCA14.01用户指南Content The help is parted into 16 chapters, two appendices, and a reference list. 1. How to get started 2. Introduction to multivariate data analysis 3. Overview of SIMCA 4. Quick ...
《DynamicSkinForm VCL D6 - XE10.2 v14.01:Delphi中的动态皮肤框架解析》 DynamicSkinForm VCL D6 - XE10.2 v14.01是一款专为Delphi开发环境设计的组件库,它允许开发者为他们的应用程序创建具有动态皮肤功能的...
标题中的"tomato_dual_14.01.0043"和描述中的"tomato_dual_15.02.0043"提到的是Tomato固件的一个特定版本,这是一款针对网络路由器的第三方固件。Tomato是由Shibby等人开发的开源项目,它基于Linux内核,提供了比...
2011/02/14.01 2011/02/14.01
4. **使用流程**:使用ALCOR MP工具量产U盘,首先需要正确识别U盘的主控型号,然后选择相应的驱动和配置文件。接着,按照工具的界面提示,依次进行初始化、分区设置、固件更新等步骤。最后,确认所有设置无误后,...
**VisualRoute v14.01 知识点详解** VisualRoute是一款强大的网络诊断工具,专为用户提供直观的网络路由追踪和性能分析功能。通过这款软件,用户可以清晰地了解到数据包从源到目标网络需要经过多少个跃点,以及这些...
tomato-K26USB-14.01.0043-MIPSR2-8M.trx
10053 工程数学14.01.doc
tomato-K26USB-14.01.0043-MIPSR1-8M 固件,亲测可以正常使用!
我只在 Ubuntu 14.01 和测试过这个脚本。 要在 Ubuntu 中安装LaTeX发行版,请在终端中键入 sudo apt-get install texlive-full 要在 Ubuntu 中安装dvipng ,请在终端中键入 sudo apt-get install dvi
这通常包括设置环境、获取AOSP(Android Open Source Project)代码库、配置编译选项,并使用`repo`和`mm`命令来构建整个系统。这个过程对理解Android的构建流程至关重要。 接着,可能会详细讲解Android的内核和...
Pixi-Pan-and-Zoom 这是什么: 关于如何在 PixiJS 中实现平移... 没有完全跨浏览器检查,我在 Ubuntu 14.01 上使用了最新版本的 Chrome 和 Firefox 未在手机上测试。 它可能不起作用,但可以很容易地扩展到触摸设备。
VTCP是虚拟TCP协议缩写,它实现了UDP可靠传输,UDP本来是一种不可靠的网络协议,但在有些情况下UDP协议可能会变得非常有用。因为UDP具有TCP所望尘莫及的速度优势。因此我们设计出了一种新的可靠UDP协议(VTCP),自动...
18.09.2018 AlphaControls v14.01 Beta released * Added CloseBtnOffsetX and CloseBtnOffsetY properties in the TsFrameBar items * Fixed error of page closing in the TsPageControl * Fixed error in the...
《DynamicSkinFormV14.01_VCL_D6 - XE10.2_FullSource:Delphi中的动态皮肤框架深度解析》 在Delphi编程领域,动态皮肤功能是提升用户界面美观度和交互体验的重要手段。"DynamicSkinFormV14.01_VCL_D6 - XE10.2_...
软件介绍: 2014最新版本的安国AU698X系列主控U盘量产工具,本版本支持L85系列,修复了之前版本中软件所存在的问题。改善了对更多FLASH的支持,增加了2个全面扫描级别的功能。使用本程序可以轻松制作U盘启动盘,...