Oracle Cloud Infrastructure(OCI)使用Packer创建客户化Image实战

Oracle Cloud Infrastructure(OCI)使用Packer创建客户化Image实战。

前提:

a,拥有Oracle Cloud Infrastructure(OCI)账户

b,拥有Oracle Cloud Infrastructure(OCI)基础知识

 

详细步骤:

1,下载安装Packer,确认

1-1,下载安装Packer

wget https://releases.hashicorp.com/packer/1.3.5/packer_1.3.5_linux_amd64.zip
unzip packer_1.3.5_linux_amd64.zip
sudo mv packer /usr/local/bin/

1-2,确认

packer version

输出结果

Packer v1.3.5

2,创建配置文件

请修改各自正确的信息。

{
  "builders": [
    {
      "user_ocid": "ocid1.user.oc1..aaaaaaaaalxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "tenancy_ocid": "ocid1.tenancy.oc1..aaaaaaaaalxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "fingerprint": "33:be:4a:4b:ed:0d:1e:xx:xx:xx:xx:xx:xx:xx:xx:xx",
      "key_file": "/u01/terra-workspace/private.pem",
      "availability_domain": "TGjA:EU-FRANKFURT-1-AD-3",
      "region": "eu-frankfurt-1",
      "base_image_ocid": "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaalxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "compartment_ocid": "ocid1.compartment.oc1..aaaaaaaaalxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "image_name": "RedisOCI",
      "shape": "VM.Standard2.1",
      "ssh_username": "ubuntu",
      "ssh_password": "xxxxxxxxxx",
      "subnet_ocid": "ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaalxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "type": "oracle-oci"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "sleep 30",
        "sudo apt-get update",
        "sudo apt-get install -y redis-server"
      ]
    }
  ]
}

注意:示例中用到Ubuntu的Image,用户名必须是ubuntu。

否者报以下错误“Error waiting for SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain”。

3,创建Image

创建过程中会先创建Instance,然后通过Instance创建Image。

packer build build.json

4,确认创建结果。

 

恭喜!你成功使用Packer创建了Image。

结尾!

你可能感兴趣的:(Packer)