【问题标题】:Using NFS with vagrant doesn't work将 NFS 与 vagrant 一起使用不起作用
【发布时间】:2014-11-23 12:44:51
【问题描述】:

我的 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 工作?
  • 主机是 OSX Yosemite,来宾是 XUbuntu,重新加载允许 NFS 工作 - 重新加载时我不需要重新输入密码,但它可以工作
  • 执行“VAGRANT_LOG=info vagrant up”并粘贴输出。
  • @Hassan 完成 - 似乎关键是:mount.nfs:不支持请求的 NFS 版本或传输协议
  • 降级并将基础映像更改为 LTS Ubuntu(而不是 XUbuntu)似乎可以解决此问题

标签: vagrant nfs vagrantfile


【解决方案1】:

对于 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

【讨论】:

  • 您是在主机还是在客人中执行此操作?谢谢
  • 我是在主机里做的。
  • 仅供参考,这只适用于 Linux,不适用于 macOS 和 windows
【解决方案2】:

这可能是由于主机 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

【讨论】:

    【解决方案3】:

    将基础映像降级并更改为 LTS Ubuntu(而不是 XUbuntu)似乎可以解决此问题。

    【讨论】:

      【解决方案4】:

      可能由于操作系统修补和软件包升级,我的 Vagrant env 停止工作,让我浪费了大约 4 个宝贵的时间。这就是我设法解决它的方法:我使用 Ubuntu 18.04 和 Vbox 6。

      1. vagrant plugin install vagrant-vbguest重新安装vagrant vbguest插件
      2. 确保 vbox 来宾添加与 VirtualBox 匹配。最好安装最新的Download 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 之间完成了操作

      【讨论】:

        【解决方案5】:

        TL;DR - 检查以确保 /etc/exports 中的所有条目都指向存在的文件夹。如果您删除或重命名了之前配置为 NFS 共享的任何文件夹,则可能会导致以后在主机和客户端虚拟机之间启动 NFS 共享的所有尝试都失败。

        此线程仍然是搜索结果中此错误的首要结果,还有另一个可能的根本原因 - 您的 /etc/exports 中的挂载失败

        NFS 服务器将读取 /etc/exports 以获取其挂载列表,如果其中配置的条目不再有效(例如,您移动/重命名/删除了文件夹),它将导致 nfs 服务器无法启动.命令会因您的操作系统而异,但如果您检查 NFS 服务器的状态,您可能会发现 NFS 由于 /etc/exports 中的配置问题而无法启动。

        【讨论】:

          【解决方案6】:

          here 所述,有时当您的Linux 发行版中没有安装nfs-server 时会发生这种情况。 here 解释了如何根据您的发行版安装它。这对我今天有用。 o/

          【讨论】:

            【解决方案7】:

            我通过将虚拟机 IP 中的最后一个数字更改为高于 1 解决了这个问题。ex(192.168.10.1->not work, 192.168.10.2->work)

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-01-08
              • 1970-01-01
              • 1970-01-01
              • 2022-06-10
              • 1970-01-01
              相关资源
              最近更新 更多