Hi, I’m Philip from the HANA Academy. In
this series of videos were looking at
R Integration for SAP HANA. In this
video we're going to look at how you can
get R up and running in the cloud
landscape so that you can do some
testing and play around with the R
Integration of for HANA, maybe if you’re using
HANA Express. Now it's not supported,
not recommended that you install R on
the HANA server but it's actually very
easy and actually very inexpensive or
even free to get R running actually in
a cloud landscape. So with Google Cloud
Platform, GCP for example, you can use the
free trial and you can actually have
your R server up and running for free.
Similar with AWS or Azure or any other
landscape. We’re not going to focus on
productive use here. So we're talking
really about just a very simple and
straightforward way that you can get R
and RSERVE up and running and access
that from HANA.
So I'm logged in to Google Cloud
Platform and in fact I'm going to be
able to create an instance but before I
do that I'm just going to show that one
thing you'll need to do is make sure
that you can access your R server from
another landscape. So from your HANA
machine. So I'm just going to go down and
look at the VPC Network and choose the
firewall rules and you'll see that I've
already created a rule and it's very
easy and different depends on your
landscape. A rule actually here called
RSERVE and what this rule does. It
basically says that for a certain port
is going to be open. So TCP port 30020
which is the port I'm going to use. You
could use any port you like. That port is
going to be open. So I've created a
firewall rule called RSERVE. Now we're
going to actually come and reference
that in a moment. So I'm going to copy
that.
So that's something you just need to be
aware of actually to make your system
accessible. So in Google I'm going to go
to the cloud launcher which is a very
easy way to get a system up and running
and I'm going to search for a solution.
I'm going to go for CentOS. Okay and CentOS
7 but of course you could put this on
any Linux you want to. I'm going to
launch that on compute engine and if we
want to get the really, really cost
efficient way of working we should
choose a machine type which is micro.
Which will give you minimal capacity but
it just means you can actually,
actually run some tests. You can see
that that actually is just four dollars 79 a
month if you're paying or if you've got
your free trial where you've got several
hundred dollars of credit then it's not
going to cost you anything at all and of
course you can choose where you put it
because depending on the landscape the
price may be slightly different. So here
for example it's slightly cheaper in a
US Central. So just four dollars 28
a month. It would normally cost if
you left it running, up and running
all the time. It’s really really very
inexpensive or cost efficient. So we've
chosen the Machine type. We’re gonna have
CentOS created. Now the one thing we do
want to mention as we just talked about
the networking a minute ago in the
firewall. I'm going to add in a network
tag and I'm going to paste in RSERVE.
So that means that port 30020 is going
to be open on this to the world. Of
course you can control how that exactly
works through the firewall because we
want to be able to access this from our
HANA system which may be in a
completely different landscape or just
running in VMware on your laptop. So
let's go ahead and create our CentOS
instance. So when we get the green tick
it means it's actually up and running
and the next thing we want to do is
actually go ahead and connect to it. So
if we select it. We see there's an SHH
option. So I can just, I don't even need to
put you anything. I can just directly
connect using SSH. So now I'm connected
to the server. Now I'm going to want to
run some scripts but the first thing
we'll just do. Let's just check on that
machine that R is not already installed.
We can do which and then R in capitals
and if it finds it'll tell us where but
no it's not there. So it looks like R
is not installed. Now to save you typing
lots of code in by hand actually in the
GitHub repository for R Integration on
the HANA Academy. So GitHub.com SAP HANA
Academy. Go to repositories, R
Integration. Actually got the scripts. The
commands we're going to use in the code
snippets for this video which is video
R 12 Installing R in GCP. So we've
actually got some code. We can copy and
paste. So the next thing we're going to
do is
we're gonna get a Sudo access. So let's
just go back there and choose our window.
So sudo access. So sudo. What's safe
is putting sudo on every command. Be
very, very careful if you do that. You've
got root access you could make a
complete mess of your machine very, very
easily with this access. So just be very
careful in what you're doing. Now the
next step is we want to install R and
we can use YUM to do that. It’s a very,
very straightforward. We don't have to
build it or anything. We can just paste
that in and go ahead and install R. Now
that's gonna take a couple of minutes to
run. So R is now installed. So the next
thing we would want to do is actually
start R. So we can just type R,
capital R. It will open it up. What we
want to do is actually install the RSERVE
package. I've got the code snippet
for that. We can go to install packages
RSERVE. So let's just paste that in and
then you'll need to select a CRAN Mirror.
Choose the one that's closest to you. For
me probably forty seven is it good one
for where I'm based. So that's now done.
Don't worry if you see some warning
messages during that process. If
you want we can verify that it's working
by using the library command. So library
and then Rserve in quotes and if you
get nothing back everything is working
fine. Now of course at this point you may
want to install any other R packages
that you're gonna use to do stats on
machine learning with. Assume you're
going to be familiar with that as an R
user. But now we can quit. The next thing
we're gonna do is actually to create a
configuration file. So let's just get out
of R. So let's quit and we will not
need to save. So just choose n. So the
next thing we're gonna do, and I pasted
that, is to create a new file called in
etc, Rserv.conf for our
configuration. Press I so that we can
insert and what we're going to need to
do is put in remote enable. So this will
mean that we can access it remotely. So
remote
enable. Escape and then : wq to
save it. So that's now been done. So the
next thing we're going to do is actually
make sure that we have read access to
this file. So we'll do a change mode on
it to add read access. So again we'll
paste that. Okay we're going to create a
user because we don't want to give
people are connecting to R server access
to the full Linux machine. We just want
them to be able to access R. So we're
going to create a user. So we'll call it
R user. Call it whatever you want. So
created a local user and now for that
user I'm gonna create a shell script.
We'll call it R start. Which was going
to be how that user can start up R itself.
In fact specifically starting up the
RSERVE component. So again inserts for an
I for insert and I'm going to paste in
these two lines which are here. So let's
paste that in. So what it's actually
doing. It’s changing to that user’s
bin directory and then it's also
doing a pgrep basically to check is
RSERVE up and running and if not it's
actually going to do the R command
with RSERVE option using port 30020.
Which is the one we decided we're gonna
use. Obviously you could use another one. So
let's escape : wq to get out of the
wonderful VI editor. We need to make sure
we can execute this shell script.
So we've got a quick chmod command to
run. So that R start shot script
actually can be executed. Okay so we're
good. Now we've got a way that we can
actually start up R. Now what we really
want to do is make it that it's every
time we start the machine R’s going to
come up automatically. So for that we can
use crontab and what were actually
gonna do is set one up that will run
every two minutes. So let's open crontab
- e to edit. Again I to insert. It’s a bit
like with VI and then this is the
command we're going to use to actually
do R starting. It’s going to call R
shell script. So let's paste that in and
basically the stars basically refer to
minutes, R seconds, days whatever. So
basically this setting here says every
two minutes I want you to check if R is
started by running that shell script and
it'll basically run the script every two
minutes and that shell script will check
if it started and if it is it was fine.
If not it will write some message to the
error Rstart.error file.
Okay so let's escape : WQ to save that. So
we've now got that crontab up and
running. So we should be fine. Now if one, if
we can actually see if we've actually
got RSERVE actually running. See if
the processes there by using this
pgrep command. Again looking at the port
and the RSERVE command. Now right now
there's nothing there but if we were to
wait two minutes which will now do then
we should find that that thing has run.
The crontab actually has run every two
minutes and it will have started
RSERVE up. Let's try it once more. Now we
see we've got process 4 9 8 6. So RSERVE
is up and running. Basically that's
all we need to do to make it work. So we
can just get out of there. Exit from the
sudo and then exit. We can go back. Now
one thing just to do in compute engine.
We need to know how we're going to
access machine. So we're going to need to
find where it's accessed. So we can need
to look for the external IP. Now if we're
going to access it from some other
landscape then it would need to be the
external IP. Say if you actually got SAP HANA
Express running in Google Cloud Platform
in the same account and locally then you
could maybe get away with using the
internal IP. We’re actually on the same
sub network. So External IP. I'm gonna
copy that. We’re going to need that in a
moment. Now I've got a HANA Express
landscape. It’s actually set up in there
a different cloud provider. It’s in AWS.
So we'll see if we can get from AWS to
GCP where the RSERVE is. Now this is
all outlined in previous video. So I'm
not going to explain the detail. We’ve
been through this before. But I'm going
to just go to the getting started for
HANA 2.0. So I can create my R user. In fact
I'm gonna copy code and I'm gonna run it
against my tenant database. However, I
need to set the configuration of the
server and port. Well it’s 30020 we're using
but the server that was what I just
copied actually from here. The external
IP of my RSERVE. So I'm gonna paste
that in. Okay so let's go ahead and run
this code. So it should now have created
a remote source for us. It created a user.
So I'm gonna add my R user. So HXE host
is my HANA Express tenant and instance
number 90. That's default tenant database
HXE and then user is R user with its
default password and I'll be expected to
change that. So I'm now logged on as my
R user. So I can actually go ahead, open
up a SQL window and now go back to
GitHub and we've got that clustering
example. Again seen in a previous video.
So we can go ahead and copy the code.
Just a very simple example using the
clustering algorithm. Let's copy that and
let's paste it and actually we can't do
this inline results in Database Explorer
with everything else. I'll comment it out.
We'll put the results in table. We’ve seen
this code in a previous video. So it
won't go through it in detail. Let's run
and it's run and if we look at our
second result. We’ve got ID and cluster.
So we have done clustering on a number
of rows of data that we actually sent
and it's all working against our remote
R server and if we were to look at the
catalog entry and for R user and to
look at the tables. In fact we can again
see our results table. Open data and
we've done it. So in just a few minutes
we were actually just start from scratch
creating an R server in Google
Cloud Platform using CentOS. Installing
R and RSERVE configuring that and
then we were able to access it using
HANA Express. Which happens in this case
to be an AWS.
You can find more HANA video tutorials
on our YouTube channel. If you'd like to
be informed as soon as new video
tutorials are published please subscribe
to the channel. You can also connect with
us on LinkedIn, follow us on Twitter and
we have pages on Facebook and Google+.
Code snippets and demo data for all of
our tutorials are published to GitHub.
Thanks for watching.