vagrant配置多机多节点


首先注意:在配置之前先把你的原来的虚拟机打包成box备份。

否则你可能面临惨痛的代价。


下一步,修改配置文件:

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.


  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "ubuntu"


  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false


  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080


  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  
  config.vm.define "slave1" do |slave1|
     config.vm.network "private_network", ip: "192.168.33.10"
  end
  
  config.vm.define "slave2" do |slave2|
     config.vm.network "private_network", ip: "192.168.33.20"
  end

 

只用改上面蓝色的几处就可以了。config.vm.box不会是你把你的虚拟机打包后的自己随意命名的文件名,而是你那个box本来的名字。

如果你大部分启动只启动master,你可以把slave的box和配置文件和master的放在不同目录。





UPDATE:

最新方法;支持共享目录,不过要注意如果是自己的box,要配置密码。


Vagrant.configure("2") do |config|
(1..4).each do |i|
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.define "node#{i}" do |node|
# 设置虚拟机的Box
node.vm.box = "ubuntu2"
# 设置虚拟机的主机名
node.vm.hostname="node#{i}"
# 设置虚拟机的IP
node.vm.network "private_network", ip: "192.168.33.#{i+3}"
# 设置主机与虚拟机的共享目录
node.vm.synced_folder "/share", "/home/vagrant/share"
# VirtaulBox相关配置
node.vm.provider "virtualbox" do |v|
# 设置虚拟机的名称
v.name = "node#{i}"
# 设置虚拟机的内存大小  
v.memory = 2048
# 设置虚拟机的CPU个数
v.cpus = 1
end
end
end


上面方法的最新参考:http://kiwenlau.com/2016/07/03/vagrant-vm-cluster/,感谢这位大神。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值