为VMware vSphere创建Ubuntu 18.04 Terraform模板

为VMware vSphere创建Ubuntu 18.04 Terraform模板

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

 


HashiCorp Terraform徽标

 

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

创建一个VMware vSphere虚拟机

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

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

12-验证虚拟机的创建。

Ubuntu 18.04 Terraform vSphere模板

13-启动虚拟机。

Ubuntu 18.04 Terraform vSphere模板

14-启动vSphere Web控制台。

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

安装Ubuntu 18.04

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

3-开始Ubuntu安装。

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

7-选择安装盘。

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

Ubuntu 18.04 Terraform vSphere模板

8-为虚拟机配置用户。

Ubuntu 18.04 Terraform vSphere模板

9-重新启动虚拟机。

Ubuntu 18.04 Terraform vSphere模板

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-编辑虚拟机的设置。

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板

7-验证修改。

Ubuntu 18.04 Terraform vSphere模板

创建VMware vSphere模板

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

Ubuntu 18.04 Terraform vSphere模板 https://blog.inkubate.io/ghosthttps:/start.fedoraproject.org/
Ubuntu 18.04 Terraform 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-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/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值