Terraform
使用 terraform 置备云虚拟机
使用 terraform 置备云虚拟机
Terraform 是一个流行的 IaC 工具。您可以使用一个命令在公有云上创建虚拟机。
阿里云和 AWS 模板用作示例提供商。您可以将 terraform.tf 作为示例。
入门
您可以在 macOS 上使用 homebrew 安装 terraform
安装 homebrew 和 terraform
然后初始化 terraform 云提供商,调整 terraform.tf 配置文件并应用它:
cd ~/pigsty/terraform
打印公共 IP 地址:
AWS 设置
您必须设置 aws 配置和凭据才能使用 AWS 提供商。
有一个 AWS(Amazon Web Services)的贡献示例,但它没有得到积极维护。
- spec/aws-cn.tf : AWS 4 节点 CentOS7 环境
阿里云设置
您可以将您的阿里云凭据添加到环境文件中,例如 ~/.bash_profile
示例配置文件:
- spec/aliyun-meta.tf : 阿里云 1 元节点模板,适用于所有发行版和 amd/arm(默认)
- spec/aliyun-full.tf : 阿里云 4 节点沙盒模板,适用于所有发行版和 amd/arm。
- spec/aliyun-oss.tf : 阿里云 5 节点构建模板,适用于所有发行版和 amd/arm。
以下是阿里云中使用的示例 ECS 公共操作系统镜像:
| 发行版 | 镜像前缀 | 镜像前缀 |
|---|---|---|
| CentOS 7.9 | centos_7_9_x64 |
rockylinux_8_10_arm6 |
| Rocky 8.10 | rockylinux_8_10_x64 |
rockylinux_9_6_arm64 |
| Rocky 9.6 | rockylinux_9_5_x64 |
|
| Debian 11.11 | debian_11_11_x64 |
|
| Debian 12.11 | debian_12_11_x64 |
debian_12_11_arm64 |
| Ubuntu 20.04 | ubuntu_20_04_x64 |
|
| Ubuntu 22.04 | ubuntu_22_04_x64 |
ubuntu_22_04_arm64 |
| Ubuntu 24.04 | ubuntu_24_04_x64 |
ubuntu_24_04_arm64 |
| Anolis 8.8 | anolisos_8_9_x64 |
腾讯云设置
有一个腾讯云的贡献示例,但它没有得到积极维护。
- spec/tencentcloud.tf : 腾讯云 4 节点 CentOS7 环境