How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu

NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980.
It allows you to mount your local file systems over a network and
remote hosts to interact with them as they are mounted locally on the
same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.

Setup NFS Server and NFS Client in Linux

Benefits of NFS
  1. NFS allows local access to remote files.
  2. It uses standard client/server architecture for file sharing between all *nix based machines.
  3. With NFS it is not necessary that both machines run on the same OS.
  4. With the help of NFS we can configure centralized storage solutions.
  5. Users get their data irrespective of physical location.
  6. No manual refresh needed for new files.
  7. Newer version of NFS also supports acl, pseudo root mounts.
  8. Can be secured with Firewalls and Kerberos.
NFS Services

Its a System V-launched service. The NFS server package includes three facilities, included in the portmap and nfs-utils packages.

  1. portmap : It maps calls made from other machines to the correct RPC service (not required with NFSv4).
  2. nfs: It translates remote file sharing requests into requests on the local file system.
  3. rpc.mountd: This service is responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
  1. /etc/exports : Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  2. /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  3. /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other services are listening.

Setup and Configure NFS Mounts on Linux Server

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

  1. NFS Server: nfsserver.example.com with IP-192.168.0.100
  2. NFS Client : nfsclient.example.com with IP-192.168.0.101
Installing NFS Server and NFS Client

We need to install NFS packages on our NFS Server as well as on NFS Client machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package installers.

[[email protected] ~]# yum install nfs-utils nfs-utils-lib
[[email protected] ~]# yum install portmap (not required with NFSv4)
[[email protected] ~]# apt-get install nfs-utils nfs-utils-lib

Now start the services on both machines.

[[email protected] ~]# /etc/init.d/portmap start
[[email protected] ~]# /etc/init.d/nfs start
[[email protected] ~]# chkconfig --level 35 portmap on
[[email protected] ~]# chkconfig --level 35 nfs on

After installing packages and starting services on both the machines, we need to configure both the machines for file sharing.

Setting Up the NFS Server

First we will be configuring the NFS server.

Configure Export directory

For sharing a directory with NFS, we need to make an entry in “/etc/exports” configuration file. Here I’ll be creating a new directory named “nfsshare” in “/” partition to share with client server, you can also share an already existing directory with NFS.

[[email protected] ~]# mkdir /nfsshare

Now we need to make an entry in “/etc/exports” and restart the services to make our directory shareable in the network.

[[email protected] ~]# vi /etc/exports

/nfsshare 192.168.0.101(rw,sync,no_root_squash)

In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP “192.168.0.101” with read and write (rw) privilege, you can also use hostname of the client in the place of IP in above example.

NFS Options

Some other options we can use in “/etc/exports” file for file sharing is as follows.

  1. ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  2. rw: This option allows the client server to both read and write access within the shared directory.
  3. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  4. no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  5. no_root_squash: This phrase allows root to connect to the designated directory.

For more options with “/etc/exports“, you are recommended to read the man pages for export.

Setting Up the NFS Client

After configuring the NFS server, we need to mount that shared directory or partition in the client server.

Mount Shared Directories on NFS Client

Now at the NFS client end, we need to mount
that directory in our server to access it locally. To do so, first we
need to find out that shares available on the remote server or NFS
Server.

[[email protected] ~]# showmount -e 192.168.0.100

Export list for 192.168.0.100:
/nfsshare 192.168.0.101

Above command shows that a directory named “nfsshare” is available at “192.168.0.100” to share with your server.

Mount Shared NFS Directory

To mount that shared NFS directory we can use following mount command.

[[email protected] ~]# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare

The above command will mount that shared directory in “/mnt/nfsshare” on the client server. You can verify it following command.

[[email protected] ~]# mount | grep nfs

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.100:/nfsshare on /mnt type nfs (rw,addr=192.168.0.100)

The above mount command mounted the nfs shared directory on to nfs client temporarily, to mount an NFS directory permanently on your system across the reboots, we need to make an entry in “/etc/fstab“.

[[email protected] ~]# vi /etc/fstab

Add the following new line as shown below.

192.168.0.100:/nfsshare /mnt  nfs defauls 0 0

Test the Working of NFS Setup

We can test our NFS server setup by creating a test file on the server end and check its availability at nfs client side or vice-versa.

At the nfsserver end

I have created a new text file named “nfstest.txt’ in that shared directory.

[[email protected] ~]# cat > /nfsshare/nfstest.txt

This is a test file to test the working of NFS server setup.
At the nfsclient end

Go to that shared directory in client server and you’ll find that shared file without any manual refresh or service restart.

[[email protected]]# ll /mnt/nfsshare
total 4
-rw-r--r-- 1 root root 61 Sep 21 21:44 nfstest.txt
[email protected] ~]# cat /mnt/nfsshare/nfstest.txt
This is a test file to test the working of NFS server setup.

Removing the NFS Mount

If you want to unmount that shared directory from your server after you are done with the file sharing, you can simply unmount that particular directory with “umount” command. See this example below.

[email protected] ~]# umount /mnt/nfsshare

You can see that the mounts were removed by then looking at the filesystem again.

[[email protected] ~]# df -h -F nfs

You’ll see that those shared directories are not available any more.

Important commands for NFS

