Windows下傻瓜Vagrant+VirtualBox+shell快速建立3檯安裝好docker的centos7虛擬機

目標:在Windows上快速建立三臺能ping通局域網及公網的安裝好docker(本身想裝什麼軟件就裝什麼軟件)的centos7虛擬機git

manager:192.168.205.10
worker1:192.168.205.11
worker2:192.168.205.12
docker

提示:沒有看上一篇的請先移步完成上一篇的傻瓜式任務(傻瓜式Vagrant+virtualBox快速建立centos7虛擬機):https://juejin.im/post/5cfe199c5188250b6d6335bashell

下面咱們用三分鐘來達成這篇文章的目標vim

1 在D:\vm\centos7\centos7-vm-2目錄用Git Bash執行vagrant init centos7初始化Vagrantfile文件並修改該文件

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

Vagrant.require_version ">= 1.6.0"

boxes = [
    {
        :name => "manager",
        :eth1 => "192.168.205.10",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "worker1",
        :eth1 => "192.168.205.11",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "worker2",
        :eth1 => "192.168.205.12",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure(2) do |config|

  config.vm.box = "centos7"
  config.ssh.username = 'root'
  config.ssh.password = 'vagrant' 
  config.ssh.insert_key = 'true'

  boxes.each do |opts|
      config.vm.define opts[:name] do |config|
        config.vm.hostname = opts[:name]
        config.vm.provider "vmware_fusion" do |v|
          v.vmx["memsize"] = opts[:mem]
          v.vmx["numvcpus"] = opts[:cpu]
        end

        config.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", opts[:mem]]
          v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
        end

        config.vm.network :private_network, ip: opts[:eth1]
      end
  end

  config.vm.synced_folder ".", "/home/vagrant"
  config.vm.provision "shell", privileged: true, path: "./setup.sh"

end
複製代碼

2 在D:\vm\centos7\centos7-vm-2目錄建立文件setup.sh

# 安裝你想安裝的工具
sudo yum install -y git vim gcc glibc-static telnet bridge-utils

# 安裝docker
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh

# 啓動docker服務
sudo systemctl start docker

#移除安裝包
rm -rf get-docker.sh複製代碼

3 當前目錄打開GitBash,執行vagrant up命令,等待幾分鐘就ok啦~

簡而言之就是根據Vagrantfile文件遍歷建立虛擬機並執行shell腳本去初始化虛擬機centos

相關文章
相關標籤/搜索