rstudio in aws 16 9

74
Rstudio Server on Amazon EC2 Liad Shekel [email protected] June 2015 Liad Shekel Rstudio Server on Amazon EC2 1 / 72

Upload: tal-galili

Post on 30-Jul-2015

7.188 views

Category:

Internet


3 download

TRANSCRIPT

Page 1: Rstudio in aws 16 9

Rstudio Server on Amazon EC2

Liad Shekel

[email protected]

June 2015

Liad Shekel Rstudio Server on Amazon EC2 1 / 72

Page 2: Rstudio in aws 16 9

Rstudio Server on Amazon EC2Outline

1 Amazon Web Services (AWS)HistoryServicesAmazon EC2Create an AWS Account

2 SSH and Asymmetric CryptographyBasic terminologyLaunch an EC2 instanceConnect to EC2 instance via SSH

3 Install R on Ubuntu ServerLinux basicsInstall R on Ubuntu ServerInstall Rstudio on Ubuntu Server

Liad Shekel Rstudio Server on Amazon EC2 2 / 72

Page 3: Rstudio in aws 16 9

History

1994-20061994: Jeff Bezos founded Amazon2002: AWS was developed for Amazon’s internal infrastructure2003: AWS started building an "infrastructure service for the world.”2006: Amazon launched “Amazon Simple Storage Service” (Amazon S3) and a virtual computingenvironment called “Amazon Elastic Compute Cloud” (Amazon EC2)

Liad Shekel Rstudio Server on Amazon EC2 3 / 72

Page 4: Rstudio in aws 16 9

How big is Amazon Web Services?

Today

About 1.4 million servers working around the globe158k − 450k servers1/3 of all internet users will access an AWS cloud site at least once a day (2012)1% of all internet traffic (2012)

Liad Shekel Rstudio Server on Amazon EC2 4 / 72

Page 5: Rstudio in aws 16 9

Amazon Web Services (AWS)Services

Liad Shekel Rstudio Server on Amazon EC2 5 / 72

Page 6: Rstudio in aws 16 9

Amazon Web Services (AWS)Amazon Elastic Compute Cloud (EC2)

Liad Shekel Rstudio Server on Amazon EC2 6 / 72

Page 7: Rstudio in aws 16 9

Amazon Web Services (AWS)Amazon Simple Storage Service (S3)

Liad Shekel Rstudio Server on Amazon EC2 7 / 72

Page 8: Rstudio in aws 16 9

Amazon Web Services (AWS)Amazon Relational Database Service (RDS)

Liad Shekel Rstudio Server on Amazon EC2 8 / 72

Page 9: Rstudio in aws 16 9

Amazon Web Services (AWS)NoSQL database service (DynamoDB) * Petabyte-scale data warehouse (RedShift)

Liad Shekel Rstudio Server on Amazon EC2 9 / 72

Page 10: Rstudio in aws 16 9

Amazon Web Services (AWS)Analytics (Hadoop, ML as a service)

Liad Shekel Rstudio Server on Amazon EC2 10 / 72

Page 11: Rstudio in aws 16 9

Amazon EC2Next: EC2 instances

Liad Shekel Rstudio Server on Amazon EC2 11 / 72

Page 12: Rstudio in aws 16 9

Amazon Elastic Compute Cloud (EC2)Introduction

Marketing lines

Scale to your needs - Amazon EC2 provides re-sizable compute capacity which allows to quicklyscale capacity, both up and down, as your computing requirements change.Pay per hour - Amazon EC2 allows you to pay only for capacity that you actually use.

Buttom lineEC2 instance is a remote

{server / machine / virtual machine / instance / computer / host }

with flexible and changeable specifications.

Liad Shekel Rstudio Server on Amazon EC2 12 / 72

Page 13: Rstudio in aws 16 9

Create an AWS Account

Link: www.aws.amazon.com

Liad Shekel Rstudio Server on Amazon EC2 13 / 72

Page 14: Rstudio in aws 16 9

Create an AWS Account

Liad Shekel Rstudio Server on Amazon EC2 14 / 72

Page 15: Rstudio in aws 16 9

Create an AWS Account

Liad Shekel Rstudio Server on Amazon EC2 15 / 72

Page 16: Rstudio in aws 16 9

Create an AWS AccountLogin credentials

Liad Shekel Rstudio Server on Amazon EC2 16 / 72

Page 17: Rstudio in aws 16 9

Create an AWS AccountContact information

Liad Shekel Rstudio Server on Amazon EC2 17 / 72

