Vagrant NFS 共享不再起作用

Vagrant NFS 共享不再起作用

以下 Vagrantfile 以前可以工作,但现在不工作了。

这是 Ubuntu 20.04 安装,我正在使用 Virtualbox。

Vagrant.configure('2') do |config|
  # Set Box
  config.vm.box = "generic/ubuntu2004"
  # Set hostname
  config.vm.hostname = "xxx"
  config.vm.define "xxx"
  config.vm.provider :virtualbox do |vb|
    vb.name = "xxx"
  end

  # Prevent vagrant-vbguests from being auto updated, this is time consuming and causes version mismatch with host
  if Vagrant.has_plugin? "vagrant-vbguest"
    config.vbguest.no_install  = false
    config.vbguest.auto_update = false
    config.vbguest.no_remote   = true
  end

  # Enable vagrant-bindfs support, if the plugin is installed
  # see https://github.com/gael-ian/vagrant-bindfs for details
  if Vagrant.has_plugin?("vagrant-bindfs")
    # The bindfs option has one more option, and the /var/nfs
    # is where the the folder is synced then it binds it to the
    # guest_path after.
    #
    # Ubuntu 22.04 has UDP disabled for NFS mounts
    # https://discourse.ubuntu.com/t/jammy-jellyfish-release-notes/24668

    config.vm.synced_folder ".", "/var/nfs", type: "nfs", nfs_udp: false

    # This uses uid and gid of the user that started vagrant.
    config.nfs.map_uid = Process.uid
    config.nfs.map_gid = Process.gid

    config.bindfs.bind_folder "/var/nfs", "/vagrant",
      perms: 'u=rwX:g=rwD',
      u: 'vagrant',
      g: 'www-data',
      o: 'nonempty'
  else
    # Enable NFS file system
    config.vm.synced_folder ".", "/vagrant", type: "nfs",  nfs_udp: false

    # This uses uid and gid of the user that started vagrant.
    config.nfs.map_uid = Process.uid
    config.nfs.map_gid = Process.gid
  end

  # This uses the vagrant-disksize support, if the plugin is installed
  if Vagrant.has_plugin?("vagrant-disksize")
    config.disksize.size = '20GB'
  end

  # Configure RAM
  config.vm.provider "virtualbox" do |vb|
    # Customize the amount of memory on the VM:
    vb.memory = "4096"
    vb.cpus = 2
  end

  # Specify private network
  config.vm.network "private_network", ip: "192.168.56.10"
  # Port requires for postgres
  config.vm.network :forwarded_port, guest: 5432, host: 5432
  config.vm.network :forwarded_port, guest: 80, host: 8080

  # Enable provisioning with a shell script.
  # config.vm.provision :shell, :path => "local/bootstrap.sh"

end

我收到的错误是:

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

mount -o vers=3 192.168.56.1:/home/steve/Projects/ze /var/nfs

Stdout from the command:

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

每次测试时我都会先运行 vagrant destroy,然后再运行 vagrant up。我做了以下操作:

  • 允许 vbguests 运行并更新
  • 尝试过 NFS 版本 4
  • 尝试不使用 NFS(安装完成,但无法正常工作)
  • 尝试将“192.168.56.1”作为主机 IP
  • 最初使用 Vagrant 2.3.4,升级到 2.3.7(并再次尝试一切)
  • 尝试在虚拟机内部进行挂载,结果通常是这样的:
sudo mount -o vers=3 192.168.56.1:/home/steve/Projects/ze /var/nfs -v

mount.nfs: timeout set for Mon Jul  3 09:06:25 2023
mount.nfs: trying text-based options 'vers=3,addr=192.168.56.1'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: portmap query retrying: RPC: Program not registered
mount.nfs: prog 100003, trying vers=3, prot=17
mount.nfs: portmap query failed: RPC: Program not registered
mount.nfs: requested NFS version or transport protocol is not supported

我正在失去生存的意志,因此任何帮助我都会感激不尽。

答案1

好的。

我最终发现(使用 nmap)NFS 没有在主机上运行,​​这是因为有一个条目链接/etc/exports到一个不再存在的目录,所以 NFS 初始化失败。

使用发现的详细信息systemctl status nfs-server

这意味着当尝试挂载 NFS 共享文件夹时,连接被拒绝并且挂载失败。

当我尝试使用 vers=4 进行挂载时,发现了第一个线索,其中包含“拒绝”错误消息。

相关内容