Some more important commands for NFS.

  1. showmount -e : Shows the available shares on your local machine
  2. showmount -e <server-ip or hostname>: Lists the available shares at the remote server
  3. showmount -d : Lists all the sub directories
  4. exportfs -v : Displays a list of shares files and options on a server
  5. exportfs -a : Exports all shares listed in /etc/exports, or given name
  6. exportfs -u : Unexports all shares listed in /etc/exports, or given name
  7. exportfs -r : Refresh the server’s list after modifying /etc/exports

This is it with NFS mounts for now, this was just a start, I’ll come up with more option and features of NFS in our future articles. Till then, Stay connected with Tecmint.com for more exciting and interesting tutorials in future. Do leave your comments and suggestions below in the comment box.

How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu

时间: 2024-10-13 15:54:12

How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu的相关文章

如何设置 NFS (Network File System) 在 RHEL/CentOS/Fedora and Debian/Ubuntu

1. 为了安装NFS挂载,需要至少2台Linux/Unix机器,如下: NFS Server:192.168.0.100 NFS Client:192.168.0.101 2. 安装NFS服务器端和客户端: yum install nfs-utils nfs-utils-lib yum install portmap (not required with NFSv4) 3.

名字就叫&quot;nfs&quot;-(network file system)

一.简介   NFS(network file system)网络文件系统.通过网络让不同的主机系统之间可以实现文件或目录共享.分为客户端和服务器,NFS网络文件系统很像windows系统的网络共享.安全功能.网络驱动器和Samba服务类似. 二.安装及其配置 服务器端配置如下: 1)安装nfs-utils和rpcbind两包 yum -y install nfs-utils rpcbind 2)启动服务 service nfs start或/etc/init.d/nfs start    /e

NFS (Network File System) 服务器共享多个目录

NFS是Network File System的缩写,即网络文件系统,这里不再详细讲解NFS的配置,具体配置看这篇博客CentOS 6 nfs共享存储配置.这里重点说的是在服务器端共享多个文件夹. 1.配置/etc/exports文件 假设服务器端要共享的目录是/var/shared/folder1 和 /var/shared/folder2.客户端要分别将这两个目录挂载到 /var/folder1 和 /var/folder2.则/etc/exports文件的配置为: <span style=

NFS - Network File System网络文件系统

NFS(Network File System/网络文件系统): 设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务): NFS只是一种文件系统,本身没有传输功能,是基于RPC协议实现的,才能达到两个Linux系统之间的文件目录共享: NFS为C/S架构: NFS 的基本原则是“容许不同的客户端及服务端通过一组RPC分享相同的文件系统”,它是独立于操作系统,容许不同硬件及操作系统的系统共同进行文件的分享. NFS在文件传送或信息传送过程中依赖于RPC协议.

CentOS7 配置NFS(Network File System)及其使用

1.       服务端配置 1.1.    安装NFS yum -y install nfs* 1.2.    查看是否安装了NFS与RPCBIND rpm -qa | grep nfs rpm -qa | grep rpcbind 1.3.    创建共享目录并共享 1.3.1.  mkdir /mnt/nfs mkdir /mnt/nfs 1.3.2.  vim /etc/exports vim /etc/exports /mnt/nfs 192.168.58.130/*(rw,ro,no

NFS(Network File System)服务配置和使用

Sun公司开发NFS (Network File System)之初就是为了在不同linux/Unix系统之间共享文件或者文件夹.可以在本地通过网络挂载远程主机的共享文件,和远程主机交互.NFS共享存储对初学者来说不太好理解,我看到过一个很好的例子,假如有三台机器A.B.C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A.B.C.但是使用NFS只需要放到A上,然后A共享给B和C即可.访问的时候,B和C是通过网络的方式去访问A上的那个目录的. 一.NFS的优势 允许本地获

NFS中小企业常见的网络文件系统服务(network file system)

NFS中小企业常见的网络文件系统服务(network file system) RPC服务最主要的功能就是记录每个NFS功能所对应的端口号,并在NFS客服端请求时将该端口和功能对应的信息传递个给请求数据的NFS客服端 流程: 1,先开启RPC服务 2,再启动NFS服务 3,NFS服务向RPC注册启动的端口 4,客服请求NFS服务 5,RPC返回端口给客服端 环境搭建: 服务端为 nfsserver  客服端为 nfsclient NFS服务需要安装的软件包: yum install nfs-ut

NFS (Network File System网络文件系统)

NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样前提 关闭selinux强制模式>>>服务端安装nfs-utils开启服务加入防火墙机制nfs,mountd,rpc-bind,加载查看已添加建立本地主机解析文件vim /etc/hosts建立文件/test_nfs编辑主配置文件同

Network File System

Network File System 2014-12-31 #system 接着上一篇博客Distributed Systems 分布式系统来扯淡,之前的博客一再在写文件系统,这次继续,只不过是分布式文件系统. 1. 这篇文章讲什么 这篇文章介绍一种分布式文件系统,名字叫Network File Sytem(NFS),翻译过来就是网络文件系统.NFS是一种分布式文件系统,大概的样子是这样的:  这里多说一句,NFS可不是仅仅指图中那个server,它包含了图中的所有部件 ,client中也有N