Recent Changes - Search:

Services

Technical Doc. Index

edit SideBar

Shiny Server Load Balancing Setup

Background

Shiny open source edition is single-threaded. To serve multiple users using parallel cores requires running multiple shiny servers. External load balancing is covered in Proxy. This page describes the configuration of multiple shiny servers on one virtual system.

Multiple Shiny-Server setup

Multiple users

For identification purposes, I've setup each shiny server with it's own UID. Also, shiny doesn't need to run as root.

useradd -d /home/shinyB -g 999 -m -u 998 -c Shiny\ Server\ B shinyB
useradd -d /home/shinyC -g 999 -m -u 997 -c Shiny\ Server\ C shinyC
useradd -d /home/shinyD -g 999 -m -u 996 -c Shiny\ Server\ D shinyD
useradd -d /home/shinyE -g 999 -m -u 995 -c Shiny\ Server\ E shinyE
useradd -d /home/shinyF -g 999 -m -u 994 -c Shiny\ Server\ F shinyF
useradd -d /home/shinyG -g 999 -m -u 993 -c Shiny\ Server\ G shinyG
useradd -d /home/shinyH -g 999 -m -u 992 -c Shiny\ Server\ H shinyH
useradd -d /home/shinyI -g 999 -m -u 991 -c Shiny\ Server\ I shinyI
useradd -d /home/shinyJ -g 999 -m -u 990 -c Shiny\ Server\ J shinyJ
useradd -d /home/shinyK -g 999 -m -u 989 -c Shiny\ Server\ K shinyK
useradd -d /home/shinyL -g 999 -m -u 988 -c Shiny\ Server\ L shinyL

The missing 'shinyA' is the default 'shiny' user.

Configuration

Each Shiny server needs its own configuration file:

cd /etc/shiny-server
for srv in B C D E F G H I J K L;do cp shiny-server.conf shiny-server${srv}.conf

; done

#cp shiny-server.conf shiny-serverA.conf
#cp shiny-server.conf shiny-serverC.conf
#ln -s shiny-server.conf shiny-serverB.conf  # helper link

The changes are the run_as username, the listening port, and the log directory, for instance for shinyA:

diff shiny-server.conf shiny-serverA.conf 
2c2
< run_as shiny;
---
> run_as shinyA;
14c14
<   listen 3838;
---
>   listen 3837;
23c23
<     log_dir /var/log/shiny-server;
---
>     log_dir /var/log/shiny-serverA;

Log directories

We have to create the new log directories appropriately:

for srv in B C D E F G H I J K L;do mkdir /var/log/shiny-server${srv}; chown shiny${srv}: /var/log/shiny-server${srv};done

#mkdir /var/log/shiny-server{A,C}
#chown -R shiny: /var/log/shiny-server*
#chown -R shinyA: /var/log/shiny-serverA*
#chown -R shinyC: /var/log/shiny-serverC*

Server ID Tag

To help identify the server in each balance pool, we drop a tag in each shiny user's ~/.Renviron file:

Pretty print host name:
hostname -s | sed 's/^gold\(.\)/Gold \1 /' | awk '{print $1toupper($2)$3}'
GoldThree
echo "R_SHNYSRVINST=GoldThreeA" > ~shinyA/.Renviron

A script to do this, almost:

for user in A B C ;do cat << EOF > /home/shiny$user/.Renviron
R_SHNYSRVINST=`hostname -s | sed 's/$/'$user'/;s/^gold\(.\)/Gold \1 /' | awk '{print $1toupper($2)$3}'`
EOF
  chown shiny$user: /home/shiny$user/.Renviron;
done
chown shiny: /home/shiny/.Renviron

Systemd service setup

Duplicate the systemd service files:

cd /etc/systemd/system
cp shiny-server.service shiny-serverA.service
cp shiny-server.service shiny-serverC.service

The changes are, for instance, for shinyA:

2c2
< Description=ShinyServer
---
> Description=ShinyServerA
6c6
< User=shiny
---
> User=shinyA
8c8
< ExecStart=/usr/bin/env bash -c 'exec /opt/shiny-server/bin/shiny-server >> /var/log/shiny-server.log 2>&1'
---
> ExecStart=/usr/bin/env bash -c 'exec /opt/shiny-server/bin/shiny-server \
/etc/shiny-server/shiny-serverA.conf >> /var/log/shiny-serverA.log 2>&1'

Note: final line-break for clarity.

Runtime

Now we must enable them all to start:

systemctl daemon-reload
systemctl enable shiny-serverA
systemctl enable shiny-serverC
systemctl start shiny-serverA
systemctl start shiny-serverC
Edit - History - Print - Recent Changes - Search
Page last modified on March 27, 2019, at 05:43 PM ADT