使用NFS的Vagrant CentOS8无法挂载:mount.nfs:不支持请求的NFS版本或传输协议

问题描述

我正在尝试为使用Jeff Geerling's packer-boxes repo构建的CentOS 8计算机做vagrant up

我的Vagrantfile看起来像这样。

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.ssh.insert_key = false
  config.vm.synced_folder '.','/vagrant',type: 'nfs'

  # VirtualBox.
  config.vm.define "virtualBox" do |virtualBox|
    virtualBox.vm.hostname = "virtualBox-centos8"
    virtualBox.vm.Box = "file://builds/virtualBox-centos8.Box"
    virtualBox.vm.network :private_network,ip: "172.16.9.29"
    virtualBox.vbguest.auto_update = true

    config.vm.provider :virtualBox do |v|      v.gui = false
      v.memory = 1024
      v.cpus = 1
      v.customize ["modifyvm",:id,"--natdnshostresolver1","on"]
      v.customize ["modifyvm","--ioapic","on"]
    end

    config.vm.provision "shell",inline: "echo Hello,World"
  end

end

我收到此错误消息,指出它无法使用NFS。

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command Failed!

mount -o vers=3 172.16.9.1:/home/bcrice/projects/packer-Boxes/centos8 /vagrant

Stdout from the command:



Stderr from the command:

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

我尝试了这里发布的所有技巧,但没有成功。

https://github.com/hashicorp/vagrant/issues/9666

我正在使用此版本的Ubuntu桌面

disTRIB_ID=Ubuntu
disTRIB_RELEASE=20.04
disTRIB_CODENAME=focal
disTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"

主机上的VirtualBox dpkg -l | grep virtualBox | awk'{print $ 3}'

6.1.10-dfsg-1~ubuntu1.20.04.1
6.1.10-dfsg-1~ubuntu1.20.04.1
6.1.10-1~ubuntu1.20.04.1
6.1.10-dfsg-1~ubuntu1.20.04.1

VirtualBox中的客人说它正在运行guest-utils

vagrant vbguest --status
[virtualBox] GuestAdditions 6.1.10 running --- OK.

我的/ etc / exports正确地自动添加了条目,但是它不起作用

cat /etc/exports
# VAGRANT-BEGIN: 1000 2b82110e-78ed-489e-891e-c80e073c4f73
"/home/bcrice/packer-Boxes/centos8" 172.16.9.29(rw,no_subtree_check,all_squash,anonuid=1000,anongid=1000,fsid=187307313)
# VAGRANT-END: 1000 2b82110e-78ed-489e-891e-c80e073c4f73

解决方法

需要执行apt install nfs-kernel-server。尽管systemctl status nfs-kernel-server表示它正在运行,但实际上并未安装。安装完成后,请执行systemctl重新启动nfs-kernel-server并成功。

一个不错的礼物是,当我运行exportfs时,它说未安装nfs-kernel-server。

运行dpkg -l | grep nfs-kernel-server并仔细检查是否已安装。