首页 文章

使用vagrant设置集群

提问于
浏览
0

我想使用Vagrant创建一个包含4个CentOS VM的集群 . 我在Widnows机器上安装了Vagrant和VirtualBox,下载了CentOS 64盒并创建了集群 . Steps

  • 执行'vagrant box add --name centos65-base'

  • 执行'vagrant init centos65-base'

  • 编辑VagrantFile,如下所示:

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

Vagrant.configure(2) do |config|

  config.vm.define :node1 do |node1_config|
    node1_config.vm.box = "centos65_base"
    node1_config.vm.network "private_network", ip: "10.0.2.5"
  end

  config.vm.define :node2 do |node2_config|
    node2_config.vm.box = "centos65_base"
    node2_config.vm.network "private_network", ip: "10.0.2.6"
  end

  config.vm.define :node3 do |node3_config|
    node3_config.vm.box = "centos65_base"
    node3_config.vm.network "private_network", ip: "10.0.2.7"
  end

  config.vm.define :node4 do |node4_config|
    node4_config.vm.box = "centos65_base"
    node4_config.vm.network "private_network", ip: "10.0.2.8"
  end
end
  • 执行'vagrant up'

在第四步结束时,群集的四个节点已配置并启动,这很好 . 我冲进去了 . 我能够从虚拟机成功ping到www.google.com和我的主机 . 但是,从群集中的一个节点ping到另一个节点会出现 "destination host unreachable" 错误 . 我跑了'ifconfig'看到正在使用的网络适配器 . eth0用于DHCP,eth1用于静态ip .

[root@vagrant-centos65 vagrant]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:4F:B8:06
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe4f:b806/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1142 errors:0 dropped:0 overruns:0 frame:0
          TX packets:672 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:106471 (103.9 KiB)  TX bytes:84099 (82.1 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:EC:A0:37
          inet addr:10.0.2.5  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:feec:a037/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:268 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:27329 (26.6 KiB)  TX bytes:482 (482.0 b)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:784 (784.0 b)  TX bytes:784 (784.0 b)

知道如何解决这个问题吗?我需要群集中的VM能够相互通信 .

1 回答

  • 0

    我通过使用192.168.33.10 - 192.168.33.13 IP地址范围而不是10.0.2.5 - 10.0.2.8来解决这个问题,用于静态IP配置 .

    我怀疑使用10.0.2.x范围导致冲突,因为DHCP也使用相同的范围 .

相关问题