Create compute instance using a custom image
In this lab you will use Custom image feature of OCI. Using this feature, an existing Compute instance with software packages and updates installed can be used to create additional compute instance. These new compute instances will come with all the software packages and updates pre-installed.
This tutorial assumes you know how to generate SSH keys on Oracle Cloud Infrastructure. Keep your SSH keys handy.
Sign in to OCI Console and Create VCN
Sign in using your tenant name, user name and password. Use the login option under Oracle Cloud Infrastructure.
From the OCI Services menu, Click Virtual Cloud Networks under Networking. Select the compartment assigned to you from the drop down menu on the left part of the screen under Networking and Click Start VCN Wizard.
Note: Ensure the correct Compartment is selected under COMPARTMENT list.
Click VCN with Internet Connectivity and click Start VCN Wizard.
Fill out the dialog box:
- VCN NAME: Provide a name
- COMPARTMENT: Ensure your compartment is selected
- VCN CIDR BLOCK: Provide a CIDR block (10.0.0.0/16)
- PUBLIC SUBNET CIDR BLOCK: Provide a CIDR block (10.0.1.0/24)
- PRIVATE SUBNET CIDR BLOCK: Provide a CIDR block (10.0.2.0/24)
- Click Next
Verify all the information and Click Create.
This will create a VCN with the following components.
VCN, Public subnet, Private subnet, Internet gateway (IG), NAT gateway (NAT), Service gateway (SG)
Click View Virtual Cloud Network to display your VCN details.
Create a Compute Instance
Go to the OCI console. From OCI services menu, under Compute, click Instances.
Click Create Instance. Fill out the dialog box:
- Name your instance: Enter a name.
- Create in Compartment: Choose the same compartment you used to create the VCN.
- Choose an operating system or image source: For the image, we recommend using the Latest Oracle Linux available.
Click Show Shape, Network and Storage Options:
- Availability Domain: Select an availability domain (the default AD 1 is fine).
- Shape: Click Change Shape.
In the Browse All Shapes dialog:
- Instance Type: Select Virtual Machine
- Shape Series: Intel Lake
- Instance Shape: Select VM.Standard2.1
Click Select Shape.
Under Configure Networking:
- Virtual cloud network compartment: Select your compartment.
- Virtual cloud network: Choose the VCN you created in Step 1.
- Subnet Compartment: Choose your compartment.
- Subnet: Choose the Public Subnet under Public Subnets.
- Use network security groups to control traffic : Leave un-checked.
- Assign a public IP address: Check this option.
Boot Volume and Add SSH Keys
- Boot Volume: Leave the default, uncheck values.
- Add SSH Keys: Choose 'Paste SSH Keys' and paste the Public Key that you have created.
Note: If 'Service limit' error is displayed choose a different shape from VM.Standard2.1, VM.Standard.E2.1, VM.Standard1.1, VM.Standard.B1.1 OR choose a different AD
Wait for Instance to be in Running state. In Cloud Shell Terminal, enter:
Enter ls and verify your SSH key file exists.
SSH into your compute instance:
ssh -i <sshkeyname> opc@<PUBLIC_IP_OF_COMPUTE>
Hint: If 'Permission denied error' is seen, ensure you are using '-i' in the ssh command. You MUST type the command, do NOT copy and paste ssh command.
Enter 'yes' when prompted for security message, and enter your passphrase.
<COMPUTE_INSTANCE_NAME>appears on the prompt.
Install httpd on Compute Instance and Create Custom Image
Switch to ssh session to compute install. Install httpd server, enter Command:
sudo yum -y install httpd
Start httpd, enter command:
sudo systemctl start httpd
Verify http status, enter command:
sudo service httpd status
We now have installed httpd server on a compute instance and will create a custom image. Switch back to OCI Console window.
From OCI services menu, Click Instances under Compute.
Click your compute instance name and Click Stop, and Stop Instance in the dialog.
Once Stopped, Click Create Custom Image from More Actions menu.
Fill out the dialog box and Click Create Custom Image. VMs status will change to Creating Image.
Start a Custom Image
Navigate to main Instances page under compute and click Custom Images. Locate your custom image, Click the Action icon and then Create Instance.
Fill out the dialog box and Click Create. Once the instance is in running state note down it's Public IP address.
SSH to the compute instance as we did in Step 2.
Start the httpd service in the custom image:
sudo service httpd start
Check the status of httpd service as before.
You have successfully created a custom image with httpd already installed and used this custom image to launch a compute instance and started httpd service. In this new compute instance there was no need to re-install httpd server as it was already present when the custom image was created.
A compute instance can have a lot more applications installed and this custom image feature facilitates launching new compute instances with these applications pre-installed.
Delete the Resources
Note - You can ignore the Delete the Resources section if you’re using Oracle’s free tenancy, otherwise deleting resources in your own tenancy is optional.
Switch to OCI console window.
If your Compute instance is not displayed, From OCI services menu Click Instances under Compute.
Locate first compute instance, Click Action icon and then Terminate.
Make sure Permanently delete the attached Boot Volume is checked, Click Terminate Instance. Wait for instance to fully Terminate.
Repeat the step to delete second compute instance.
From OCI Services Menu Click Compute then Custom Images. Locate the custom image you created. Click the Action icon and then Delete.
From OCI services menu Click Virtual Cloud Networks under Networking, list of all VCNs will appear.
Click on your VCN , then click Terminate.
Click Terminate All in the Confirmation window. Click Close once VCN is deleted.
Authors - Flavio Pereira, Larry Beausoleil
Contributors - Arabella Yao, Product Manager Intern, DB Product Management, Kamryn Vinson, Intern