Page 18: Rstudio in aws 16 9

Create an AWS AccountPayment information

Liad Shekel Rstudio Server on Amazon EC2 18 / 72

Page 19: Rstudio in aws 16 9

Create an AWS AccountIdentity verification (1)

Liad Shekel Rstudio Server on Amazon EC2 19 / 72

Page 20: Rstudio in aws 16 9

Create an AWS AccountIdentity verification (2)

Liad Shekel Rstudio Server on Amazon EC2 20 / 72

Page 21: Rstudio in aws 16 9

Create an AWS AccountIdentity verification (3)

Liad Shekel Rstudio Server on Amazon EC2 21 / 72

Page 22: Rstudio in aws 16 9

Create an AWS AccountSupport plan

Liad Shekel Rstudio Server on Amazon EC2 22 / 72

Page 23: Rstudio in aws 16 9

Create an AWS AccountConfirmed

Liad Shekel Rstudio Server on Amazon EC2 23 / 72

Page 24: Rstudio in aws 16 9

Create an AWS AccountWait...

Liad Shekel Rstudio Server on Amazon EC2 24 / 72

Page 25: Rstudio in aws 16 9

Create an AWS AccountDone!

Liad Shekel Rstudio Server on Amazon EC2 25 / 72

Page 26: Rstudio in aws 16 9

Create an AWS AccountNext: EC2 instances

Liad Shekel Rstudio Server on Amazon EC2 26 / 72

Page 27: Rstudio in aws 16 9

Amazon Elastic Compute Cloud (EC2)First glance

Link: https://console.aws.amazon.com

Liad Shekel Rstudio Server on Amazon EC2 27 / 72

Page 28: Rstudio in aws 16 9

Amazon Elastic Compute Cloud (EC2)Instances

Liad Shekel Rstudio Server on Amazon EC2 28 / 72

Page 29: Rstudio in aws 16 9

Launch EC2 InstanceChoose Amazon machine image (AMI)

Liad Shekel Rstudio Server on Amazon EC2 29 / 72

Page 30: Rstudio in aws 16 9

Launch EC2 InstanceChoose an instance type

Liad Shekel Rstudio Server on Amazon EC2 30 / 72

Page 31: Rstudio in aws 16 9

Launch EC2 InstanceHow much does it cost? (1)

Liad Shekel Rstudio Server on Amazon EC2 31 / 72

Page 32: Rstudio in aws 16 9

Launch EC2 InstanceHow much does it cost? (2)

Liad Shekel Rstudio Server on Amazon EC2 32 / 72

Page 33: Rstudio in aws 16 9

Launch EC2 InstanceInstance details

Liad Shekel Rstudio Server on Amazon EC2 33 / 72

Page 34: Rstudio in aws 16 9

Launch EC2 InstanceSSD / Magnetic Storage (30GB in free tier)

Liad Shekel Rstudio Server on Amazon EC2 34 / 72

Page 35: Rstudio in aws 16 9

Launch EC2 InstanceAdd tags

Liad Shekel Rstudio Server on Amazon EC2 35 / 72

Page 36: Rstudio in aws 16 9

Launch EC2 InstanceSecurity groups

Liad Shekel Rstudio Server on Amazon EC2 36 / 72

Page 37: Rstudio in aws 16 9

Launch EC2 InstanceReview and launch!

Liad Shekel Rstudio Server on Amazon EC2 37 / 72

Page 38: Rstudio in aws 16 9

Launch EC2 InstanceOh. Wait... Key pair? SSH?

Liad Shekel Rstudio Server on Amazon EC2 38 / 72

Page 39: Rstudio in aws 16 9

Launch EC2 InstanceOh. Wait... Key pair? SSH?

Liad Shekel Rstudio Server on Amazon EC2 39 / 72

Page 40: Rstudio in aws 16 9

Kay Pair and Asymmetric CryptographyPublic-key encryption

Public-key encryption and authentication

The “message“ is encrypted on the remote machine using the client’s public keyThe “message” can be decrypted only with the matching private keyRSA is one example of a public-key algorithm. RSA is based on the practical difficulty of factoring theproduct of two large prime numbers.

Liad Shekel Rstudio Server on Amazon EC2 40 / 72

Page 41: Rstudio in aws 16 9

Secure Shell (SSH)What is an SSH protocol?

BasicsA shell is a user interface for access to an operating system’s servicesA Secure Shell (SSH) is an encrypted network protocol for initiating text-based shell sessions onremote machines in a secure way

