Avahi在Centos 7 Vagrant VirtualBox环境中不起作用

时间:2019-01-22 10:46:48

标签: vagrant virtualbox centos7 avahi

我正在尝试建立一个专用网络,使计算机可以使用其主机名相互通信。例如

$ vagrant@master: ssh vagrant@node1
$ vagrant@node1: hostname # logged in to node1 from master
node1.example.com
$ vagrant@node1: ssh vagrant@node1 # logged in to master from node1
$ vagrant@master: hostname
master.example.com

Avahi是最优选的选择。但是,我正在努力使其在Centos 7上运行。类似的设置在Linux环境下也可以正常工作。

这是Vagrant文​​件,以便您可以复制相同的环境。

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
BOX_IMAGE = "centos/7"
NODE_COUNT = 2

Vagrant.configure("2") do |config|
  config.vm.define "master" do |subconfig|
    subconfig.vm.box = BOX_IMAGE
    subconfig.vm.hostname = "master.example.com"
    subconfig.vm.network :private_network, ip: "10.0.0.10"
    subconfig.vm.network "forwarded_port", guest: 80, host: 8090
  end

  (1..NODE_COUNT).each do |i|
    config.vm.define "node#{i}" do |subconfig|
      subconfig.vm.box = BOX_IMAGE
      subconfig.vm.hostname = "node#{i}.example.com"
      subconfig.vm.network :private_network, ip: "10.0.0.#{i + 10}"
      subconfig.vm.network "forwarded_port", guest: 80, host: "809#{i + 1}"
    end
  end

  # Install avahi on all machines  
  config.vm.provision "shell", inline: <<-SHELL
    yum install -y avahi nss-mdns
    systemctl start avahi-daemon.service
    systemctl status avahi-daemon.service
  SHELL
end

最好能使它正常工作,如果还有其他方法,我也很乐意尝试。

0 个答案:

没有答案