Amazon EC2(Ubuntu14.04)からUbuntu16.04にOSをアップグレードしRStudio ServerとJupyterHub環境をインストール

2016.07.14

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

下記エントリではRStudioをAMIから構築した環境にJupyterHub&R実行環境を整えるという内容でしたが、RStudio Serverの方をAMIからでは無く、通常(コマンドによるインストール)の方法で進めた場合にどのような形となるかを試してみたいと思い、実際試してみました。OSは上記同様Ubuntuなのですが、AMIから立ち上げた場合のバージョン(16.04)に相当するバージョンのもの(素のバージョンAMI)が無かったので、Ubuntu14.04から16.04にOSをアップグレードするという手順についても併せて検証・実践してみています。

目次

Ubuntu14.04から16.04へOSアップグレード

ubuntu1404-RStudio-JupyterHub_01

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

こちらのエントリを参考にリポジトリの追加までを行い、

こちらの情報を参考にアップグレード処理を実施しました。

OS再起動後、バージョンを確認して見ます。ちゃんとアップグレードされている事を確認出来ました。

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"

RStudio Serverのインストール

先日投稿した下記エントリでは、RStudioをAMIからの一発構築で行いました(行った後の環境に混在させる形で導入を進めていました)が、今回のエントリではRStudioも各種コマンドで導入する形を取ってみようと思います。

下記エントリの手順を途中まで進めていたので、Rが入るように環境を整えたいと思います。DISTRIB_CODENAME=xenialという風に値が変わっている部分がありますので、

リポジトリの情報を追記。(というか、アップグレード作業の過程で前バージョンの内容もコメントアウトされていますね)

$ sudo vim /etc/apt/sources.list

#DISTRIB_CODENAME=trustyの場合
# deb http://cran.ism.ac.jp/bin/linux/ubuntu trusty/ # disabled on upgrade to xenial

#DISTRIB_CODENAME=xenialの場合
deb http://cran.ism.ac.jp/bin/linux/ubuntu xenial/

以降は各種ドキュメントに従い、必要となるパッケージを導入。

$ sudo apt-get -y update
$ sudo apt-get -y install r-base
$ sudo apt-get -y install gdebi-core
$ wget https://download2.rstudio.org/rstudio-server-0.99.902-amd64.deb
$ sudo gdebi rstudio-server-0.99.902-amd64.deb
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done

RStudio Server
 RStudio is a set of integrated tools designed to help you be more productive with R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, and workspace management.
Do you want to install the software package? [y/N]:y
Selecting previously unselected package rstudio-server.
(Reading database ... 75384 files and directories currently installed.)
Preparing to unpack rstudio-server-0.99.902-amd64.deb ...
Unpacking rstudio-server (0.99.902) ...
Setting up rstudio-server (0.99.902) ...
groupadd: group 'rstudio-server' already exists
rsession: no process found
Created symlink from /etc/systemd/system/multi-user.target.wants/rstudio-server.service to /etc/systemd/system/rstudio-server.service.
● rstudio-server.service - RStudio Server
   Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2016-07-12 11:05:00 UTC; 1s ago
  Process: 12345 ExecStart=/usr/lib/rstudio-server/bin/rserver (code=exited, status=0/SUCCESS)
 Main PID: 12348 (rserver)
    Tasks: 3
   Memory: 876.0K
      CPU: 361ms
   CGroup: /system.slice/rstudio-server.service
           └─12348 /usr/lib/rstudio-server/bin/rserver

Jul 12 11:05:00 ip-10-0-0-35 systemd[1]: Starting RStudio Server...
Jul 12 11:05:00 ip-10-0-0-35 systemd[1]: Started RStudio Server.

ユーザーのパスワードも併せて設定しておきます。

$ sudo passwd ubuntu
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

ブラウザアクセス。そして上記で設定したユーザー名&パスワードでログイン。

ubuntu1404-RStudio-JupyterHub_02

無事アクセス出来ました。

ubuntu1404-RStudio-JupyterHub_03

JupyterHub周りの環境導入

