使用NFS与Vagrant不起作用。

9

我在我的Vagrantfile中有以下内容:

config.vm.network :private_network, ip: "10.0.0.103"
config.vm.synced_folder ".", "/vagrant/", type: "nfs"

在全新的虚拟机上执行 vagrant up 命令会出现以下情况:
==> default: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mount -o 'vers=3,udp' 10.0.0.1:'/Users/wayne/app' /vagrant

Stdout from the command:



Stderr from the command:

stdin: is not a tty
mount.nfs: access denied by server while mounting 10.0.0.1:/Users/wayne/app

我需要运行vagrant reload,然后它似乎可以正常工作... 但是我不应该这样做吧?
[更新:日志输出]
INFO retryable: Retryable exception raised: #<Vagrant::Errors::LinuxNFSMountFailed: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mount -o 'vers=3,udp' 10.0.0.1:'/Users/wayne/sonatribe' /vagrant

Stdout from the command:



Stderr from the command:

stdin: is not a tty
mount.nfs: requested NFS version or transport protocol is not supported
>
 INFO ssh: Execute: mount -o 'vers=3,udp' 10.0.0.1:'/Users/wayne/sonatribe' /vagrant (sudo=true)
 INFO retryable: Retryable exception raised: #<Vagrant::Errors::LinuxNFSMountFailed: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mount -o 'vers=3,udp' 10.0.0.1:'/Users/wayne/sonatribe' /vagrant

Stdout from the command:



Stderr from the command:

stdin: is not a tty
mount.nfs: requested NFS version or transport protocol is not supported

你使用哪个操作系统?另外,你说重新加载实际上可以让NFS工作? - Hassan
主机是OSX Yosemite,客户机是XUbuntu,重新加载允许NFS工作 - 重新加载时我不需要重新输入密码,但它可以工作。 - user156888
执行命令"VAGRANT_LOG=info vagrant up"并将输出粘贴。 - Hassan
@Hassan 完成 - 看起来关键是:mount.nfs:请求的NFS版本或传输协议不受支持。 - user156888
降级并将基础镜像更改为LTS Ubuntu(而不是XUbuntu)似乎解决了这个问题。 - user156888
7个回答

7

对于 Linux,我在主机上执行以下操作:

systemctl stop nfs-kernel-server.service
systemctl disable nfs-kernel-server.service
systemctl enable nfs-kernel-server.service
systemctl start nfs-kernel-server.service

你是在主机上还是在客户机上做的?谢谢 - Sliq
1
我是在主机上完成的。 - Oleksandr Fedorov
2
仅适用于Linux系统,不支持macOS和Windows操作系统。 - Sliq

3
由于操作系统补丁和软件包升级,我的Vagrant环境停止工作,浪费了我约4个小时的时间。以下是我解决问题的方法:我使用的是Ubuntu 18.04和Vbox 6。
  1. 使用命令 vagrant plugin install vagrant-vbguest 重新安装vagrant vbguest插件
  2. 确保vbox客户端插件与VirtualBox版本匹配。最好安装最新版下载 VBox Guest Additions
  3. 一些NFS包可能会丢失,所以请使用sudo apt-get install -y nfs-server 命令安装
  4. 重启电脑
  5. 使用管理员权限运行以下命令

    sudo systemctl stop nfs-kernel-server.service
    sudo systemctl disable nfs-kernel-server.service
    sudo systemctl enable nfs-kernel-server.service
    sudo systemctl start nfs-kernel-server.service
    
  6. 为了保险起见,我执行了vagrant destroyvagrant global-status --prune


1
TL;DR - 确保/etc/exports中所有条目指向存在的文件夹。如果您删除或重命名了以前配置为NFS共享的任何文件夹,则可能会导致将来在主机和客户端VM之间启动NFS共享的所有尝试失败。
这个帖子仍然是搜索结果中此错误的顶级结果,还有另一个可能的潜在原因-在/etc/exports中挂载失败。
NFS服务器将从/etc/exports读取其挂载列表,如果其中配置的条目不再有效(例如,您移动/重命名/删除了文件夹),它将导致NFS服务器无法启动。命令因操作系统而异,但如果您检查NFS服务器的状态,您可能会发现NFS由于/etc/exports中的配置问题而无法启动。

1
这可能是由于主机VirtualBox和Guest Additions版本不匹配引起的。在这种情况下,在您的启动日志中出现错误行之前,您应该会看到:
  ==> default: Checking for guest additions in VM...
  default: The guest additions on this VM do not match the installed version of
  default: VirtualBox! In most cases this is fine, but in rare cases it can
  default: prevent things such as shared folders from working properly. If you see
  default: shared folder errors, please make sure the guest additions within the
  default: virtual machine match the version of VirtualBox you have installed on
  default: your host and reload your VM.
  default:
  default: Guest Additions Version: 5.0.26
  default: VirtualBox Version: 5.1

在我的情况下,将VirtualBox更新到最新版本解决了问题。
或者,您可以使用vbguest Vagrant插件在主机上安装正确的Guest Addition版本:
vagrant plugin install vagrant-vbguest

1
这并没有解决问题。我在使用ansible之前安装了vagrant-vbguest,但是仍然出现错误。 - nbro

0

降级并将基础镜像更改为LTS Ubuntu(而不是XUbuntu)似乎解决了这个问题。


0

我通过将虚拟机IP地址中的最后一个数字改为大于1来解决了这个问题。例如(192.168.10.1->不工作,192.168.10.2->工作)


0

就像这里所描述的,有时在你的Linux发行版上没有安装nfs-server会导致这种情况发生。这里解释了如何根据你的发行版安装它。对我来说今天有效。o/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接