2019年3月24日 星期日

Vagrant for VMWare ESXi 6.0a

所需材料

  1. VMWare ESXi 6.0a SSH service is enabled
  2. Vagrant and install vagrant-vmware-esxi plugin
  3. VMware ovftool
  4. vSphere client (設定與確認使用)

安裝

VMWare ESXi 6.0a

此為免費版可
  1. 開啟 ssh 服務
  2. 依需求可建立其他使用者作為 vagrant 登入使用

Windows 7 SP1 64 bit

  1. 下載 Vagrant 並安裝
  2. 開啟 cmd 後可建立一個資料夾,輸入 vagrant init 初始化
  3. 輸入 vagrant status 確認是否正常
  4. 如出現 powershell 版本低於 3 版,則點我下載安裝,依需求選擇 WINDOWS6.132 or 64 bit 版本。
    REF
  5. 安裝 plugin
vagrant plugin install vagrant-vmware-esxi
vagrant plugin list
  1. 安裝 vSphere Client
    點此下載,不斷下一步安裝完成即可
a. 開啟 ssh 服務
b. 依需求可建立其他使用者作為 vagrant 登入使用
  1. 安裝 VMware ovftool 不斷下一步即可完成安裝。
  2. 設定 ovftool 環境變數
    [電腦]右鍵 -> [內容] -> [進階系統設定] -> [環境變數]
    修改 [系統變數] 中 [Path] ,在最後方加入以下路徑後按確定
    ;C:\Program Files\VMware\VMware OVF Tool
    設定完成後重開機

CentOS 7.6

  1. 安裝 vagrant
yum install -y https://releases.hashicorp.com/vagrant/2.2.4/vagrant_2.2.4_x86_64.rpm
  1. 安裝 ovftool
    下載 ovftool 後上傳至主機後,提供執行權限並依照指示安裝
chmod +x VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle
./VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle
  1. 初始化 vagrant
mkdir vagrant-centos7
cd vagrant-centos7
vagrant init
  1. 安裝 plugin
vagrant plugin install vagrant-vmware-esxi
vagrant plugin list
如出現類似以下錯誤,則需 yum install gcc -y
...
checking if the C compiler accepts ... *** extconf.rb failed ***
...
  1. 輸入 vagrant status 確認有無錯誤訊息

使用

  • 下載所需 box 檔
windows 開啟 cmd
centos 則直接以 terminal
cd 至 vagrant init 過的資料夾
輸入以下指令
vagrant box add generic/centos7
  • 編輯 Vagrantfile 如以下範本
Vagrant.configure("2") do |config|
  config.vm.hostname="c7"
  config.vm.box = 'generic/centos7'
  config.vm.provision "shell", path: "script.sh"

  config.vm.provider :vmware_esxi do |esxi|
    #
    #   Provider settings
    #
    esxi.esxi_hostname = '192.168.48.133'
    esxi.esxi_username = 'root'
    esxi.esxi_password = 'prompt:'
    esxi.esxi_hostport = 22
    esxi.esxi_disk_store = 'datastore1'
    esxi.guest_memsize = '2048'
    esxi.guest_numvcpus = '2'
    esxi.guest_boot_disk_size = 15
    #esxi.guest_storage = [10, 20]
    #esxi.esxi_virtual_network = 'vmnet_example'
  end
end
可加入 shell 腳本
#!/bin/sh
yum install nginx -y
  • 啟動
    vagrant up 後會將 generic/centos7 用 ovftool 以 ssh 方式傳送至 ESXi Host 中
  • 刪除
    vagrant destroy
  • 連線
    a. 使用 vagrant ssh 連線
    b. 以ssh config 連線
    輸入 vagrant ssh-config 會輸出以下資訊
# 可修改為 Host ooo
Host default
  HostName 192.168.48.136
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /root/vagrant-centos7/.vagrant/machines/default/vmware_esxi/private_key
  IdentitiesOnly yes
  LogLevel FATAL
將其複製到 ~/.ssh/config 內後,再 ssh ooo 即可免密碼登入
REF1
REF2
REF3


REF

沒有留言:

張貼留言

MariaDB Cluster on CentOS7.6

目標 於3臺 CentOS 7.6 minimal 上建置 MariaDB 10.3 Galera cluster