为VMware vSphere创建Ubuntu 16.04 Terraform模板

it2024-03-22  60

为VMware vSphere创建Ubuntu 16.04 Terraform模板

 

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

 

 

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

创建一个VMware vSphere虚拟机

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

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

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

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

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

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

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

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

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

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

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

12-验证虚拟机的创建。

13-启动虚拟机。

14-启动vSphere Web控制台。

安装Ubuntu 16.04

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

2-开始Ubuntu安装。

3-选择您的Ubuntu安装语言。

4-选择您的Ubuntu虚拟机所在的国家/地区。

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

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

7-为虚拟机配置用户。

8-不要加密虚拟机的主目录。

9-验证虚拟机的时区。

10-选择安装磁盘的分区方法。

11-选择安装盘。

12-如果使用代理,请配置一个。

13-选择自动安装安全更新。

14-选择安装“ OpenSSH服务器”。

15-安装GRUB。

16-重新启动虚拟机。

17- SSH到新的Ubuntu虚拟机。

 

$ ssh sguyennet@10.10.40.253

 

18-升级Ubuntu软件包。

 

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

 

清理虚拟机配置

1-从/ etc / network / interfaces网络配置中删除以下几行。

 

# The primary network interface auto ens192 iface ens192 inet static address 10.10.40.253 netmask 255.255.255.0 network 10.10.40.0 broadcast 10.10.40.255 gateway 10.10.40.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 10.10.40.1 dns-search inkubate.io

 

2-关闭Ubuntu虚拟机。

 

$ sudo shutdown now

 

3-编辑虚拟机的设置。

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

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

6-验证修改。

创建VMware vSphere模板

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

测试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-16.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 16.04模板通过Terraform部署vSphere虚拟机。

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

最新回复(0)