B4J Tutorial [GCE] For Noobs, Part 3 - Creating an Empty Virtual Machine

We’re now ready to start creating virtual machines that will be used to host our B4J application/s. We’ll be creating a small VM in this tutorial.

On the left side of the screen, in our dashboard, locate the menu ‘Compute Engine’ which is in the section labelled COMPUTE and click on it. There is another sub-menu that appears when your mouse cursor hovers over the menu - ignore that for now. By default when you click on the menu item you will be taken to the first sub-menu item - in this instance it is the VM Instances sub-menu option.

Initially, there will not be any VMs listed because you haven’t created any … yet. It will take a few short moments for Compute Engine to set things up for you for the first time. Once it is finished click on the Create button and you will be taken to the ‘Create an instance’ section.

Jargon: ‘instance’ - is a VM. It’s Google’s name for a VM. I’ll use this interchangeably at times.

In this section there may be some fields already filled in and just to the right you will also notice a price (shown in the below image)


Don’t worry about that for now. It’s a simple monthly estimate of the cost of the VM based on the current settings initially chosen for them VM.

Note: Pricing will vary from one Zone to the next.

‘Zone’ - is both a region and an area/zone within the region. It is where the resources for the VM will be located and also where the data will be stored.

But, we’re jumping ahead slightly here. Let’s go through each of the fields on the screen.

This is the name of the VM (instance). It is what will be used in other sections to identify a VM.

This specifies where you want the VM to be hosted. The Zone combines both the region and zone. A region is a physical location somewhere on the Globe while a Zone is a location within the region. A single Datacentre can have several Zones isolated from each other.

Machine Type
This is where you specify how many CPUs and how much RAM you want for the VM. Pricing is calculated per CPU and by the amount of RAM you need.

Google will sometimes provide some useful hints about a VM indicating if it should have more or less CPU/RAM depending on the usage of the VM over a period of time. This is a good feature and can save you money if you have created a VM with more resources than it really needs.

If you look at the available list of Machine Types you can see that there are a quite a few options to choose from. If you are migrating a physical machine to a VM then simply choose the machine type that best matches the physical machine. However, if you KNOW that the physical machine is under-powered for the work it does then here’s your chance to add a bit more ‘grunt’ to the machine.

The ‘micro’ and ‘small’ machine types make use of ‘shared cpus’. This means that the CPU is shared across other VMs that may or may not (most likely the latter) be in your project. If you’re creating a simple test VM or a VM that doesn’t need a lot of resources then these machine types are a good choice as they are cheap and perform quite well.

Boot disk
This is the Operating System (OS) to use on the boot disk as well as the size of the boot disk. By default all boot disks are set to an initial size of 10GB with the exception of the Windows Server types which have an initial size of 50GB. This is large enough for most small apps and web sites. However, if you need to change the size of the boot disk then click on the ‘Change’ button and you’ll be presented with a list of available OS’s and you can also change the size of the boot disk (from memory I think the largest boot disk size you can have is a very modest 2TB). For these tutorials, I’ll be using Debian 9 Stretch as the OS. This will install MariaDB instead of MySQL. If you want to use MySQL then choose Ubuntu 17.10 for the OS. There’ll be more on MySQL and MariaDB in a later tutorial.

OS’s available include quite a few different versions of Linux and there are also MS Windows Server OS’s available. If you plan to use the MS Windows Servers OS’s then you will need to check the T&C’s of the Free Trial Period to ensure that these OS types are included in the offer.

One thing to note is that most, if not all, of the Linux servers do not require a monthly licence fee. MS Windows Server instances, on the other hand, do require you to pay for a monthly licence fee. An advantage to MS Windows Server is that if you require access to a remote desktop then this is easily done.

Lastly, if you are planning to have your B4J console app and database hosted on a single server AND you know that there will be a lot of data stored in the database then increase the size of the boot disk.

Note: it is possible to add more disk space by adding additional disks. This is outside the scope of this tutorial and may be covered in a later tutorial.

Identity and API access
Change the ‘Access scopes’ to ‘Allow full access to all Cloud APIs’. If this is not done then copying files to the VM will be slightly problematic and impossible even. If you forget to set this option and you later get errors when attempting to copy then this might be the issue. To fix the issue, you’ll need to stop the VM instance, edit the VM Instance which will allow you to change this setting and then you will need to Start the VM Instance.

In a nutshell, it’s much simpler to set this here now.

There are two checkboxes available that can be used to enable HTTP or HTTPS access to the VM. HINT: if you plan to deploy/install your own B4J Web App onto a GCE VM then these checkboxes should be checked ;)

Management, disks, networking, SSH keys
This is outside the scope of this tutorial. A future tutorial might be created to cover this in some detail.

Okay, we’re going to modify the default options for our first VM. Change the Machine Type to ‘micro (1 shared vCPU)’ and change the ‘Zone’ to a zone that is near your physical location. Make that there are ticks in the two Firewall checkboxes to allow HTTP and HTTPS web access to the VM. Also, change the Name to something that makes sense. Eg. use a name that best describes the application that will run on the VM. eg. web-server-1. Our chose settings for our first VM will cost us just $4.28 per month (from memory I believe the pricing is shown in USD)

Note: a shared vCPU is a CPU that is a) virtual and b) is shared between your VM and other VMs running on the same physical hardware as your VM. Performance of the VM can be impacted if the vCPU is heavily utilised by other VMs.
You need to decide if you need a VM with more CPU resources.

Note: pricing of a VM is highly dependent of the resources allocated to it. VMs that use shared vCPUs are cheaper. The more CPU resources your VM requires then the higher the monthly cost. Memory required for your VM is another factor contributing to the monthly cost.

Click on the Create button. After a brief moment you will be taken back to the VM instances dashboard. You will also see that GCE is now busy creating your new VM instance for you :)

When the VM is ready you will see something like the below


Sweet! You now have a VM up and running. It’s not doing very much right now but we will get to that in the coming tutorials.

Note: The VM created is like a barren desert. What I mean is that there’s nothing running on it except for Linux right now. There’s no Java Runtime or MySQL or Apache or Minesweeper or anything else for that matter. It’s up to us to install whatever we need to run on the VM.