Network file system is a simple way to share files and folders over the network. NFS is developed by Sun Microsystems in 1980. NFS is very popular in the Linux and Unix world. NFS is an alternative for SMB which is Windows ecosystem file-sharing protocol. We will look at how to install the NFS server, share files and mount shares in this tutorial with some extra configurations.
网络文件系统是一种通过网络共享文件和文件夹的简单方法。 NFS由Sun Microsystems于1980年开发。NFS在Linux和Unix世界中非常流行。 NFS是Windows生态系统文件共享协议的SMB的替代方案。 在本教程中,我们将通过一些额外的配置来研究如何安装NFS服务器,共享文件和挂载共享。
安装NFS (Install NFS)
可以为Ubuntu,Debian,Kali,Mi安装NFS (Installing NFS can be done for Ubuntu, Debian, Kali, Mi)
Ubuntu,Debian,Kali,Mint: (Ubuntu, Debian, Kali, Mint:)
$ sudo apt install nfs-common
Fedora,CentOS,RedHat: (Fedora, CentOS, RedHat:)
$ yum install nfs-utils.x86_64
人 (Man)
Manpage for NFS daemon or simple server can get like below.
NFS守护程序或简单服务器的联机帮助页如下所示。
$ man nfsd
配置文件(Configuration Files)
NFS server works as a daemon as expected. Daemon configuration file is by default in /etc/default/nfs-kernel-server
for Ubuntu-based systems
NFS服务器按预期方式充当守护程序。 对于基于Ubuntu的系统,默认情况下,守护程序配置文件位于/etc/default/nfs-kernel-server
中
Ubuntu,Debian,Kali,Mint: (Ubuntu, Debian, Kali, Mint:)
/etc/default/nfs-kernel-server
Fedora,CentOS,RedHat: (Fedora, CentOS, RedHat:)
/etc/nfsmount.conf
服务 (Services)
NFS server has more than one service to share files and folders.
NFS服务器具有多个服务来共享文件和文件夹。
汇出档案 (Export File)
Shares are generally defined in different configuration files than daemon configuration files. NFS shares are called exports
and stored into /etc/exports
. Below we can see the default export file.
共享通常在与守护程序配置文件不同的配置文件中定义。 NFS股票称为exports
并存储到/etc/exports
。 在下面我们可以看到默认的导出文件。
As we see in this file some examples of shares are defined in comments which have no effect.
正如我们在此文件中看到的,注释中定义了一些共享示例,这些示例无效。
建立分享 (Create Share)
As stated previously to create share an entry should be created in the export file. We will create a simple entry that does not have advanced attributes. Say our directory we want to share is located at /share
.
如前所述,要创建共享,应在导出文件中创建一个条目。 我们将创建一个没有高级属性的简单条目。 说我们要共享的目录位于/share
。
Put the following line to the /etc/exports
将以下行放入/etc/exports
/share *
重新加载NFS服务器 (Reload NFS Server)
We have to change the configuration of the NFS server and created a new share to enable the new configuration we should reload the server.
我们必须更改NFS服务器的配置并创建新的共享以启用新配置,我们应该重新加载服务器。
Ubuntu,Debian,Kali,Mint: (Ubuntu, Debian, Kali, Mint:)
$ sudo systemctl restart nfs-server.service
Fedora,CentOS,RedHat: (Fedora,CentOS, RedHat:)
systemctl restart nfs-server.service
列出股份(List Shares)
NFS has the ability to list shares. This feature is similar to SMB. We will run list command from our client named ubu2
. While trying to list share there can be an error like clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
which simply means a network access error. Generally, firewalls will prevent access to the NFS service to get a share list. Create appropriate rules to access these services.
NFS可以列出共享。 此功能类似于SMB。 我们将从名为ubu2
的客户端运行list命令。 尝试列出共享时,可能会出现类似clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
的错误clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
,这仅意味着网络访问错误。 通常,防火墙将阻止访问NFS服务以获取共享列表。 创建适当的规则以访问这些服务。
$ showmount -e 192.168.122.179
挂载NFS共享(Mount NFS Share)
NFS shares can be mounted to the local system with regular mount command and NFS related parameters. To mount NFS share NFS file system libraries must be installed which is provided by NFS packages we have previously installed.
可以使用常规安装命令和与NFS相关的参数将NFS共享安装到本地系统。 要挂载NFS共享,必须安装由我们先前安装的NFS软件包提供的NFS文件系统库。
$ mount -t nfs 192.168.122.179:/share mnt
While mounting shares NFS type provided with
-t nfs
在安装时,共享
-t nfs
提供的NFS类型And remote NFS share specified
192.168.122.179:/share
和远程NFS共享指定为
192.168.122.179:/share
Local mount path is working directory
mnt
本地安装路径是工作目录
mnt
卸载NFS (Unmount NFS)
Unmounting is the same as regular disk-based file systems. This will unmount the NFS file system. We will unmount the path /mnt
in this example.
卸载与常规的基于磁盘的文件系统相同。 这将卸载NFS文件系统。 在本示例中,我们将卸载路径/mnt
。
$ sudo umount mnt
翻译自: https://www.poftut.com/linux-nfs-server-setup-configuration-examples/