Linux NFS服务器设置和配置示例

本文详细介绍了如何在Linux(包括Ubuntu, Debian, Kali, CentOS等)上安装和配置NFS服务器,包括安装过程、配置文件详解、创建和挂载共享、服务管理和卸载等步骤,是Linux用户共享文件和目录的实用指南。" 113291121,10538079,Jsp+Ssm+Mysql实现的在线水果商城系统详解,"['JavaWeb', 'Spring框架', 'MyBatis', '数据库设计', '电商系统']
摘要由CSDN通过智能技术生成

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
Install NFS
Install NFS
安装NFS

Fedora,CentOS,RedHat: (Fedora, CentOS, RedHat:)

$ yum install nfs-utils.x86_64
Install NFS
Install NFS
安装NFS

(Man)

Manpage for NFS daemon or simple server can get like below.

NFS守护程序或简单服务器的联机帮助页如下所示。

$ man nfsd
Man
Man

配置文件(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 。 在下面我们可以看到默认的导出文件。

Export files
导出文件

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服务器的配置并创建新的共享以启用新配置,我们应该重新加载服务器。

LEARN MORE  How To Unmount Disk in Linux, Ubuntu, CentOS with umount Command
了解更多如何使用umount命令在Linux,Ubuntu,CentOS中卸载磁盘

Ubuntu,Debian,Kali,Mint: (Ubuntu, Debian, Kali, Mint:)

$ sudo systemctl restart nfs-server.service
Reload NFS Server
Reload NFS Server
重新加载NFS服务器

Fedora,CentOS,RedHat: (Fedora,CentOS, RedHat:)

systemctl restart nfs-server.service
Reload NFS Server
Reload NFS Server
重新加载NFS服务器

列出股份(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
List NFS Shares
List NFS Shares
列出NFS共享

挂载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
Mount NFS Share
Mount NFS Share
挂载NFS共享
  • 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
Unmount NFS
Unmount NFS
卸载NFS

翻译自: https://www.poftut.com/linux-nfs-server-setup-configuration-examples/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值