(For more resources related to this topic, see here.)
When you add a new instance to your project, it is automatically started. After a few moments, it will be ready for logging in using SSH. In order to create and start an instance, run the following command:
% gcutil –-project=<project_id> addinstance <instance_name>
gcutil will interactively collect the necessary details on the command line.
For our example, we create a new instance called hello-google-compute:
% gcutil –project=packt-gce-starter addinstance hello-gce INFO: Waiting for insert of instance hello-gce. Sleeping for 3s. [omitted]
The omitted output will show information on the zone, image, and machine type selected during interactive setup and provide a return code to indicate whether the operation was successful.
If you wish to create an instance non-interactively, you will have to set a few additional parameters. The instance name must only contain lower-case letters, numbers, or dashes and it must start with a letter.
Option |
Description |
–machine-type |
The machine type to host the instance. gcutillistmachinetypes displays a list of available machine types, and gcutil getmachinetype provides details on a specific machine type. |
–image |
The name of the image to install, from the project’s images collection. gcutil listimages displays a list of available images, and gcutil getimage provides details on a specific image. |
A comprehensive list of options can be listed by running the following command:
% gcutil help addinstance
After creation, your instance will be also displayed in the Google Cloud Console.
% gcutil --project=<project_id> listinstances
By default, every instance has a network setup that allows the virtual machine to communicate with other machines in the same network and with the rest of the world via the Internet. Note that, however, communication is restricted by the default firewall to incoming SSH traffic; see The Firewall object section for details.
Information on a newly created instance
Checking the status of an instance
After having started an instance, or for routine checks during the management of your GCE infrastructure, you may want to check the status of a given virtual machine. This can be done either via the Web UI, as shown in the preceding screenshot, or by calling:
% gcutil --project=<project_id> getinstance <instance_name>
For our test instance, this will yield something like:
% gcutil –-project=packt-gce-starter getinstance hello-gce +------------------------+-------------------------------------+ | property | value | +------------------------+-------------------------------------+ | name | hello-gce | | description | | | creation-time | 2013-05-27T11:02:54.825-07:00 | | machine | machineTypes/n1-standard-1 | | | | | status | RUNNING | | status-message | | | | | | disk | 0 | | type | EPHEMERAL | | mode | READ_WRITE | | | | | network-interface | | | network | networks/default | | ip | 10.240.17.7 | | access-configuration | External NAT | | type | ONE_TO_ONE_NAT | | external-ip | 192.158.30.140 | +------------------------+-------------------------------------+
Note the status line within the above output; it says RUNNING. This indicates that the machine is ready to be used.
GCE instance states and transitions
Every instance in GCE has a defined status lifecycle, as shown in the preceding figure, and the following states are known:
Status |
Description |
PROVISIONING |
Resources are being reserved for the instance, but the virtual machine is not running yet. |
STAGING |
Resources have been acquired for the instance, and the virtual machine is prepared for launch. |
RUNNING |
The instance is booting up or running. |
STOPPED |
The instance has been either shutdown, or it failed. Subsequently, it will either reboot (changing to PROVISIONING), or stop (changing to TERMINATED). |
TERMINATED |
The instance has been either shutdown or it failed, and rebooting the virtual machine is not an option. This status is permanent, and the instance must be deleted and recreated. |
Logging in to your instance
As mentioned before, the default network setup allows you to connect to your instance via the SSH protocol. GCE automatically handles key management for you and your project members. To relieve you from the hassle of key handling, gcutil wraps SSH and takes care of sorting out password-less authentication correctly.
To login to your instance via SSH, run the following command from your workstation computer:
% gcutil --project=<project_id> ssh <instance_name>
For our example, you would do the following:
% gcutil --project=packt-gce-starter ssh hello-gce INFO: Zone for 'hello-gce' detected as u'europe-west1-a'. INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o
CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/packt
/.ssh/google_compute_engine -A -p 22 [email protected] -- [omitted] packt@hello-gce:~$
As mentioned before, GCE takes care of SSH through the gcutil. In fact, gcutil does a lot! Most importantly, it checks whether you already have a public/private key pair and, if not, creates one for you. It also takes care of uploading your public key to the Google Cloud Console and associating it with your Google user account. In addition, it automatically injects your public key into every instance so that you can directly login, even if you did not set up a user account within the OS image.
If you wish to use a different SSH client, you will have to manage usage and the upload of the correct key manually. gcutil stores the generated key pair in your home folder under the hidden directory ~/.ssh. There, you will (besides others) find two files:
- google_compute_engine (your private key)
- google_compute_engine.pub (your public key)
Even if you do not wish to use gcutil for SSH’ing into your virtual machines, you should go through its setup routine at least once so that your keys are generated and uploaded to the Google Cloud Console; otherwise, you will not be able to login.
One ring to rule them all
During initial key ring generation, gcutil will ask you to enter and repeat a passphrase to protect your SSH key. Although you can leave the passphrase empty, we strongly recommend not doing so. If you do not protect your key with a passphrase, anyone who gets hold of your workstation computer can easily copy your key and will then have full administrative access to your whole GCE infrastructure!
Summary
Thus we learned how to get started with creating and running your infrastructure in the Cloud and few concepts that make up a well-performing GCE system.
Resources for Article :
Further resources on this subject:
- Blogger: Improving Your Blog with Google Analytics and Search Engine Optimization [Article]
- Google Earth, Google Maps and Your Photos: a Tutorial [Article]
- Search Engine Optimization using Sitemaps in Drupal 6 [Article]