JupyterHub周りの環境導入については、先日投稿した下記エントリの該当部分をなぞる形で進める事が出来ます。以下JupyterHub環境導入までは実行文のコピペでスイスイ。

  • 下準備
  • Python3系環境のインストール(Python 3.5.2の導入)
  • nvm/npm周りの環境整備(nvm:0.31.2, Node.js:6.2.2を導入)
  • JupyterHub環境のインストール

jupyterhubを起動すると以下の様なログ表示となりました。

  • 設定ファイルの作成
  • 認証トークンの作成、設定
  • 管理者ユーザー、ホワイトリストの設定

についても上記エントリを元に対応を実施します。

$ jupyterhub
[I 2016-07-12 11:25:23.295 JupyterHub app:643] Writing cookie_secret to /home/ubuntu/jupyterhub_cookie_secret
[W 2016-07-12 11:25:23.467 JupyterHub app:304] 
    Generating CONFIGPROXY_AUTH_TOKEN. Restarting the Hub will require restarting the proxy.
    Set CONFIGPROXY_AUTH_TOKEN env or JupyterHub.proxy_auth_token config to avoid this message.
    
[W 2016-07-12 11:25:23.478 JupyterHub app:757] No admin users, admin interface will be unavailable.
[W 2016-07-12 11:25:23.478 JupyterHub app:758] Add any administrative users to `c.Authenticator.admin_users` in config.
[I 2016-07-12 11:25:23.478 JupyterHub app:785] Not using whitelist. Any authenticated user will be allowed.
[I 2016-07-12 11:25:23.490 JupyterHub app:1231] Hub API listening on http://127.0.0.1:8081/hub/
[E 2016-07-12 11:25:23.493 JupyterHub app:963] Refusing to run JuptyterHub without SSL. If you are terminating SSL in another layer, pass --no-ssl to tell JupyterHub to allow the proxy to listen on HTTP.

ポート番号(8081)の重複はどうやら無いようです。--no-sslオプションでサーバ起動させてみます。

$ jupyterhub --no-ssl
[I 2016-07-12 11:32:22.852 JupyterHub app:622] Loading cookie_secret from /home/ubuntu/jupyterhub_cookie_secret
[W 2016-07-12 11:32:22.883 JupyterHub app:743] 
    JupyterHub.admin_users is deprecated.
    Use Authenticator.admin_users instead.
[I 2016-07-12 11:32:22.907 JupyterHub app:1231] Hub API listening on http://127.0.0.1:8081/hub/
[W 2016-07-12 11:32:22.911 JupyterHub app:959] Running JupyterHub without SSL. There better be SSL termination happening somewhere else...
[I 2016-07-12 11:32:22.911 JupyterHub app:968] Starting proxy @ http://*:8000/
11:32:23.049 - info: [ConfigProxy] Proxying http://*:8000 to http://127.0.0.1:8081
11:32:23.054 - info: [ConfigProxy] Proxy API at http://127.0.0.1:8001/api/routes
[I 2016-07-12 11:32:23.115 JupyterHub app:1254] JupyterHub is now running at http://127.0.0.1:8000/

所定のサーバにポート8000でアクセス。ログインするユーザーは上記手順で設定したユーザーを用います。

ubuntu1404-RStudio-JupyterHub_06

こちらも無事ログイン出来ました。

ubuntu1404-RStudio-JupyterHub_07

アクセス時に以下エラーメッセージは変わらず出ていましたので、一応先と同じ対応を施しておきました。

$ sudo chown ubuntu.ubuntu /run/motd.dynamic

JupyterHub環境へのR環境の追加についても先述エントリと同様の手順で無事に準備する事が出来ました。

ubuntu1404-RStudio-JupyterHub_08

まとめ

基本的には前述のエントリに準ずる手順となりますが、環境の衝突が無い分、こちらの方が実施手順の頃合いとしては良さそうです。幾つかOSや手法について試してみた感じではありますが、JupyterHubを実行利用するのであればUbuntuが都合良さそうだなというのが個人的な感想です。こちらからは以上です。