Tag Archives: Linux

RStudio Server and Apache

rstudio2To install R and RStudio Server on Ubuntu:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
sudo apt-get update
sudo apt-get install r-base
sudo -i R
wget https://download2.rstudio.org/rstudio-server-1.1.453-amd64.deb
sudo gdebi rstudio-server-1.1.453-amd64.deb

Configure Apache 2.4 to proxy RStudio, install required modules.

sudo apt-get install libapache2-mod-proxy-html
sudo apt-get install libxml2-dev

Edit configuration file 000-default.conf to add the followings. Assuming RStudio runs on default port 8787 and preferred path is /rstudio:

<Proxy *>
	Allow from localhost
< /Proxy *>

RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /rstudio/(.*) ws://localhost:8787/$1  [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /rstudio/(.*) http://localhost:8787/$1 [P,L]
ProxyPass /rstudio/ http://localhost:8787/
ProxyPassReverse /rstudio/ http://localhost:8787/
ProxyRequests Off

Finally restart apache.

sudo a2enmod proxy && sudo a2enmod proxy_http && sudo a2enmod proxy_wstunnel && sudo service apache2 restart

Re-mounting an AWS EBS Volume to another instance

This is handy for a lot of reasons, like rescuing disk data or fixing boot configuration. The detail is here at the Amazon documentation. The outline of steps is below:

  1. Stop the original instance.
  2. Detach the volume from the stopped instance.
  3. Create a new instance of similar type to the original instance and assign the same security group.
  4. Start the new instance.
  5. Attach the detached original volume to the new instance as /dev/xvdf
  6. Login to the new instance, create mount point and mount the original volume.
  7. Once completed, umount the original volume and detach from the new instance.
  8. Attach the original volume to the original instance as /dev/sda1
  9. Start the original instance.

Essential commands for this, based on Ubuntu. Some steps above are done in the AWS Console GUI.

ubuntu:~$ lsblk
 xvda 202:0 0 8G 0 disk
xvda1 202:1 0 8G 0 part /
 xvdf 202:80 0 10G 0 disk
xvdf1 202:81 0 10G 0 part
ubuntu:~$ sudo file -s /dev/xvdf
 /dev/xvdf: x86 boot sector
ubuntu:~$ sudo mkdir /rescue
ubuntu:~$ sudo mount /dev/xvdf1 /rescue