2017년 6월 30일 금요일

ppc64le Ubuntu에서 CRAN의 R 서버 및 package 설치, 그리고 rstudio 설치

CRAN (Comprehensive R Archive Network, https://cran.r-project.org )은 R 관련된 소스와 패키지, 문서 등을 모아 놓은 site입니다.  지난 번에는 MS-R의 source를 받아서 ppc64le에서 build한 바 있습니다만, 이번에는 이 CRAN site에서 받은 source로 역시 ppc64le에서 build 해보겠습니다.   NVLink P100이 장착된 IBM Minsky에서는 이 R 및 rstudio를 함께 사용하는 경우가 많습니다.

먼저 Ubuntu OS에서 필요 package들을 설치합니다.

u0017496@sys-87925:~/R-3.4.0$ sudo apt-get install libreadline-dev readline-common libx11-dev libxt-dev libbz2-dev liblzma-dev libpcre2-dev libpcre3-dev  libcurl4-gnutls-dev gfortran-5-powerpc-linux-gnu texlive-latex-base texinfo texlive-fonts-extra openjdk-8-jdk openjdk-8-jdk-headless

이어서 CRAN site에서 가장 최신의 안정적인 버전을 download 받습니다.

u0017496@sys-87925:~$ wget https://cran.r-project.org/src/base/R-3/R-3.4.0.tar.gz
--2017-06-29 22:28:51--  https://cran.r-project.org/src/base/R-3/R-3.4.0.tar.gz
Resolving cran.r-project.org (cran.r-project.org)... 137.208.57.37
Connecting to cran.r-project.org (cran.r-project.org)|137.208.57.37|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 30175855 (29M) [application/x-gzip]
Saving to: ‘R-3.4.0.tar.gz’

R-3.4.0.tar.gz                   100%[=======================================================>]  28.78M  1.05MB/s    in 20s

2017-06-29 22:29:13 (1.43 MB/s) - ‘R-3.4.0.tar.gz’ saved [30175855/30175855]

u0017496@sys-87925:~$ tar -zxvf R-3.4.0.tar.gz

u0017496@sys-87925:~$ cd R-3.4.0

이제 configure를 돌립니다.  아무 option 없이 그냥 해도 됩니다만, 나중에 r-studio를 쓰고자 한다면 여기서 '--enable-R-shlib' option을 꼭 붙여야 합니다.

u0017496@sys-87925:~/R-3.4.0$ ./configure --enable-R-shlib
...
R is now configured for powerpc64le-unknown-linux-gnu

  Source directory:          .
  Installation directory:    /usr/local

  C compiler:                gcc  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  Default C++ compiler:      g++   -g -O2
  C++98 compiler:            g++ -std=gnu++98 -g -O2
  C++11 compiler:            g++ -std=gnu++11 -g -O2
  C++14 compiler:            g++  -g -O2
  C++17 compiler:
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:

  Interfaces supported:      X11
  External libraries:        readline, curl
  Additional capabilities:   NLS
  Options enabled:           shared BLAS, R profiling

  Capabilities skipped:      PNG, JPEG, TIFF, cairo, ICU
  Options not enabled:       memory profiling

  Recommended packages:      yes

이제 make를 수행합니다.   CPU가 느리다면 시간이 꽤 오래 걸립니다.

u0017496@sys-87925:~/R-3.4.0$ make
...
building/updating vignettes for package 'grid' ...
building/updating vignettes for package 'parallel' ...
building/updating vignettes for package 'utils' ...
make[1]: Leaving directory '/home/u0017496/R-3.4.0/src/library'
make[1]: Entering directory '/home/u0017496/R-3.4.0'
configuring Java ...
Java interpreter : /usr/bin/java
Java version     : 1.8.0_131
Java home path   : /usr/lib/jvm/java-8-openjdk-ppc64el/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

trying to compile and link a JNI program
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/ppc64le/server -ljvm
make[2]: Entering directory '/tmp/Rjavareconf.1ALuwL'
gcc -I/home/u0017496/R-3.4.0/include -DNDEBUG -I/usr/lib/jvm/java-8-openjdk-ppc64el/jre/../include -I/usr/lib/jvm/java-8-openjdk-ppc64el/jre/../include/linux  -I/usr/local/include   -fPIC  -g -O2  -c conftest.c -o conftest.o
gcc -shared -L/home/u0017496/R-3.4.0/lib -L/usr/local/lib -o conftest.so conftest.o -L/usr/lib/jvm/java-8-openjdk-ppc64el/jre/lib/ppc64le/server -ljvm -L/home/u0017496/R-3.4.0/lib -lR
make[2]: Leaving directory '/tmp/Rjavareconf.1ALuwL'


JAVA_HOME        : /usr/lib/jvm/java-8-openjdk-ppc64el/jre
Java library path: $(JAVA_HOME)/lib/ppc64le/server
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/ppc64le/server -ljvm
Updating Java configuration in /home/u0017496/R-3.4.0
Done.

make[1]: Leaving directory '/home/u0017496/R-3.4.0'

make install 하면 기본값인 /usr/local/lib/R 밑으로 설치됩니다.

u0017496@sys-87925:~/R-3.4.0$ sudo make install
...
make[3]: Leaving directory '/home/u0017496/R-3.4.0/src/modules/internet'
make[3]: Entering directory '/home/u0017496/R-3.4.0/src/modules/lapack'
/usr/local/lib/R/lib/libRlapack.so is unchanged
make[3]: Leaving directory '/home/u0017496/R-3.4.0/src/modules/lapack'
make[3]: Entering directory '/home/u0017496/R-3.4.0/src/modules/X11'
/usr/local/lib/R/modules/R_de.so is unchanged
make[3]: Leaving directory '/home/u0017496/R-3.4.0/src/modules/X11'
make[2]: Leaving directory '/home/u0017496/R-3.4.0/src/modules'
make[2]: Entering directory '/home/u0017496/R-3.4.0/src/library'
installing packages ...
  building HTML index ...
make[2]: Leaving directory '/home/u0017496/R-3.4.0/src/library'
make[1]: Leaving directory '/home/u0017496/R-3.4.0/src'
make[1]: Entering directory '/home/u0017496/R-3.4.0/tests'
make[1]: Nothing to be done for 'install'.
make[1]: Leaving directory '/home/u0017496/R-3.4.0/tests'

아래와 같이 별도로 PATH 지정을 해주지 않아도 /usr/local/bin/R을 쓸 수 있는데, 이는 /usr/local/lib/R/bin/R과 동일한 copy를 저기에도 설치하기 때문입니다.

u0017496@sys-87925:~/R-3.4.0$ which R
/usr/local/bin/R

u0017496@sys-87925:~/rstudio/build$ ls -ll /usr/local/lib/R/bin/R
-rwxr-xr-x 1 root root 8770 Jun 30 04:04 /usr/local/lib/R/bin/R
u0017496@sys-87925:~/rstudio/build$ ls -l /usr/local/bin/R
-rwxr-xr-x 1 root root 8770 Jun 30 04:04 /usr/local/bin/R

이제 R을 구동해 봅니다.  버전 3.4.0임을 보실 수 있습니다.

u0017496@sys-87925:~/R-3.4.0$ R

R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: powerpc64le-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

CRAN site로터  knitr package를 설치해 봅니다.

> install.packages("knitr")
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors

 1: 0-Cloud [https]                 2: Algeria [https]
 3: Australia (Canberra) [https]    4: Australia (Melbourne) [https]
 5: Australia (Perth) [https]       6: Austria [https]
 7: Belgium (Ghent) [https]         8: Brazil (RJ) [https]
 9: Brazil (SP 1) [https]          10: Bulgaria [https]
11: Chile 1 [https]                12: China (Lanzhou) [https]
13: Colombia (Cali) [https]        14: Czech Republic [https]
15: Denmark [https]                16: Estonia [https]
17: France (Lyon 1) [https]        18: France (Lyon 2) [https]
19: France (Marseille) [https]     20: France (Montpellier) [https]
21: France (Paris 2) [https]       22: Germany (Göttingen) [https]
23: Germany (Münster) [https]      24: Greece [https]
25: Iceland [https]                26: Indonesia (Jakarta) [https]
27: Ireland [https]                28: Italy (Padua) [https]
29: Japan (Tokyo) [https]          30: Malaysia [https]
31: Mexico (Mexico City) [https]   32: Norway [https]
33: Philippines [https]            34: Russia (Moscow) [https]
35: Serbia [https]                 36: Spain (A Coruña) [https]
37: Spain (Madrid) [https]         38: Sweden [https]
39: Switzerland [https]            40: Turkey (Denizli) [https]
41: Turkey (Mersin) [https]        42: UK (Bristol) [https]
43: UK (Cambridge) [https]         44: UK (London 1) [https]
45: USA (CA 1) [https]             46: USA (IA) [https]
47: USA (KS) [https]               48: USA (MI 1) [https]
49: USA (OR) [https]               50: USA (TN) [https]
51: USA (TX 1) [https]             52: Vietnam [https]
53: (other mirrors)
...
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (knitr)

The downloaded source packages are in
        ‘/tmp/RtmpFb3FLc/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done


잘 되는 것을 보실 수 있습니다.   하나 더 해보지요.  anim.plots을 설치해 보겠습니다.

> install.packages("anim.plots")
also installing the dependency ‘animation’

trying URL 'https://cran.revolutionanalytics.com/src/contrib/animation_2.5.tar.gz'
Content type 'application/octet-stream' length 299340 bytes (292 KB)
==================================================
downloaded 292 KB

trying URL 'https://cran.revolutionanalytics.com/src/contrib/anim.plots_0.2.tar.gz'
Content type 'application/octet-stream' length 610350 bytes (596 KB)
==================================================
downloaded 596 KB

* installing *source* package ‘animation’ ...
** package ‘animation’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (animation)
* installing *source* package ‘anim.plots’ ...
** package ‘anim.plots’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (anim.plots)

The downloaded source packages are in
        ‘/tmp/RtmpFb3FLc/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

역시 잘 됩니다.  이제 r-studio를 설치해 보겠습니다.   먼저 github에서 source를 받습니다.

u0017496@sys-87925:~$ git clone https://github.com/rstudio/rstudio.git

먼저 dependencies 관련 항목을 설치합니다.  아래와 같이 install-dependencies-debian 명령을 수행하면 됩니다.

u0017496@sys-87925:~$ cd rstudio/dependencies/linux

u0017496@sys-87925:~/rstudio/dependencies/linux$ ls
install-boost  install-dependencies-debian  install-dependencies-yum  install-dependencies-zypper  install-qt-sdk  README

u0017496@sys-87925:~/rstudio/dependencies/linux$ ./install-dependencies-debian
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libxlmass-devel.8.1.5 libxlsmp libxlsmp-devel.4.1.5 xlc-license-community.13.1.5 xlf-license-community.15.1.5
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  dpkg-dev fakeroot libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libfakeroot
  libfile-fcntllock-perl
Suggested packages:
...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
--2017-06-30 02:40:01--  https://s3.amazonaws.com/rstudio-buildtools/QtSDK-5.4.2-x86_64.tar.gz
Resolving s3.amazonaws.com (s3.amazonaws.com)... 54.231.81.19
Connecting to s3.amazonaws.com (s3.amazonaws.com)|54.231.81.19|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 65843419 (63M) [application/x-tar]
Saving to: ‘/tmp/QtSDK-5.4.2-x86_64.tar.gz’

/tmp/QtSDK-5.4.2-x86_64.tar.gz   100%[========================================================>]  62.79M  7.90MB/s    in 8.0s

2017-06-30 02:40:10 (7.82 MB/s) - ‘/tmp/QtSDK-5.4.2-x86_64.tar.gz’ saved [65843419/65843419]

이어서 common 항목을 설치합니다.

u0017496@sys-87925:~/rstudio/dependencies/linux$ cd ../common

u0017496@sys-87925:~/rstudio/dependencies/common$ ./install-common
gin-1.5.zip already installed
gwt-2.7.0.zip already installed
junit-4.9b3.jar already installed
selenium-java-2.37.0.zip already installed
selenium-server-standalone-2.37.0.jar already installed
ChromeDriver binaries already installed
Dictionaries already installed
Mathjax already installed
1.63.0 already installed in /opt/rstudio-tools/boost/boost_1_63_0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12.0M  100 12.0M    0     0  7067k      0  0:00:01  0:00:01 --:--:-- 7070k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.6M  100 10.6M    0     0  4887k      0  0:00:02  0:00:02 --:--:-- 4888k
libclang 3.5 already installed
libclang headers already installed
Already up-to-date.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
* checking for file ‘rsconnect/DESCRIPTION’ ... OK
* preparing ‘rsconnect’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
Removed empty directory ‘rsconnect/examples’
* building ‘rsconnect_0.8.3.tar.gz’

이제 비로소 cmake를 돌릴 준비가 되었습니다.  TYPE는 Release로, TARGET은 Server로 해서 rstudio를 build 합니다.

u0017496@sys-87925:~/rstudio/dependencies/common$ cd ../..

u0017496@sys-87925:~/rstudio$ mkdir build
u0017496@sys-87925:~/rstudio$ cd build

u0017496@sys-87925:~/rstudio/build$ cmake .. -DRSTUDIO_TARGET=Server -DCMAKE_BUILD_TYPE=Release
...
-- Looking for setresuid
-- Looking for setresuid - found
-- Performing Test PAM_MESSAGE_CONST
-- Performing Test PAM_MESSAGE_CONST - Success
-- Found PAM: /usr/lib/powerpc64le-linux-gnu/libpam.so;/usr/lib/powerpc64le-linux-gnu/libdl.so
-- Found LibR: /usr/local/lib/R
-- Found R: /usr/local/lib/R
-- Performing Test LIBR_MINIMUM_VERSION
-- Performing Test LIBR_MINIMUM_VERSION - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/u0017496/rstudio/build

이제 make를 수행합니다.  매우 오래 걸립니다.

u0017496@sys-87925:~/rstudio/build$ make
Scanning dependencies of target gwt_build
Buildfile: /home/u0017496/rstudio/src/gwt/build.xml

ext:
   [jscomp] Compiling 54 file(s) with 41 extern(s)

javac:
    [mkdir] Created dir: /home/u0017496/rstudio/src/gwt/bin
    [javac] Compiling 10 source files to /home/u0017496/rstudio/src/gwt/bin
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Compiling 2067 source files to /home/u0017496/rstudio/src/gwt/bin
...
[ 99%] Building CXX object src/cpp/server/CMakeFiles/rserver.dir/ServerAddins.cpp.o
[ 99%] Linking CXX executable rserver
[ 99%] Built target rserver
Scanning dependencies of target rserver-pam
[ 99%] Building CXX object src/cpp/server/pam/CMakeFiles/rserver-pam.dir/PamMain.cpp.o
[100%] Linking CXX executable rserver-pam
[100%] Built target rserver-pam

이제 make install로 설치합니다.  기본인 /usr/local/lib/rstudio-server으로 들어갑니다.

u0017496@sys-87925:~/rstudio/build$ sudo make install
Buildfile: /home/u0017496/rstudio/src/gwt/build.xml

ext:
   [jscomp] None of the files changed. Compilation skipped.

javac:
    [javac] Compiling 1 source file to /home/u0017496/rstudio/src/gwt/bin

gwtc:
     [java] Jun 30, 2017 4:55:11 AM java.util.prefs.FileSystemPreferences$1 run
     [java] INFO: Created user preferences directory.
     [java] Compiling module org.rstudio.studio.RStudio
...
-- Installing: /usr/local/lib/rstudio-server/bin/rserver
-- Installing: /usr/local/lib/rstudio-server/bin/rstudio-server
-- Installing: /usr/local/lib/rstudio-server/extras/init.d/debian/rstudio-server
-- Installing: /usr/local/lib/rstudio-server/extras/init.d/redhat/rstudio-server
-- Installing: /usr/local/lib/rstudio-server/extras/init.d/suse/rstudio-server
-- Installing: /usr/local/lib/rstudio-server/extras/pam/rstudio
-- Installing: /usr/local/lib/rstudio-server/extras/apparmor/rstudio-server
-- Installing: /usr/local/lib/rstudio-server/extras/apparmor/apparmor-profile-load
-- Installing: /usr/local/lib/rstudio-server/extras/upstart/rstudio-server.conf
-- Installing: /usr/local/lib/rstudio-server/extras/upstart/rstudio-server.redhat.conf
-- Installing: /usr/local/lib/rstudio-server/extras/systemd/rstudio-server.service
-- Installing: /usr/local/lib/rstudio-server/extras/systemd/rstudio-server.redhat.service
-- Installing: /usr/local/lib/rstudio-server/bin/rserver-pam

이제 rstudio-server를 아래아 같이 서비스로 등록해줍니다.

u0017496@sys-87925:~/rstudio/build$ sudo cp /usr/local/lib/rstudio-server/extras/init.d/debian/rstudio-server /etc/init.d/rstudio-server

u0017496@sys-87925:~/rstudio/build$ sudo update-rc.d rstudio-server defaults

u0017496@sys-87925:~/rstudio/build$ sudo ln -f -s /usr/local/lib/rstudio-server/bin/rstudio-server /usr/sbin/rstudio-server

이제 systemctl로 rstudio-server 서비스를 구동하고, status를 확인합니다.

u0017496@sys-87925:~/rstudio/build$ sudo systemctl start rstudio-server.service

u0017496@sys-87925:~/rstudio/build$ sudo systemctl status rstudio-server.service
● rstudio-server.service - LSB: RStudio Server
   Loaded: loaded (/etc/init.d/rstudio-server; bad; vendor preset: enabled)
   Active: active (running) since Fri 2017-06-30 05:09:49 EDT; 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 11585 ExecStart=/etc/init.d/rstudio-server start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/rstudio-server.service
           └─11593 /usr/local/lib/rstudio-server/bin/rserver

Jun 30 05:09:49 sys-87925 systemd[1]: Starting LSB: RStudio Server...
Jun 30 05:09:49 sys-87925 systemd[1]: Started LSB: RStudio Server.

이제 http://서버주소:8787 로 web browser를 통해 접근할 수 있습니다.   user id와 passwd는 OS user의 것을 그대로 쓰면 됩니다.



역시 plot(mtcars)를 수행해 봅니다.  아래 그림의 왼쪽 command 창을 보시면 plot 명령에서 한번 error가 난 것을 볼 수 있는데, 이는 우측의 plot 창이 너무 좁게 되어 있어서 그렇습니다.  그 창을 마우스로 넓게 키워주면 잘 되는 것을 보실 수 있습니다.



댓글 1개:

  1. Github의 rstudio 설치 가이드에 나와있습니다만, (https://github.com/rstudio/rstudio/blob/master/INSTALL)

    Redhat 에서 Rstudio를 설치하는 경우, update-rc.d 가 아니라 /sbin/chkconfig 명령어를 수행해주면 됩니다.
    * Debian: sudo update-rc.d rstudio-server defaults
    * Redhat/SUSE: sudo /sbin/chkconfig --add rstudio-server

    답글삭제