File this under "what I wished was on the web whilst trying to do this myself."
edit 20th November, 2016 - now everything in this post is abstracted away and available in the googleComputeEngineR package - I would say its a lot easier to use that. Here is a post on getting started with it. http://code.markedmondson.me/launch-rstudio-server-google-cloud-in-two-lines-r/
edit 30th April, 2016: I now have a new post up on how to install RStudio Server on Google Compute Engine using Docker, which is a better way to do it.
edit 30th Nov, 2015: Oscar explains why some users couldn't use their username
edit 5th October: Added how to login, add users and migrated from gcutil to gcloud
Google Compute Engine is a very scalable and quick alternative to Amazon Web Services, but a bit less evolved in the images available for users.
If you would like to have a VM with R 3.01, RStudio Server 0.98 and OpenCPU installed, then you can click on the link below, and install a pre-configured version for you to build upon.
With this image, you have a cloud server with the most popular R / Cloud interfaces available, which you can use to apply statistics, machine learning or other R applications on web APIs. It is a fundamental building block for a lot of my projects.
The VM image is here. [940.39MB]
To use, follow these steps:
Downloading the instance and uploading to your project
- Create your own Google Cloud Compute project if you haven't one already.
- Put in billing details. Here are the prices you'll pay for running the machine. Its usually under $10 a month.
- Download the image from the link above (and here) and then upload it to your own project's Cloud Storage. Details here
- Add the uploaded image to your project with a nice name that is only lowercase, numbers or includes hyphens (-). Details here. You can do this using gcloud and typing:
$ gcloud compute images create IMAGE_NAME --source-uri URI
Creating the new Instance
- Now go to Google Compute Engine, and select Create New Instance
- Select the zone, machine type you want (i.e. you can select a 50GB RAM machine if needed for big jobs temporarily)
- In the dropdown for images you should be able to see the image from step 4 above. Here is a screenshot of how it should look, I called my image "r-studio-opencpu20140628"
Or, if you prefer using command line, you can do the steps above in one command with gcloud like this:
$ gcloud compute instances create INSTANCE [INSTANCE ...] --image IMAGE
Using your instance
You should now have RStudio running on http://your-ip-address/rstudio/ and openCPU running on http://your-ip-address/ocpu/test and a welcome homepage running at the root http://your-ip-address
To login, your Google username is an admin as you created the Google cloud project. See here for adding users to Google Cloud projects.
If you don't know your username, try this command using gcloud to see your user details:
$ gcloud auth login
Any users you add to Debian running on the instance will have a user in RStudio - to log into Debian and add new users, see below:
$ ## ssh into the running instance
$ gcloud compute ssh <your-username>@new-instance-name
$ #### It should now tell you that you are logged into your instance #####
$ #### Once logged in, add a user: example with jsmith
$ sudo useradd jsmith
$ sudo passwd jsmith
$ ## give the new user a directory and change ownership to them
$ sudo mkdir /home/jsmith
$ sudo chown jsmith:users /home/jsmith
Oscar in the comments below also explains why sometimes your username may not work:
Like other comments, my username did not work.
Rather than creating a
new user, you may need to simply add a password to your user account:
$ sudo passwd .
Also, the username will be your email address with the '.' replaced with '_'. So firstname.lastname@example.org became xx_yy
You may also want to remove my default user the image comes with:
$ sudo userdel markedmondson
...and remove my folder:
$ sudo rm -rf /home/markedmondson
The configuration used
If you would like to look before you leap, or prefer to install this yourself, a recipe is below. It largely cobbles together the instructions around the web supplied by these sources:
Many thanks to them.
It covers installation on the Debian Wheezy images available on GCE, with the necessary backports: