這篇是一個把 R Studio Server 裝在 LXD 底下的 CentOS8 Container 的紀錄。
安裝:
1. 先裝 EPEL-Release Repo:裡面有官方維護的 R 套件。不過要安裝 R,在 CentOS 8 要啟用 PowerTools Repo 才行。
在 CentOS 8 的 R,背後的 BLAS 函式庫已經使用 OpenBLAS 了~相信速度會比 CentOS 7 的改善許多。
此外,雖然 RHEL/CentOS 8 已經跟 Fedora 一樣使用 dnf 作套件管理,不過 yum 指令仍然向下相容~
lab@lxdlab:~$ lxc launch images:centos/8/amd64 rstudio Creating rstudio Retrieving image: rootfs: 12% (1.30MB/s) Starting rstudio lab@lxdlab:~$ lab@lxdlab:~$ lxc exec rstudio -- yum install -y epel-release CentOS-8 - AppStream 3.8 MB/s | 6.5 MB 00:01 CentOS-8 - Base 2.2 MB/s | 5.0 MB 00:02 CentOS-8 - Extras 13 kB/s | 4.2 kB 00:00 Dependencies resolved. ================================================================================================ Package Architecture Version Repository Size ================================================================================================ Installing: epel-release noarch 8-8.el8 extras 23 k Transaction Summary ================================================================================================ Install 1 Package Total download size: 23 k Installed size: 32 k Downloading Packages: epel-release-8-8.el8.noarch.rpm 910 kB/s | 23 kB 00:00 ------------------------------------------------------------------------------------------------ Total 54 kB/s | 23 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : epel-release-8-8.el8.noarch 1/1 Running scriptlet: epel-release-8-8.el8.noarch 1/1 Verifying : epel-release-8-8.el8.noarch 1/1 Installed: epel-release-8-8.el8.noarch Complete! lab@lxdlab:~$ lab@lxdlab:~$ lxc exec rstudio -- sed -e 's/enabled=0/enabled=1/g' -i /etc/yum.repos.d/CentOS-PowerTools.repo lab@lxdlab:~$ lab@lxdlab:~$ lxc exec rstudio -- yum repolist CentOS-8 - AppStream 5.2 kB/s | 4.3 kB 00:00 CentOS-8 - Base 6.5 kB/s | 3.8 kB 00:00 CentOS-8 - Extras 2.6 kB/s | 1.5 kB 00:00 CentOS-8 - PowerTools 2.9 MB/s | 2.0 MB 00:00 Extra Packages for Enterprise Linux Modular 8 - x86_64 6.6 kB/s | 8.7 kB 00:01 Extra Packages for Enterprise Linux 8 - x86_64 29 kB/s | 6.9 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 3.0 MB/s | 6.1 MB 00:02 repo id repo name status AppStream CentOS-8 - AppStream 5107 BaseOS CentOS-8 - Base 2110 PowerTools CentOS-8 - PowerTools 1523 *epel Extra Packages for Enterprise Linux 8 - x86_64 5074 epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64 0 extras CentOS-8 - Extras 9 lab@lxdlab:~$ lab@lxdlab:~$ lxc exec rstudio -- yum install -y R . . . 過程略 lab@lxdlab:~$
2. 接著安裝 RStudio-Server(到這裡找安裝檔)
lab@lxdlab:~$ lxc exec rstudio -- yum install -y https://download2.rstudio.org/server/fedora28/x86_64/rstudio-server-rhel-1.2.5033-x86_64.rpm Last metadata expiration check: 0:01:33 ago on Wed Mar 25 02:20:17 2020. rstudio-server-rhel-1.2.5033-x86_64.rpm 10 MB/s | 45 MB 00:04 Dependencies resolved. ================================================================================================ Package Architecture Version Repository Size ================================================================================================ Installing: rstudio-server x86_64 1.2.5033-1 @commandline 45 M Installing dependencies: psmisc x86_64 23.1-3.el8 BaseOS 151 k Transaction Summary ================================================================================================ Install 2 Packages Total size: 45 M Total download size: 151 k Installed size: 345 M Downloading Packages: psmisc-23.1-3.el8.x86_64.rpm 775 kB/s | 151 kB 00:00 ------------------------------------------------------------------------------------------------ Total 205 kB/s | 151 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : psmisc-23.1-3.el8.x86_64 1/2 Running scriptlet: rstudio-server-1.2.5033-1.x86_64 2/2 Installing : rstudio-server-1.2.5033-1.x86_64 2/2 Running scriptlet: rstudio-server-1.2.5033-1.x86_64 2/2 groupadd: group 'rstudio-server' already exists Created symlink /etc/systemd/system/multi-user.target.wants/rstudio-server.service → /etc/systemd/system/rstudio-server.service. ● rstudio-server.service - RStudio Server Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: disabled) Active: activating (start) since Wed 2020-03-25 02:22:09 UTC; 21ms ago Main PID: 213 (code=exited, status=1/FAILURE); Control PID: 216 (rserver) Tasks: 1 (limit: 26213) Memory: 552.0K CGroup: /system.slice/rstudio-server.service └─216 /usr/lib/rstudio-server/bin/rserver Mar 25 02:22:09 rstudio systemd[1]: Starting RStudio Server... Verifying : psmisc-23.1-3.el8.x86_64 1/2 Verifying : rstudio-server-1.2.5033-1.x86_64 2/2 Installed: rstudio-server-1.2.5033-1.x86_64 psmisc-23.1-3.el8.x86_64 Complete! lab@lxdlab:~$
這樣就裝完了。
以下切進去 container 裡面進行。
3. 驗證安裝
lab@lxdlab:~$ lxc shell rstudio [root@rstudio ~]# rstudio-server verify-installation 25 Mar 2020 10:29:40 [rsession-rstudio-server] WARNING Unable to determine LANG (proceeding with no LANG set; LOGGED FROM: void rstudio::core::r_util::ensureLang() /var/lib/jenkins/workspace/IDE/open-source-pipeline/v1.2-patch/src/cpp/core/r_util/REnvironmentPosix.cpp:856 [root@rstudio ~]#
指令執行後沒有特殊的抱怨就是可以了。上面的抱怨只是 LXC Container 裡面的 locale 設定都是 C,也就是沒設定,無傷大雅~
這時 R Studio Server 會以自己的帳號執行
[root@rstudio ~]# tail -1 /etc/passwd rstudio-server:x:998:995::/home/rstudio-server:/bin/bash [root@rstudio ~]# [root@rstudio ~]# tail -1 /etc/group rstudio-server:x:995: [root@rstudio ~]#
4. R Studio Server 的 Port 預設是 8787,要變更的話,可以增加到 R Studio Server 的設定檔。我這邊不做更改,僅紀錄變更方式
[root@rstudio ~]# echo "www-port=80" >> /etc/rstudio/rserver.conf
因為這邊在 LXD 環境運作,因此要將服務轉發出來
lab@lxdlab:~$ lxc config device add rstudio rstudio-ui proxy listen=tcp:0.0.0.0:8787 connect=tcp:localhost:8787 Device rstudio-ui added to rstudio lab@lxdlab:~$
5. 接著建立一個「新」帳號,用來提供登入 RStudio-Server
R Studio Server 預設將使用帳號跟 OS 帳號透過 PAM 認證連動,因此需要建立帳戶,掛到 rstudio-server 這個 User Group 下。如果需要 LDAP 的帳號連動認證功能,需要裝企業版。
[root@rstudio ~]# useradd ruser --shell /sbin/nologin -g rstudio-server
[root@rstudio ~]# passwd ruser
* CentOS7 之後沒有 --disabled-login 選項,於是直接把 shell 指向 nologin既有 OS 帳號 <username> 使用
[root@rstudio ~]# usermod -a -G rstudio
6. 最後,啟用服務
不過在安裝完畢時,就已經啟動了~
[root@rstudio ~]# service rstudio-server start
Redirecting to /bin/systemctl start rstudio-server.service
[root@rstudio ~]#
這邊一樣,雖然從 RHEL/CentOS 7 之後就使用討厭的 SystemD,但舊的 SysV 的 service 指令仍然相容~7. 用瀏覽器開到 http://<server-ip>:8787 網頁就好了:這邊轉發出來,因此服務會在 LXD Host 上看到
Note:RStudio-Server 需要 /tmp 能任意讀寫(權限 777),以及家目錄權限是帳號自己的
8. 要安裝 R 教學 swirl 套件:需要安裝 libcurl-devel 與 openssl-devel 的 Linux 套件,才有辦法裝(會編譯 RCurl 跟 httr)
[root@rstudio ~]# yum install -y libcurl-devel openssl-devel
參考:
沒有留言:
張貼留言