我尝试使用 vagrant 搭建一个开发环境,其中一段配置文件如下。
(1..NUMBER_OF_WORKER_INSTANCES).each do |i|
vm_name = "%s-%02d" % [WORKER_NAME_PREFIX, i]
vm_static_ip = WORKER_IP_TEMPLATE % [100 + i]
vm_ssh_host_port = "202%01d" % [i]
config.vm.define(vm_name) do |worker|
worker.vm.box = "ubuntu/trusty64"
worker.vm.hostname = vm_name
worker.vm.network "private_network", ip: vm_static_ip
worker.vm.provider :virtualbox do |vb|
vb.name = vm_name
vb.memory = 1024
vb.cpus = 1
vb.customize ["modifyvm", :id, "--nic2", "hostonly"]
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
end
worker.vm.provision "shell", path: "scripts/setup-os.sh", privileged:false
worker.vm.provision "shell", path: "scripts/setup-java.sh", privileged:false
worker.vm.provision "shell" do |s|
s.path = "scripts/setup-flink.sh"
s.args = " -t #{NUMBER_OF_WORKER_INSTANCES}"
s.privileged=false
end
worker.vm.network "forwarded_port", guest: 22, host: vm_ssh_host_port, id: 'ssh'
end
在调试 vagrantfile 的过程中,引入的脚本报错,于是修改之后继续使用 vagrant up 启动虚拟机,这个时候会报错,端口被宿主机占用,我尝试多次更换端口之后 up 或者 reload,发现每一个新换的端口都会被报错占用。请教大家一下这是为什么?
1
mengzhexin OP 这是我将 vm_ssh_host_port 替换成手动随机端口 2282 之后的报错
Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 2282 is already in use on the host machine. |