0% found this document useful (0 votes)
13 views

OCI Lab 1 Compute VM - Create Oracle Linux Server

Uploaded by

pelealugreitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

OCI Lab 1 Compute VM - Create Oracle Linux Server

Uploaded by

pelealugreitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Oracle Academy Cloud Program (OACP)

Oracle Cloud Infrastructure (OCI) - Lab 1


• Create and Connect to a Compute VM Instance with Oracle Linux Server
• Install Java JDK
• Create, Compile, and Run a Java Program on Linux Command Line

Section 1: Download and Install Required Software


To manage public/private keys we will require Git for Windows
This task will take approximately 10 minutes to complete

1. On your local computer go to https://gitforwindows.org

2. Click Download

3. Save the file

4. Open the folder where the file is saved from step 3, and then click the executable file to install

5. Follow the On-Screen Instructions - accept all default settings

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
To connect a GUI session on our Compute VM Oracle Linux Instance we will require Real VNC Viewer
This task will take approximately 10 minutes to complete

1. On your local computer go to


https://www.realvnc.com/en/connect/download/viewer/

2. Click Download VNC Viewer

3. Save the file

4. Open the folder you have saved the file in and click the executable to install

5. Follow the On-Screen Instructions

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
2
Section 2: Create secure Public/Private Key authentication
If you already have a public private key set, you may skip this section

This task will take approximately 5 minutes to complete

1. Open a Git Bash Terminal window


a. Find Git in your programs
b. Click Git Bash to open a Terminal window

2. Enter the following command to create the key:


ssh-keygen -t rsa -b 2048

3. You will be Prompted for a Passphrase (or hit enter for blank)

4. You will be Prompted to repeat the Passphrase (or hit enter for blank)
a. If you entered a Passphrase, be sure to make note of it

5. You will be Prompted for path (or hit enter for default)
a. Default path is c:\users\username\.ssh\
b. 2 files will be created:
i. id_rsa (private key)
ii. id_rsa.pub (public key)
c. Make a note of where these files are located

6. Close Git Bash

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
3
Section 3: Create an Always Free Compute Instance with Oracle Linux 7
This task will take approximately 10 minutes to complete. You can create/own 2 (two) Always Free Instances.
1. Sign into your Oracle Cloud Tenancy

2. Select Create a VM Instance

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
4
3. Accept defaults for:

a. Placement

b. Image and shape

c. Networking

Your name appears here

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
5
4. Add SSH keys:

a. Select Upload public key files (.pub)

b. Drag id_rsa.pub that you saved in Section 2, Step 5 into the “Drop .pub files here”

5. Click “Create”

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
6
6. Your new Compute VM Instance will now be created

a. It may take a few minutes to provision your Compute Instance

b. When completed with Provisioning, you will see your Compute Instance in green (Running)

c. Once provisioned, take note of the public IP address assigned to your Instance

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
7
Section 4: Connect to the Compute VM Instance
This task will take approximately 5 minutes to complete.
1. Open a Git Bash Terminal window

a. Find Git in your programs

b. Click Git Bash to open a Terminal window

Note: You can have multiple Git Bash Terminal windows open

2. Execute the following command using your public IP address (from Section 3, Step 6c) to SSH Connect to your Compute VM Instance:
ssh opc@public IP address

Example: ssh [email protected]

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
8
3. If prompted to continue, enter “yes”

If you entered a Passphrase in Section 2 (Steps 3 and 4), you will be prompted to enter it here

The first time you connect, you will see a message that the new IP address has been added to a list of known hosts.

You now have a fully functioning Oracle Linux 7 Server

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
9
Section 5: Install JDK 8
To Install JDK 8 follow these steps:
1. In the Git Bash terminal window execute the following command to install the latest version of the repository:
sudo yum install -y --enablerepo=ol7_ociyum_config oci-included-release-el7

2. Once step 1 is completed, execute the following command to list the available JDK versions:
yum list jdk*
Note: As of this writing, the repository contains Oracle Java 8, 11,12,13, 14, 15, 16

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
10
3. To install Oracle Java 8, version 1.8.0 Execute the following command
sudo yum install jdk1.8.x86_64
Follow the on-screen instructions to download and install. If prompted to accept download size – type y.

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
11
4. To confirm the Java version, execute the following command
java -version

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
12
Section 6: Create, Compile and Run a Java Program

1. Create a new folder in your user directory (opc) by entering the command:
mkdir java

2. Change to that folder, enter the command


cd java

3. To start the vi editor and open a .java file, enter the command
vi HelloWorld.java

4. To begin editing the file, enter Insert Mode by typing the letter “i”
i

5. Enter the following code exactly as follows:


public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}

6. To complete editing, exit Insert mode - press Esc

7. To write the file to your java directory, enter the command


:w

8. To quit the vi editor, enter the command


:q

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
13
9. To compile the .java program, enter the command
javac HelloWorld.java

10. To run the program, enter the command


java HelloWorld

11. You should see Hello, World! displayed in the command line like below:

Copyright © 2021, Oracle and/or its affiliates. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
14

You might also like