Vagrant本地集群启动及ssh配置

先放配置文件

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

Vagrant.configure("2") do |config|
  config.vm.define :master1, primary: true do |master|
    master.vm.provider :vmware_desktop do |vmware|
      vmware.vmx["memsize"] = "1024"
      vmware.vmx["numvcpus"] = "2"
      vmware.ssh_info_public = true
      vmware.vmx["ethernet0.pcislotnumber"] = "32"
    end
    master.vm.box = "centos/7"
    master.vm.hostname = "master1"
  end
  (1..2).each do |n|
    config.vm.define "slave#{n}" do |node|
      node.vm.box = "centos/7"
      node.vm.hostname = "slave#{n}"
      node.vm.provider :vmware_desktop do |v|
        v.vmx["memsize"] = "1024"
    v.vmx["numvcpus"] = "2"
    v.ssh_info_public = true
      end
    end
  end
  config.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2222, disabled: true
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.manage_guest = true
  config.vm.box_check_update = false
  config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
  config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "~/.ssh/id_rsa"
  config.ssh.private_key_path = ["~/.ssh/id_rsa", "~/.vagrant.d/insecure_private_key"]
  config.ssh.forward_agent = true
  config.ssh.insert_key = false
end

这个文件启动了三个节点,master1/slave1/slave2,可以从宿主机ssh进去,它们之间可以相互ssh,使用的都是宿主机上的key

参考 ssh-agent
参考 ssh agent

你可能感兴趣的:(Vagrant本地集群启动及ssh配置)