Client side requires SSH client (such as Putty or MobaXterm)Remote side require SSH server (build-in Ubuntu server)

The Secure File Transfer Protocol (SFTP) is an SSH extension that provides file access, file transfer,and file management functionalitiesUsually, SSH uses port 22SSH uses Asymmetric cryptography

Liad Shekel Rstudio Server on Amazon EC2 41 / 72

Page 42: Rstudio in aws 16 9

Asymmetric cryptographyIn practice

How? What? Where?On the remote server there should be a list of authorized public keys. The corresponding private keysare authorized for connection.The authorized_keys file is located in

/home/<user_name>/.ssh/authorized_keys

To connect to the remote server, make sure that your public key appears in the authorized_keys file(on the server)Choose your private key file on the SSH client configurationsThat’s it

Liad Shekel Rstudio Server on Amazon EC2 42 / 72

Page 43: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)We’re back!

Liad Shekel Rstudio Server on Amazon EC2 43 / 72

Page 44: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Download your new private key

Liad Shekel Rstudio Server on Amazon EC2 44 / 72

Page 45: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Congrats!

Download here: https://goo.gl/k8VSS2

My new PRIVATE key!

What are we missing?

The matching public key is stored in the authorized_keys file on the instance.

Liad Shekel Rstudio Server on Amazon EC2 45 / 72

Page 46: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Congrats!

Download here: https://goo.gl/k8VSS2

My new PRIVATE key!

What are we missing?

The matching public key is stored in the authorized_keys file on the instance.

Liad Shekel Rstudio Server on Amazon EC2 45 / 72

Page 47: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Launch you first EC2 instance

Liad Shekel Rstudio Server on Amazon EC2 46 / 72

Page 48: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)

Liad Shekel Rstudio Server on Amazon EC2 47 / 72

Page 49: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Instance State: Pending

Liad Shekel Rstudio Server on Amazon EC2 48 / 72

Page 50: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Instance State: Running!

Liad Shekel Rstudio Server on Amazon EC2 49 / 72

Page 51: Rstudio in aws 16 9

Launch EC2 Instance (Cont’d)Instance State: Running!

Liad Shekel Rstudio Server on Amazon EC2 50 / 72

Page 52: Rstudio in aws 16 9

Use SSH ClientIntroducing MobaXterm

Liad Shekel Rstudio Server on Amazon EC2 51 / 72

Page 53: Rstudio in aws 16 9

Use SSH ClientNew session

Liad Shekel Rstudio Server on Amazon EC2 52 / 72

Page 54: Rstudio in aws 16 9

Use SSH ClientSession settings

Liad Shekel Rstudio Server on Amazon EC2 53 / 72

Page 55: Rstudio in aws 16 9

Use SSH ClientSSH session

Liad Shekel Rstudio Server on Amazon EC2 54 / 72

Page 56: Rstudio in aws 16 9

Use SSH ClientSSH settings

Remote host: IP addressUse private key: downloaded private key file

Liad Shekel Rstudio Server on Amazon EC2 55 / 72

Page 57: Rstudio in aws 16 9

Use SSH ClientLogin: ubuntu (default user)

Liad Shekel Rstudio Server on Amazon EC2 56 / 72

Page 58: Rstudio in aws 16 9

Use SSH ClientLogin: ubuntu (default user)

Liad Shekel Rstudio Server on Amazon EC2 57 / 72

Page 59: Rstudio in aws 16 9

Use SSH ClientThe IP address is now a known host.

Liad Shekel Rstudio Server on Amazon EC2 58 / 72

Page 60: Rstudio in aws 16 9

Use SSH ClientWelcome to Ubuntu 14.04.2

Liad Shekel Rstudio Server on Amazon EC2 59 / 72

Page 61: Rstudio in aws 16 9

Linux basicsCommand line

The Linux command structure: command OPTIONS ARGUMENTS

Command: This is the base of the command.

To show top lines of a file, use the head commandTo to create new directory use the mkdir command

OPTIONS: Alter the behavior of the command.

To show 5 or 10 top lines of a file, use the head command with option -n 5 or -n 10

ARGUMENTS: Typically file names or other data that is needed by the command.

head -n 5 file_name

Liad Shekel Rstudio Server on Amazon EC2 60 / 72

Page 62: Rstudio in aws 16 9

Linux basicsSuper User DO

First Thing to know:

sudo = Super User DO.

Example:To delete the file ’a.txt’ type: rm a.txt

However, if it doesn’t work, try: sudo rm a.txt

Example:

