为VMware vSphere创建CentOS 7 Terraform模板

it2024-03-25  66

为VMware vSphere创建CentOS 7 Terraform模板

 

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

 

 

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

创建VMware vSphere虚拟机

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

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

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

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

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

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

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

8-将CentOS 7 ISO添加到虚拟机的CD / DVD驱动器。

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

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

11-验证虚拟机的创建。

12-启动虚拟机。

13-启动vSphere Web控制台。

安装CentOS 7

1-启动CentOS安装程序。

2-选择安装程序的语言。

3-选择安装盘。

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

5-开始安装。

6-配置root密码。

7-配置管理员用户。

8-重新启动虚拟机。

9- SSH到新的CentOS虚拟机。

 

$ ssh sguyennet@10.10.40.253

 

10-升级CentOS软件包。

 

$ sudo yum upgrade

 

11-安装Perl。

 

$ sudo yum install perl

 

12-安装open-vm-tools

 

$ sudo yum install open-vm-tools

 

13-重新启动虚拟机。

 

$ sudo reboot

 

清理虚拟机配置

1- SSH到新的CentOS虚拟机。

 

$ ssh sguyennet@10.10.40.253

 

2-删除临时网络配置。

 

$ sudo rm /etc/sysconfig/network-scripts/ifcfg-ens192

 

3-关闭CentOS虚拟机。

 

$ sudo shutdown now

 

4-编辑虚拟机的设置。

5-将网卡重新设置为“ VM Network”。

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

7-验证更改。

创建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 = "centos-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 = "centos-7-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

 

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

转自:https://blog.inkubate.io/create-a-centos-7-terraform-template-for-vmware-vsphere/

最新回复(0)