In this article I will show how easy it is to create a Linux Instance (Virtual Server) in the Oracle Cloud.
I assume you have signed up for an account in the Oracle Cloud, if not see Into the Oracle Cloud in just some simple steps
- Create a key pair
- Choose a compartment for your resources
- Create a cloud network
- Create (Launch) an instance
First we need to prepare by taking the following steps:
Create a key pair
Instances use an SSH key pair instead of a password to authenticate a remote user. A key pair file contains a private key and public key. You keep the private key on your computer and provide the public key every time you launch an instance.
Open a terminal session on your PC and create a key pair, for instance:
Robs-MacBook-Pro:mykeys rzoeteweij$ ssh-keygen -t rsa -N "" -b 2048 -C "mykey" -f /home/rzoeteweij/mykeys/mykeys Generating public/private rsa key pair. Your identification has been saved in/home/rzoeteweij/mykeys/mykeys. Your public key has been saved in/home/rzoeteweij/mykeys/mykeys. The key fingerprint is: SHA256:JSRVfFXh23EKHyJ8poFluyjnvHHWTAz5BlSDxJCA1jJ4 mykey The key's randomart image is: +---[RSA 2048]----+ | .++.=o=+.. ..oo| | .... B +.++.. | | . . o.+.+ +..| | E .B . + =.| | .S o . + .| | .o+. . | | .=+ o.. | | +o=. | | ++o | +----[SHA256]-----+ Robs-MacBook-Pro:mykeys rzoeteweij$ ls -al total 16 drwxr-xr-x 4 rzoeteweij staff 128 Nov 9 11:34 . drwxr-xr-x+ 32 rzoeteweij staff 1024 Nov 27 08:43 .. -rw------- 1 rzoeteweij staff 1675 Nov 9 11:34 mykeys -rw-r--r-- 1 rzoeteweij staff 387 Nov 9 11:34 mykeys.pub
Choosing a compartment
Compartments help you organise and control access to your resources. A compartment is a collection of related resources (such as cloud networks, compute instances, or block volumes) that can be accessed only by those groups that have been given permission by an administrator in your organisation. For example, one compartment could contain all the servers and storage volumes that make up the production version of your company’s Human Resources system. Only users with permission to that compartment can manage those servers and volumes.
As the first resource we are going to create next is a Virtual Cloud Network, we navigate from the left pane Menu, Networking > Virtual Cloud Networks
In the left side pane we select the compartment we want to use to store our resources, in this example we choose compartment ‘Demo‘
Create a cloud network
Before you can launch an instance, you need to have a virtual cloud network (VCN) and subnet to launch it into. A subnet is a subdivision of your VCN that you define in a single availability domain. The subnet directs traffic according to a route table. For this example, you’ll access the instance over the internet using its public IP address, so your route table will direct traffic to an internet gateway. The subnet also uses a security list to control traffic in and out of the instance.
Click [Create Virtual Cloud Network]
Make sure the correct Compartment to store the Virtual Cloud Network, has been selected
Enter a Name for the Virtual Cloud Network
Select Create Virtual Cloud Network plus related resources
This automatically sets up a Virtual Cloud Network with access to the internet. You can set up firewall rules and Security Lists to control ingress and egress traffic to your Instances. All related resources will be created in the same Compartment as the VCN.
Click [Create Virtual Cloud Network]
Next to the Virtual Cloud Network named myCorp_Network the following network resources will be created automatically:
- CIDR block range of 10.0.0.0/16
- An internet gateway
- A route table with a default route rule to enable traffic to and from the internet gateway
- A default security list. You will edit this default security list later in the tutorial.
- A public subnet in each availability domain.
- The VCN will automatically use the Internet and VCN Resolver for DNS.
Next we can start creating our first Instance
Launch (Create) our first Instance
An Instance within the Oracle Cloud actually is a Virtual Server that usually is based on Linux (although Windows is also a possibility) and can be used as any other virtual or physical Linux server you might have running on premise.
From the left pane Menu, navigate Compute > Instances
Click [Create Instance]
Within the Create Instance dialog enter
- Name: Enter a name, for example: <your initials>_Instance.
- Availability Domain: Accept the default.
- Operating system: Accept the default, Oracle Linux 7.X.
- Instance type: Accept the default, Virtual Machine.
- Instance shape: Accept the default, VM.Standard2.1 (1 OCPU, 15GB RAM).
- The shape defines the number of CPUs and amount of memory allocated to the instance.
- Configure boot volume: Leave both options unselected.
- SSH Keys: Click Choose SSH Key files, navigate to the location where you saved the public key portion (.pub) of the SSH key file you created, select the file and click Open.
- Virtual cloud network compartment: Select the compartment containing the cloud network you created.
- Virtual cloud network: Select the cloud network you created.
- Subnet compartment: Select the compartment containing the subnet created with your cloud network in availability domain 1.
- Subnet: Select the subnet created with your cloud network in availability domain 1.
- Assign public IP address: Leave checked.
Click [Create Instance]
The actual provisioning of the Instance might take some time, as soon as the provisioning is completed the Instance will be shown as available
Connect to the newly created Instance
The Instance in the Oracle Cloud has been created with default user opc. The next example will show how to connect to the newly created Instance using this user and the Public IP Address.
As we have created the instance including a Public IP Address, we can now ssh to this Public IP as follows:
ssh -i /Users/rzoeteweij/mykeys/mykeys firstname.lastname@example.org
Robs-MacBook-Pro:mykeys rzoeteweij$ ssh -i /Users/rzoeteweij/mykeys/mykeys email@example.com The authenticity of host '126.96.36.199 (188.8.131.52)' can't be established. ECDSA key fingerprint is SHA256:vSNmR6/7J+fCTRsqNvxxRrUbjKLTogX8fWAAAj2poREEI. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '184.108.40.206' (ECDSA) to the list of known hosts. [opc@mycorp-instance ~]$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.2G 0 7.2G 0% /dev tmpfs 7.3G 0 7.3G 0% /dev/shm tmpfs 7.3G 58M 7.2G 1% /run tmpfs 7.3G 0 7.3G 0% /sys/fs/cgroup /dev/sda3 39G 2.1G 37G 6% / /dev/sda1 200M 9.6M 191M 5% /boot/efi tmpfs 1.5G 0 1.5G 0% /run/user/1000 [opc@mycorp-instance ~]$ ls [opc@mycorp-instance ~]$ ls -al total 16 drwx------. 5 opc opc 4096 Nov 28 14:55 . drwxr-xr-x. 3 root root 17 Nov 28 14:40 .. -rw-r--r--. 1 opc opc 18 Aug 24 07:12 .bash_logout -rw-r--r--. 1 opc opc 193 Aug 24 07:12 .bash_profile -rw-r--r--. 1 opc opc 231 Aug 24 07:12 .bashrc drwxrwxr-x. 3 opc opc 18 Nov 28 14:55 .cache drwxrwxr-x. 3 opc opc 18 Nov 28 14:55 .config drwx------. 2 opc opc 29 Nov 28 14:40 .ssh [opc@mycorp-instance ~]$ ping oracle.com PING oracle.com (220.127.116.11) 56(84) bytes of data. 64 bytes from vp-ocoma-cms-adc.oracle.com (18.104.22.168): icmp_seq=1 ttl=248 time=40.3 ms 64 bytes from vp-ocoma-cms-adc.oracle.com (22.214.171.124): icmp_seq=2 ttl=248 time=40.4 ms 64 bytes from vp-ocoma-cms-adc.oracle.com (126.96.36.199): icmp_seq=3 ttl=248 time=40.3 ms ^C --- oracle.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 40.370/40.386/40.413/0.165 ms
As the example terminal session shows we can ping to oracle.com, proofing the instance has access to the public internet
Please notice that all statements made by me and information provided on this blog are mine and not necessarily those of Oracle Corporation.