在 CentOS 8/Rocky Linux 8 上安装 Terraform |
Terraform 是一款与云无关的基础设施自动化工具,由出色的 HashiCorp 工程师创建,可帮助您使用代码进行基础设施资源管理。 Terraform 允许您构建、更改和版本化部署在流行云环境和本地的基础设施。这篇短文将向您展示如何在 CentOS 8/Rocky Linux 8 Linux 系统上安装 terraform。
在 CentOS 8/Rocky Linux 8 上安装 Terraform
在开始之前,请确保您有一个 sudo 用户,用于在 CentOS 8/Rocky Linux 8 Linux 计算机上安装 Terraform。以下几个步骤应该适合您。
步骤1:安装yum-utils包
我们将使用 yum-utils 包来帮助将 HashiCorp 存储库添加到系统中:
sudo yum install -y yum-utils
步骤 2:在 CentOS 8/Rocky Linux 8 上安装 Terraform
接下来我们添加 CentOS YUM 存储库:
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
确认存储库已添加并且正在运行:
$ sudo dnf repolist
repo id repo name
appstream CentOS Stream 8 - AppStream
baseos CentOS Stream 8 - BaseOS
centos-advanced-virtualization CentOS-8 - Advanced Virtualization
centos-ceph-nautilus CentOS-8 - Ceph Nautilus
centos-nfv-openvswitch CentOS-8 - NFV OpenvSwitch
centos-openstack-wallaby CentOS-8 - OpenStack wallaby
centos-rabbitmq-38 CentOS-8 - RabbitMQ 38
epel Extra Packages for Enterprise Linux 8 - x86_64
epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64
extras CentOS Stream 8 - Extras
hashicorp Hashicorp Stable - x86_64
powertools CentOS Stream 8 - PowerTools
如果您可以从列表中看到 hashcorp,请继续安装 terraform:
sudo yum -y install terraform
如果您想要安装 Terraform 的旧版本,HashiCorp Yum 存储库包含多个版本的 Terraform:
$ yum --showduplicate list terraform
....
terraform.x86_64 1.2.0-1 hashicorp
terraform.x86_64 1.2.1-1 hashicorp
terraform.x86_64 1.2.2-1 hashicorp
terraform.x86_64 1.2.3-1 hashicorp
terraform.x86_64 1.2.4-1 hashicorp
terraform.x86_64 1.2.5-1 hashicorp
terraform.x86_64 1.2.6-1 hashicorp
terraform.x86_64 1.2.7-1 hashicorp
terraform.x86_64 1.2.8-1 hashicorp
terraform.x86_64 1.2.9-1 hashicorp
terraform.x86_64 1.3.0-1 hashicorp
terraform.x86_64 1.3.1-1 hashicorp
terraform.x86_64 1.3.2-1 hashicorp
terraform.x86_64 1.3.3-1 hashicorp
terraform.x86_64 1.3.4-1 hashicorp
terraform.x86_64 1.3.5-1 hashicorp
然后选择特定版本的 Terraform,请参阅示例:
sudo dnf install terraform-<version>.x86_64
步骤 3:确认 CentOS 8/Rocky Linux 8 上的 Terraform 安装
检查 Terraform 的版本以验证我们的安装:
$ terraform version
Terraform v1.3.5
on linux_amd64
然后,您可以参考我们有关使用 Terraform 的一些指南。
- 如何使用 Terraform 在 KVM 上配置虚拟机
- Hetzner 云与 Terraform
- 如何使用 Terraform 在 oVirt/RHEV 上配置虚拟机
- 使用 Terraform 在 Hetzner Cloud 上部署 VM 实例
- 使用 Packer 和 Ansible 构建 AWS EC2 机器映像 (AMI)
其他学习材料包括:
- HashiCorp 认证:Terraform 助理
- 学习 DevOps:使用 Terraform 进行基础设施自动化
- HashiCorp 认证:Terraform Associate -50 个实践演示
- AWS 上的 Terraform 与 SRE 和 IaC DevOps |真实世界 20 个演示