Запустить в облаке Oracle виртуальную машину


$ export TENANCY_COMPARTMENT_ID=$(
    oci iam compartment list \
    --all \
    --compartment-id-in-subtree true \
    --access-level ACCESSIBLE \
    --include-root \
    --raw-output \
    --query "data[?contains(\"id\",'tenancy')].id | [0]"
)

$ echo ${TENANCY_COMPARTMENT_ID}

$ export COMPARTMENT_NAME=test-compartment

$ oci iam compartment create \
    --name ${COMPARTMENT_NAME} \
    --description "Test compartment for linux" \
    --compartment-id ${TENANCY_COMPARTMENT_ID}


// compartment-id
$ oci iam compartment list


// delete compartment-id
// $ oci iam compartment delete --force \
    --compartment-id ocid1.compartment.oc1..aaaaaaaaxary2whptgduzl3m3uqu6p2ci4wpwvty7ow2qrh6xejvv5sb4xaa


$ export COMPARTMENT_ID=указать ранее созданный compartment
$ echo ${COMPARTMENT_ID}


Network setup for Linux VM

$ export VCN_DISPLAY_NAME="VCN_LINUX_DISPLAY_NAME"
$ export VCN_DNS_LABEL="VCNDNS"


$ oci network vcn create \
    --compartment-id ${COMPARTMENT_ID} \
    --display-name ${VCN_DISPLAY_NAME} \
    --dns-label ${VCN_DNS_LABEL} \
    --cidr-block "10.0.0.0/24"


// $ oci network vcn delete -y \
//     --vcn-id <VCN_ID>


$ oci network vcn list \
    --compartment-id ${COMPARTMENT_ID}


$ export VCN_ID=$(
    oci network vcn list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["id"]'
)


$ echo ${VCN_ID}


$ export DEFAULT_SECURITY_LIST_ID=$(
    oci network vcn list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["default-security-list-id"]'
)


$ echo ${DEFAULT_SECURITY_LIST_ID}


$ export DEFAULT_ROUTE_TABLE_ID=$(
    oci network vcn list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["default-route-table-id"]'
)


$ echo ${DEFAULT_ROUTE_TABLE_ID}


$ oci iam availability-domain list \
  --compartment-id ${COMPARTMENT_ID}  \
  | jq -r -c '.data[] ["name"]'


QBXU:EU-FRANKFURT-1-AD-1
QBXU:EU-FRANKFURT-1-AD-2
QBXU:EU-FRANKFURT-1-AD-3


$ export AVAILABILITY_DOMAIN=QBXU:EU-FRANKFURT-1-AD-3


$ oci compute shape list \
    --compartment-id ${COMPARTMENT_ID} \
    --availability-domain ${AVAILABILITY_DOMAIN}  \
    | jq -r -c '.data[] ["shape"]'


BM.Standard.A1.160
VM.Standard.A1.Flex
VM.Standard.E2.1.Micro


VM.Standard.E2.1.Micro дают бесплатно только в QBXU:EU-FRANKFURT-1-AD-3


$ export SUBNET_DISPLAY_NAME=subnetlinuxtest
$ export SUBNET_DNS_LABEL=subnetlinuxtest

$ echo ${DEFAULT_SECURITY_LIST_ID}


// Прописать руками <default_secrity_list_id>
$ oci network subnet create \
    --vcn-id ${VCN_ID} \
    --compartment-id ${COMPARTMENT_ID} \
    --availability-domain ${AVAILABILITY_DOMAIN} \
    --display-name ${SUBNET_DISPLAY_NAME} \
    --dns-label ${SUBNET_DNS_LABEL} \
    --cidr-block "10.0.0.0/24" \
    --security-list-ids '["<default_secrity_list_id>"]'


$ oci network subnet list  \
    --compartment-id ${COMPARTMENT_ID}


$ export SUBNET_ID=$(
    oci network subnet list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["id"]'
)


$ export ROUTE_TABLE_ID=$(
    oci network subnet list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["route-table-id"]'
)


$ echo ${SUBNET_ID}

$ echo ${ROUTE_TABLE_ID}


Create Network Internet Gateway


$ export INTERNET_GATEWAY_DISPLAY_NAME=LinuxGateWay


$ oci network internet-gateway create \
    --compartment-id ${COMPARTMENT_ID} \
    --is-enabled true \
    --vcn-id ${VCN_ID} \
    --display-name ${INTERNET_GATEWAY_DISPLAY_NAME}


$ export GATEWAY_ID=$(
    oci network internet-gateway list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["id"]'
)


$ echo ${GATEWAY_ID}


Adding Route Rules to Route Table


// Прописать руками <internet_gateway_id>
$ oci network route-table update \
    --rt-id ${ROUTE_TABLE_ID} \
    --route-rules '[
        {"cidrBlock" : "0.0.0.0/0",
        "networkEntityId" : "<internet_gateway_id>"}
    ]'


Set up and connect to the Linux VM


// Получить список образов операционных систем
$ oci compute image list --all \
    --compartment-id ${COMPARTMENT_ID}  \
    | jq -r -c '.data[] ["display-name"]'


$ export DISPLAY_NAME="LinuxVMTest"

// Выбрал Ubuntu 20
$ export IMAGE_ID=ocid1.image.oc1.eu-frankfurt-1.aaaaaaaadqrjjiunkzkf62ggllx56s3p5775gonlifl74d4ri3bykztb4bha


$ ssh-keygen -t rsa


// Заменить путь до публичного ключа
$ oci compute instance launch \
    --availability-domain ${AVAILABILITY_DOMAIN} \
    --compartment-id ${COMPARTMENT_ID} \
    --shape "VM.Standard.E2.1.Micro" \
    --display-name ${DISPLAY_NAME} \
    --image-id ${IMAGE_ID} \
    --ssh-authorized-keys-file ${HOME}/.ssh/id_rsa.pub \
    --subnet-id ${SUBNET_ID}


$ oci compute instance list \
    --compartment-id ${COMPARTMENT_ID}


$ export INSTANCE_ID=$(
    oci compute instance list \
    --compartment-id ${COMPARTMENT_ID} \
    | jq -r -c '.data[] ["id"]'
)


// DELETE
// $ oci compute instance terminate \
//    --instance-id ${INSTANCE_ID}


$ echo ${INSTANCE_ID}


$ oci compute instance list-vnics \
    --instance-id ${INSTANCE_ID}


$ export PUBLIC_IP=$(
    oci compute instance list-vnics \
    --instance-id ${INSTANCE_ID} \
    | jq -r -c '.data[] ["public-ip"]'
)


$ echo ${PUBLIC_IP}


$ ssh ubuntu@${PUBLIC_IP}


// Если не ubuntu
$ ssh opc@${PUBLIC_IP}


$ sudo apt update -y && sudo apt upgrade -y


См. Подробнее:

https://git.ir/pluralsight-provisioning-virtual-machines-on-oracle-compute-cloud/


$ oci limits quota list --compartment-id ocid1.compartment.oc1..aaaaaaaaoujbluer6x6sjjtmzzpvkq4reidzyuolihmfsbie5b6tvp35crpq