为VMware vSphere创建Ubuntu 18.04 Terraform模板

it2024-03-24  77

为VMware vSphere创建Ubuntu 18.04 Terraform模板

Terraform是HashiCorp创建的自动化工具。它专注于以自动方式部署云基础架构。它支持许多云提供商,例如AWS,DigitalOcean,Google Cloud Platform,OpenStack,VMware vSphere等。Terraform是用GoLang开发的,这使得安装真正易于执行,并支持许多操作系统。

 

 

在本实验中,我们将看到如何为VMware vSphere创建Ubuntu 18.04 Terraform模板。

创建一个VMware vSphere虚拟机

1-创建一个新的虚拟机。

2-为您的虚拟机模板选择一个名称。

3-为虚拟机选择一个临时计算资源。

4-选择虚拟机的数据存储。

5-选择虚拟机的vSphere兼容性。

6-选择“ Ubuntu Linux(64位)”作为虚拟机的来宾OS。

7-将SCSI控制器的类型更改为“ VMware Paravirtual”。

8-为虚拟机选择一个临时网络。

9-将Ubuntu 18.04 ISO添加到虚拟机的CD / DVD驱动器。

10-在启动时连接CD / DVD驱动器。

11-完成虚拟机的硬件定制。

12-验证虚拟机的创建。

13-启动虚拟机。

14-启动vSphere Web控制台。

安装Ubuntu 18.04

1-选择Ubuntu安装程序的语言。

2-选择Ubuntu安装的键盘布局。

3-开始Ubuntu安装。

4-使用临时配置配置虚拟机的网卡。

5-配置代理(如果使用的话)。

6-选择磁盘的分区布局。

7-选择安装盘。

8-为虚拟机配置用户。

9-重新启动虚拟机。

10- SSH到新的Ubuntu虚拟机。

 

$ ssh sguyennet@10.10.40.253

 

11-升级Ubuntu软件包。

 

$ sudo apt-get update $ sudo apt-get upgrade

 

安装VMware工具

1-在笔记本电脑上下载VMware工具(如果您还没有帐户,则必须创建一个帐户)。

2-解压缩档案。

 

$ tar xvzf VMware-Tools-core-10.3.5-10430147.tar.gz

 

3-将VMware工具ISO复制到模板虚拟机。

 

$ scp vmtools/linux.iso sguyennet@10.10.40.253:/tmp

 

4- SSH到模板虚拟机。

 

$ ssh sguyennet@10.10.40.253

 

5-安装VMware工具ISO。

 

$ sudo mount -o loop /tmp/linux.iso /mnt

 

6-解压缩VMware Tools安装程序。

 

$ tar xvzf /mnt/VMwareTools-10.3.5-10430147.tar.gz -C /tmp

 

7-卸载VMware工具ISO。

 

$ sudo umount /mnt

 

8-删除open-vm-tools软件包。

 

$ sudo apt-get remove --purge open-vm-tools

 

9-安装VMware工具(默认情况下保留所有选项)。

 

$ cd /tmp/vmware-tools-distrib $ sudo ./vmware-install.pl

 

10-重新启动机器。

 

$ sudo reboot

 

清理虚拟机配置

1-删除临时网络配置。

 

$ sudo rm /etc/netplan/50-cloud-init.yaml

 

2-阻止云配置保留主机名。

 

$ sudo vim /etc/cloud/cloud.cfg ... preserve_hostname: true ...

 

3-关闭Ubuntu虚拟机。

 

$ sudo shutdown now

 

4-编辑虚拟机的设置。

5-将网卡设置回“ VM Network”。

6-将CD / DVD驱动器重新设置为“客户端设备”。

7-验证修改。

创建VMware vSphere模板

1-将虚拟机转换为vSphere模板。

 https://blog.inkubate.io/ghosthttps:/start.fedoraproject.org/

测试VMware vSphere模板

安装Terraform

这是有关如何在Linux桌面上安装Terraform的示例。Terraform也可用于Mac OSX和Windows。

1-下载Terraform。

 

$ wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip

 

2-解压缩档案。

 

$ unzip -e terraform_0.11.14_linux_amd64.zip

 

3-将二进制文件复制到您的路径中。

 

$ sudo cp terraform /usr/bin

 

根据模板启动新的虚拟机

1-克隆Terraform脚本存储库。

 

$ git clone https://github.com/sguyennet/terraform-vsphere-standalone.git

 

2-初始化Terraform。

 

$ cd terraform-vsphere-standalone

 

 

$ terraform init

 

3-配置部署(进行相应修改)。

 

$ vim terraform.tfvars #=============================================================================== # VMware vSphere configuration #=============================================================================== # vCenter IP or FQDN # vsphere_vcenter = "vcsa.inkubate.io" # vSphere username used to deploy the infrastructure # vsphere_user = "administrator@vsphere.local" # Skip the verification of the vCenter SSL certificate (true/false) # vsphere_unverified_ssl = "true" # vSphere datacenter name where the infrastructure will be deployed # vsphere_datacenter = "inkubate-lab" # vSphere cluster name where the infrastructure will be deployed # vsphere_cluster = "Compute-01"

 

#=============================================================================== # Virtual machine parameters #=============================================================================== # The name of the virtual machine # vm_name = "ubuntu-standalone" # The datastore name used to store the files of the virtual machine # vm_datastore = "Datastore-02" # The vSphere network name used by the virtual machine # vm_network = "pg-inkubate-production-static" # The netmask used to configure the network card of the virtual machine (example: 24) # vm_netmask = "24" # The network gateway used by the virtual machine # vm_gateway = "10.10.40.1" # The DNS server used by the virtual machine # vm_dns = "10.10.40.1" # The domain name used by the virtual machine # vm_domain = "inkubate.io" # The vSphere template the virtual machine is based on # vm_template = "ubuntu-18.04-terraform-template" # Use linked clone (true/false) vm_linked_clone = "false" # The number of vCPU allocated to the virtual machine # vm_cpu = "1" # The amount of RAM allocated to the virtual machine # vm_ram = "1024" # The IP address of the virtual machine # vm_ip = "10.10.40.254"

 

4-部署虚拟机。

 

$ terraform apply

 

5-测试访问虚拟机。

 

$ ssh sguyennet@10.10.40.254

 

6-销毁虚拟机。

 

$ terraform destroy

 

恭喜你!现在,您可以使用此Ubuntu 18.04模板通过Terraform部署vSphere虚拟机。

转自:https://blog.inkubate.io/create-a-ubuntu-18-04-terraform-template-for-vmware-vsphere/

最新回复(0)