# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "ubuntu15.04" config.ssh.insert_key = false config.vm.define "kafka-base" do |server| server.vm.network "private_network", ip: "192.168.33.11" server.vm.hostname = "kafka-base" end config.vm.define "kafka-connector" do |server| server.vm.network "private_network", ip: "192.168.33.12" server.vm.hostname = "kafka-connector" end end
vagrant@kafka-base:~$ hostname kafka-base vagrant@kafka-base:~$ ping kafka-connector ping: unknown host kafka-connector vagrant@kafka-base:~$ cat /etc/hosts 127.0.0.1 kafka-base kafka-base 127.0.0.1 localhost 127.0.1.1 vagrant-ubuntu-trusty.vagrantup.com vagrant-ubuntu-trusty ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
vagrant-hostsというプラグインを入れてみると解決した。
$ vagrant plugin install vagrant-hosts
以下のようにserver.vm.provisionの行を追加すると、ホスト名が設定され、さらにゲストOSの/etc/hostsに仮想マシンのホスト名情報が追記される。
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "ubuntu15.04" config.ssh.insert_key = false config.vm.define "kafka-base" do |server| server.vm.network "private_network", ip: "192.168.33.11" server.vm.provision :hosts, :sync_hosts => true end config.vm.define "kafka-connector" do |server| server.vm.network "private_network", ip: "192.168.33.12" server.vm.provision :hosts, :sync_hosts => true end end
以下のように動作確認してみると、ホスト 名でゲストOS間の通信ができることが分かる。
vagrant@kafka-base:~$ hostname kafka-base vagrant@kafka-base:~$ ping kafka-connector PING kafka-connector (192.168.33.12) 56(84) bytes of data. 64 bytes from kafka-connector (192.168.33.12): icmp_seq=1 ttl=64 time=0.470 ms 64 bytes from kafka-connector (192.168.33.12): icmp_seq=2 ttl=64 time=0.348 ms ^C --- kafka-connector ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1002ms rtt min/avg/max/mdev = 0.348/0.409/0.470/0.061 ms vagrant@kafka-base:~$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 kafka-base 192.168.33.11 kafka-base 192.168.33.12 kafka-connector
0 件のコメント:
コメントを投稿