3.3. Uploading and running a RHEL instance on Google Cloud
To run your RHEL instance on Google Cloud, you need to configure and upload a RHEL image to Google Cloud.
3.3.1. Installing the Google Cloud SDK 复制链接链接已复制到粘贴板!
You can use Google Cloud SDK to manage Google Cloud resources and services from your command line by using Google Cloud CLI.
Prerequisites
- You have downloaded, extracted, and initialized the Google Cloud SDK.
Procedure
-
Use the
gcloudCLI utility to manage project and instances. Create a project:
# gcloud projects create <example_gcp_project_id> --name <example_gcp_project>The example creates a project with the project ID
<example_gcp_project_id>and the project name<example_gcp_project>.Display project information:
# gcloud compute <example_project_info> describe --project <example_project_name>
3.3.2. Creating a new project on Google Cloud 复制链接链接已复制到粘贴板!
To upload your RHEL image to Google Cloud, You need to create new project on Google Cloud. A project manages your assigned Google Cloud resources.
Prerequisites
- You have an account on Google Cloud.
Procedure
- Launch the Google Cloud Console.
- Click the drop-down menu to the right of Google Cloud.
- From the pop-up menu, click NEW PROJECT.
- From the New Project window, enter a name for your new project.
- Check Organization. Click the drop-down menu to change the organization, if necessary.
- Confirm the Location of your parent organization or folder. Click Browse to search for and change this value, if necessary.
- Click CREATE to create your new Google Cloud project.
Create a Google Cloud storage bucket to import and store objects such as virtual machine (VM) images.
Procedure
Log in to the Google cloud console:
# gcloud auth loginCreate a storage bucket:
# gsutil mb gs://<example_bucket_name>注意Alternatively, you can use the Google Cloud Console to create a bucket. For details, see Create a bucket.
Specify the image name that you want to create, the existing bucket name, and the name of the image:
# *gcloud compute images create my-image-name --source-uri gs://__<example_bucket_name>__/disk.raw.tar.gz*注意Alternatively, you can use the Google Cloud Console to create an image. See Creating, deleting, and deprecating custom images for more information.
Optional: Find the image in the Google Cloud Console.
- Click the Navigation menu to the left of the Google Cloud Console banner.
- Select Compute Engine and then Images.
Run the
qemu-imgcommand to convert yourqcow2image to therawformat:# qemu-img convert -f qcow2 -O raw rhel-10.0-sample.qcow2 disk.rawCompress the image:
# tar --format=oldgnu -Sczf disk.raw.tar.gz disk.rawUpload the image to the existing bucket:
# gsutil cp disk.raw.tar.gz gs://<example_bucket_name>注意Upload could take a few minutes.
- From the Google Cloud home screen, click the collapsed menu icon and select Storage and then select Browser.
Click the name of your bucket where
disk.raw.tar.gzis now listed.注意You can also upload your image by using the Google Cloud Console. To do so, click the bucket name and then click Upload files.
To configure a GCE VM instance from an image, use the Google Cloud Console.
Procedure
- From the Google Cloud Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Images.
- Select your image.
- Click Create Instance.
- On the Create an instance page, enter a Name for your instance.
- Choose a Region and Zone.
- Choose a Machine configuration that meets or exceeds the requirements of your workload.
- Ensure that Boot disk specifies the name of your image.
- Optional: Under Firewall, select Allow HTTP traffic or Allow HTTPS traffic.
- Click Create.
- Find your image under VM instances.
Click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select VM instances.
注意Alternatively, you can use the
gcloud compute instances createcommand to create a GCE VM instance from an image.# gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-imageThe example creates a VM instance named
myinstance3in zoneus-central1-abased upon the existing imagetest-iso2-image. For details, see gcloud compute instances create.Use the
ssh-keygenutility to generate an SSH key pair to use with GCE by using the public IP address:# ssh-keygen -t rsa -f ~/.ssh/google_compute_engine.pub- From the Google Cloud Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Metadata.
- Click SSH Keys and then click Edit.
-
Enter the output generated from the
~/.ssh/google_compute_engine.pubfile and click Save. Connect to the instance:
# ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>注意Or, you can run the
gcloud compute config-sshcommand to populate the config file with aliases for instances. The aliases allow simple SSH connections by instance name. For details, see gcloud compute config-ssh.