V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mengzhexin
V2EX  ›  问与答

vagrant 端口转发的缓存请教

  •  
  •   mengzhexin · 2019-09-04 21:25:18 +08:00 · 1074 次点击
    这是一个创建于 1935 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我尝试使用 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 条回复    2019-09-04 21:26:47 +08:00
    mengzhexin
        1
    mengzhexin  
    OP
       2019-09-04 21:26:47 +08:00
    这是我将 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.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2191 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 01:54 · PVG 09:54 · LAX 17:54 · JFK 20:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.