以下 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
我正在失去生存的意愿,所以任何帮助将不胜感激。
好的。
我最终发现(使用 nmap)NFS 没有在主机上运行,这是因为链接到
/etc/exports
不再存在的目录的条目,因此 NFS 初始化失败。使用发现的详细信息
systemctl status nfs-server
这意味着当尝试挂载 NFS 共享文件夹时,连接被拒绝并且挂载失败。
当我尝试使用 vers=4 进行安装时发现了第一条线索,其中包括“拒绝”错误消息。
您可以尝试以下一些操作:
nfs_version
。例如,要使用 NFS 版本 3,您将使用以下代码:nfs_udp
。例如,要使用 UDP,您可以使用以下代码:如果您已经尝试了所有这些方法,但仍然收到错误,那么您可以尝试将 Vagrantfile 和命令的输出发布
mount
到论坛或邮件列表以寻求帮助。