Bhaskar Karambelkar's Blog

Setting up R on a SmartOS Zone.

 

Tags: R R-Stats SmartOS HowTo


Recently I converted a spare beefy laptop (8 cores, 16 GB RAM, 750GB HD) to a SmartOS hypervisor. I wanted to play with some bare metal hypervisor / container stuff and ESXi was just not cutting it. I’m not a Solaris nerd, but I know enough Unix to find may way around in Linux/*BSDs/Solaris/HP-UX, so it was not a big pain. In fact ZFS is really nice.

Anyway, this post is about setting up R in a zone. It wasn’t very difficult to set up R in a zone but it was not completely straight forward as well.

On the SmartOS host

# Update the list of available images
imgadm update
# import the latest base-64 image (15.3.0)
imgadm import 842e6fa6-6e9b-11e5-8402-1b490459e334

Next create a file zone.json with the following content in a convenient place.

{
  "alias": "zone01",
  "hostname": "zone01",
  "brand": "joyent",
  "quota": 10,
  "max_physical_memory": 2048,
  "dataset_uuid": "842e6fa6-6e9b-11e5-8402-1b490459e334",
  "default_gateway": "10.0.0.1",
  "resolvers": [
    "8.8.8.8",
    "8.8.4.4"
  ],
  "nics": [
    {
      "nic_tag": "stub0",
      "ip": "10.0.0.5",
      "netmask": "255.255.255.0",
      "allow_ip_spoofing": "1",
      "gateway": "10.0.0.1"
    }
  ]
}

Note You’ll probably need to change the alias, hostname, quota (disk-space in GB), max_physical_memory, and networking stuff like gateway and nics to match your environment. I had problems running the zone with 1G memory, better give it at least 2 Gigs.

# Provision and bring up the zone
vcadm create -f zone.json
zlogin <UUID of the new zone>

Now inside the zone

pkgin update # Update pkgsrc
# Compiler and related stuff
# I had a hard time compiling R packages with gcc48/gcc49 so
# I used gcc47 which worked perfectly.
pkgin install gcc47 gcc47-libs gmake autoconf automake cmake
# XML stuff
pkgin install libxml2 libxml libxml++1 libxml++-2
pkgin install R R2pkg
# Setup CRAN Mirror
# TODO may be https instead of http
echo 'options(repos=structure(c(CRAN="http://cran.rstudio.com/")))' > ~/.Rprofile
# Install Rcpp and devtools, this will pull in a lot of goodies with it
Rscript -e "install.packages('Rcpp','devtools')"
# Install Hadleyverse
Rscript -e "install.packages(c('plyr', 'dplyr', 'stringr', 'rvest', 'httr', 'reshape2', 'ggplot2', 'ggmap', 'tidyr', 'lubridate', 'readr', 'testthat', 'roxygen2'))"
# Some other useful R package
Rscript -e "install.packages(c('data.table', 'knitr', 'rmarkdown'))"

After that it’s your usual R stuff. I’m going to convert this zone to a shiny server and will blog about it when done.