Liad Shekel Rstudio Server on Amazon EC2 61 / 72

Page 63: Rstudio in aws 16 9

Linux basics

List of files and directories:ls, ls -l, ls -l dir_path.

Navigate between directories:cd, cd .., cd ~, cd /, cd dir_name

Edit/create file (using nano or vim)nano file_name.R, vim file_name.R

open file in view mode (read only)nano -v file_name.R

Display Linux processes:top, htop (sudo apt-get install htop)

Liad Shekel Rstudio Server on Amazon EC2 62 / 72

Page 64: Rstudio in aws 16 9

Linux basicsAdd user

ubuntu is the default AMI (Amazon Machine Image) user.RStudio require password authenticated user.Add user:sudo adduser <username>

you will be asked for a new password (twice) and then for an optional additional information.Make yourself a sudoer (optional):sudo adduser <username> sudo

Liad Shekel Rstudio Server on Amazon EC2 63 / 72

Page 65: Rstudio in aws 16 9

Install R on Ubuntu Server

In Linux, like in R, we can download packages (≈software) from repositories.

For example, to install R run:sudo apt-get install r-base-core

Download package lists from the repositories:sudo apt-get update

Upgrade packages according to the updated information:sudo apt-get upgrade

The default repositories install old R version (3.0.2), In order to download the latest version we needto manually add repository.

Liad Shekel Rstudio Server on Amazon EC2 64 / 72

Page 66: Rstudio in aws 16 9

Install R on Ubuntu ServerAdd repository and install latest R version

Edit the sources.list file and add the R repository locationsudo nano /etc/apt/sources.list

Add this line to the end of the file:deb http://cran.rstudio.com/bin/linux/ubuntu trusty/ .To get permissions to the new repository run:sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9

Download new package lists:sudo apt-get update

Install the latest R version (3.2.0):sudo apt-get install r-base-core

Liad Shekel Rstudio Server on Amazon EC2 65 / 72

Page 67: Rstudio in aws 16 9

Install Rstudio on Ubuntu ServerOnly a few seconds away...

Rstudio installationgdebi lets you install local deb packages:sudo apt-get install gdebi-core

Download rstudio’s deb package:wget http://download2.rstudio.org/rstudio-server-0.99.446-amd64.deb

Use gdebi to install the deb package:sudo gdebi rstudio-server-0.99.446-amd64.deb

Open web browser and enter url: <server_ip>:8787Use your username and password.Do crazy things with Rstudio.

Liad Shekel Rstudio Server on Amazon EC2 66 / 72

Page 68: Rstudio in aws 16 9

Install Rstudio on Ubuntu ServerOnly a few seconds away...

Rstudio installationgdebi lets you install local deb packages:sudo apt-get install gdebi-core

Download rstudio’s deb package:wget http://download2.rstudio.org/rstudio-server-0.99.446-amd64.deb

Use gdebi to install the deb package:sudo gdebi rstudio-server-0.99.446-amd64.deb

Open web browser and enter url: <server_ip>:8787Use your username and password.Do crazy things with Rstudio.

Liad Shekel Rstudio Server on Amazon EC2 66 / 72

Page 69: Rstudio in aws 16 9

Rstudio Server on Amazon EC2

Thank you!

Liad Shekel

[email protected]

Liad Shekel Rstudio Server on Amazon EC2 67 / 72

Page 70: Rstudio in aws 16 9

Or... Rstudio AMI!

Google “Rstudio AMI” and follow the first link:http://www.louisaslett.com/RStudio_AMI/

Choosing one of the AMI would take you again to “Launch instance” screensThe new instance is created with R (3.2.0) and Rstudio-server (0.98.1103) installed (make sure youopen port 80 in the security group!)Username: rstudioPassword: rstudioSorry for not telling this earlier :-)

Liad Shekel Rstudio Server on Amazon EC2 68 / 72

Page 71: Rstudio in aws 16 9

Rstudio AMICommunity AMI

Liad Shekel Rstudio Server on Amazon EC2 69 / 72

Page 72: Rstudio in aws 16 9

Rstudio AMICommunity AMI

Liad Shekel Rstudio Server on Amazon EC2 70 / 72

Page 73: Rstudio in aws 16 9

Rstudio AMICommunity AMI

Liad Shekel Rstudio Server on Amazon EC2 71 / 72

Page 74: Rstudio in aws 16 9

Rstudio Server on Amazon EC2

Thank you!

Liad Shekel

[email protected]

Liad Shekel Rstudio Server on Amazon EC2 72 / 72