Creating a Google Cloud Virtual Machine Instance.
- Google Cloud Platform account.
- Knowledge of which OS you wish to run (we recommend Centos 7).
- Tiger Vnc (or any Remote Desktop/screen share tool on the local machine).
- SSH Key (For usage in connecting to the vm) – See instructions for creating one below.
To create a engine and install engine in a google cloud environment we need to:
- Create an ssh key
- Create a google vm instance and link to the the ssh key
- Connect to the vm and update it.
- Install a desktop environment on the vm.
- Install tiger vnc (or any remote desktop tool)
- Setup vnc port forwarding to port 2 and remote desktop into the vm
- Copy engine installer on to the vm
- Install engine and setup eflow like a standard installation.
Step 1: Creating an SSH key : Prerequisite
To create an SSH key we use the command ssh-keygen to generate a private and public ssh key.
The generic command to be run from the local machine:
- ssh-keygen -t rsa -f <path>/<keyname> -C <username> -b 2048
- <path> is the file system path where we want to write out the key.
- <keyname> is the name of the key we wish to use.
- <username> is the user name of the account we want on the google VM
So in the case I have create a Google key folder in my documents:
- <PATH> = /Users/sampleuser/Documents/googlekeys/
- <keyname> = examplekey
- <username> = sampleuser
Give us the command:
- ssh-keygen -t rsa -f /Users/sampleuser/Documents/googlekeys/ examplekey -C sampleuser -b 2048
At this point you will be asked to set a passphrase – this is an optional password when using the newly create key for connection. It is recommended you set one, but you will need to to enter the password for you key every time the key is used for connection.
Note the pass pharse is separate to any of the google passwords set for the VM. Afterwards 2 sshkeys will be created with the name stated. One public (ending with a .pub extension) and one private with no extension.
Creating the VM
Login to the google cloud platform and navigate to “Compute Engine” In the Left hand column navigate to VM instances. At the top of the page click Create Instance.
This will open up a new window. From here you can setup all the basic VM configurations.
General Setup Notes:
Region : Select the same region that you have (or would like to have) your bucket in. This will avoid additional transfer charges when transferring data between bucket and vm.
OSType: To set the OS type Scroll down to the boot disk and click Change
Select the require Operating system from the drop downs – we recommend centos 7.
Access Scopes: This depends on your use case. By default though you can not upload files to a bucket. It is recommend you use Set access for each api option and manually decide which setting you wish to enable. To allow upload and downloads to a bucket ensure STORAGE is READ/WRITE or FULL
Firewall : we allow both HTTPS and HTTP (This is use case specific)
Specs: We recommend 24GB of ram per esp for perm instances.
Once you have set up your vm with the required settings click create.
NOTE at this point we have NOT attached the SSH key and we CANNOT connect via SSH.
After creating the Instance we need to EDIT the instance to add the SSH key we created in step 0 (or use and existing SSH key).
To edit the instance simply double click the newly created instance from the table. (This should be list in the vm instances page after creation)
Then click the Edit button near the top of the page.
Scroll down to Security and access - SSH keys.
Click add item. Then copy the contents to of the public SSH key into the text box
Note to get the contents you can open the sshkey.pub with various text editor tools and simply CTRL A, CTRL C, to copy the contents. Then paste them into the google webpage.
Afterwards, Click save to confirm adding the SSH key.
Connecting to the VM
To connect to the linux vm you can either user putty, SSH or various other tools. If you create a windows Instance you can simply export a RDP (remote desktop file) from google and connect straight to your windows instance.
We will use SSH in this example.
ssh -I <pathToKey>/<keyname> <username>@<external IP>
- <pathToKey> is the path to the ssh key
- <keyname> is the ssh key name
- <username> is the set username when creating the ssh key
- <Exteneral ip> is the ip address of the vm instance
Note unless configured, the External IP address can and will change if you stop your instance. The External IP address can be found in the VM instances page, in the table of Google VM's
So to connect to a VM we can use the settings below:
- <pathToKey> = Users/YourAccount/Documents/keys/
- <keyname> = googlekey
- <Username> = *Your Username*
- <External Ip> = 18.104.22.168
ssh -i /Users/tristansear/Documents/keys/googlekey
If it was setup you will be prompted for the SSH key’s password. Afterwards, you should be connected to the Google VM.
Now we need to update the VM and install a Desktop Environment
To update the VM Run: Sudo yum update
To install Gnome Desktop Run: sudo yum -y groups install “GNOME DESKTOP”
Set Gnome to run by Default Echo “exec gnome-session” >>~/.xinitve
Sudo bash -c ‘echo PREFERED=/usr/bin/gnome-session >/etc/sysconfig/desktop’
Sudo systemctl set-default graphical.target
At this point, it is recommended you set a password for the ssh user/ the default vm user.
sudo passwd <username>
Next, we want to install Tiger VNC
Sudo yum install tigercvnc-server
After vnc is installed you need to set the vnc password via the command
Now you can either run vncserver:2 each time you start the vm to start a vnc server to connect to or its possible to start the server automatically.
To run the VNC server automatically
Next copy the the vncserver@.service file to etc/system/system/vncserver@:2.service (note 2 is the port you wish to connect to vnc to it can be any number bar 1 as that interferes with eflow service)
sudo cp /lib/systemd/system/vncserver@.service
next you need to edit the /etc/systemd/system/vncserver@:2.service and replace any instance of <user> with the current instance user.
sudo vi /etc/systemd/system/vncserver@:2.service
- I: to edit and replace any instance of <User> with current user.
- ESC: to exit out of insert/edit mode
- *Spacebar* + wq!: To exit out of VI and save the changes
At this stage it is recommended to restart the Google VM instance.
If you haven’t already, disconnect from the current session.
We now need to connect via port forwarding. To do this add -L <port> localhost<port> As we setup the vnc server on port 2 we connect to port 5902 on the local machine. Therefore to connect to the same VM we now have the SSH command.
ssh -L 5902:localhost:5902 -i /Users/*Your Username*/Documents/keys/googlekey *Your Usernameemail@example.com We can then run VNC on the localmachine and connect to localhost:5902 to share screens with the Google VM.
Next, we need to copy the Engine installer onto the VM.
We use scp:
- scp -i <pathtokey>/<keyname> <username> <path to file>/<filename> <username>@<externalip>:<path on vm to copy to>
- scp -i /Users/*Your Username*/Documents/googlekeys/googlekey *Your Username* /Users/*Your Username*/Desktop/ engine.x86_64.rpm *Your Usernamefirstname.lastname@example.org:~
Once engine eval/perm has been copied to the VM simply follow the installer document to install like normal.