写点什么

Vagrant 创建多台主机

用户头像
FeiLong
关注
发布于: 2020 年 07 月 19 日

使用 Vagrant 创建多台虚拟机。

环境


注意:Vagrant 使用 Hyper-V 创建虚拟机时不支持设置静态 IP。具体原因请参考 https://www.vagrantup.com/docs/providers/hyperv/limitations


  • Provider:Hyper-V

过程

配置文件

Vagrantfile


# -*- mode: ruby -*-# # vi: set ft=ruby : Vagrant.require_version ">= 2.0.0" $num_instances ||= 3$instance_name_prefix ||= "k8s"$vm_memory ||= 2048$vm_cpus ||= 1 Vagrant.configure("2") do |config|  # 创建多台虚拟机  (1..$num_instances).each do |i|    config.vm.define vm_name = "%s-%01d" % [$instance_name_prefix, i] do |node|      node.vm.hostname = vm_name      node.vm.box = "centos/7"       # 设置内存、CPU      node.vm.provider "hyperv" do |h|        h.memory = $vm_memory        h.cpus = $vm_cpus      end       # 关闭 swap      node.vm.provision "shell", inline: "swapoff -a"       if i == $num_instances        # 同步目录        node.vm.synced_folder ".", "/vagrant", type: "smb"      end    end  endend 
复制代码


启动

注意:k8s-3 主机设置了文件共享,因此需要手动输入宿主机用户名、密码(也可以将用户名、密码写入配置文件中,但这样不安全)。

vagrant upBringing machine 'k8s-1' up with 'hyperv' provider...Bringing machine 'k8s-2' up with 'hyperv' provider...Bringing machine 'k8s-3' up with 'hyperv' provider...==> k8s-1: Verifying Hyper-V is enabled...==> k8s-1: Verifying Hyper-V is accessible...... ==> k8s-3: Machine booted and ready!==> k8s-3: Preparing SMB shared folders...    k8s-3: You will be asked for the username and password to use for the SMB    k8s-3: folders shortly. Please use the proper username/password of your    k8s-3: account.    k8s-3:    k8s-3: Username (user[@domain]): xxx@hotmail.com    k8s-3: Password (will be hidden): Vagrant requires administrator access to create SMB shares andmay request access to complete setup of configured shares.==> k8s-3: Setting hostname...==> k8s-3: Mounting SMB shared folders...    k8s-3: D:/repo/k8s => /vagrant==> k8s-3: Running provisioner: shell...    k8s-3: Running: inline script 
复制代码


参考

  • https://www.vagrantup.com/docs/providers/hyperv/configuration


发布于: 2020 年 07 月 19 日阅读数: 79
用户头像

FeiLong

关注

还未添加个人签名 2018.09.17 加入

还未添加个人简介

评论

发布
暂无评论
Vagrant 创建多台主机