[Mac] install RStudio-Server :: Homebrew

Published onesixx on

iangow.wordpress.com/2013/05/01/rstudio-server-on-mac-os-x/
Matt Furia
support.rstudio.com/hc/en-us/articles/200552316-Configuring-the-Server
www.rstudio.com/products/rstudio/download-server
http://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/
https://www.rstudio.com/products/rstudio/

Prerequisites

Installing R

http://onesixx.com/install-r-mac/

RStudio Server를 설치하기 위해서는 R을 먼저 설치해야한다.

추가 package 설치 

C/C++ Compilers and Libraries

~|⇒ brew install gcc ccache cmake pkg-config autoconf automake

gcc(GNU compiler collection), ccache(Object-file caching compiler wrapper),
cmake(Cross-platform make), pkg-config(Manage compile and link flags for libraries),
autoconf(Automatic configure script builder), automake(Tool for generating GNU Standards-compliant Makefiles)

SSL/SSH Libraries -optional (Openssl)

~|⇒ brew install openssl [email protected]
~|⇒ brew install libressl libssh2

libressl(Version of the SSL/TLS protocol forked form OpenSSL),  libssh2(C library implementing the SSH2 protocol)

git 

http://onesixx.com/homebrew-ex/
~|⇒ brew install git --with-brewed-openssl --with-pcre

version control을 위해 Apple에서도 git을 제공하지만, Homebrew를 통해 관리도 가능

pcre (Perl Compatible Regular Expressions)

PCRE library는 Perl5문법을 사용하여 정규식 패턴 매칭을 구현하는 함수의 집합(없으면 설치)

 Python

Apple에서도 제공하지만, Homebrew를 통해 관리도 가능 (gdbm, sqlite도 함께 설치)

~|⇒ brew install python

 Postgresql

|➜  brew install postgresql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
closure-compiler   gdal               liblwgeom          ndpi               postgis            tracebox
docker             git-annex          libmypaint         newsboat           pulseaudio         ttyd
docker-completion  json-c             libu2f-host        ntopng             rabbitmq           ykpers
emscripten         konoha             libu2f-server      pianobar           [email protected]            zmap
fastd              libfabric          mpw                pianod             riemann-client
==> Deleted Formulae
bokken

==> Downloading https://homebrew.bintray.com/bottles/postgresql-10.3.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-10.3.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/postgresql/10.3/bin/initdb /usr/local/var/postgres
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
==> Summary
🍺  /usr/local/Cellar/postgresql/10.3: 3,383 files, 39.2MB

Qt

github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit
~|⇒ brew search qt5

1) Qt website 에서 qt-opensource-mac-x64-clang-5.5.1.dmg 다운받아 설치 (default 옵션으로)

qt: stable 5.10.1 (bottled), HEAD [keg-only]
Cross-platform application and UI framework
https://www.qt.io/
/usr/local/Cellar/qt/5.10.1 (9,375 files, 295.1MB)
  Poured from bottle on 2018-05-10 at 15:35:04
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/qt.rb
==> Dependencies
Build: pkg-config ✔
Optional: mysql ✘, postgresql ✘
==> Requirements
Build: xcode ✘
Required: macOS >= 10.8 ✔
==> Options
--with-docs
	Build documentation
--with-examples
	Build examples
--with-mysql
	Build with mysql support
--with-postgresql
	Build with postgresql support
--without-proprietary-codecs
	Don't build with proprietary codecs (e.g. mp3)
--HEAD
	Install HEAD version
==> Caveats
We agreed to the Qt opensource license for you.
If this is unacceptable you should uninstall.

This formula is keg-only, which means it was not symlinked into /usr/local,
because Qt 5 has CMake issues when linked.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/qt/lib
    CPPFLAGS: -I/usr/local/opt/qt/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/qt/lib/pkgconfig

Homebrew에서  qt55가 /usr/local/bin에 symlink를 하기 위해

~|⇒ brew link --force qt55

확인

~|⇒ which qmake
/usr/local/opt/[email protected]/bin/qmake

capybara webkit

~|➜  sudo gem install capybara-webkit 
Building native extensions. This could take a while...
Successfully installed capybara-webkit-1.15.0
Parsing documentation for capybara-webkit-1.15.0
Installing ri documentation for capybara-webkit-1.15.0
Done installing documentation for capybara-webkit after 0 seconds
1 gem installed

Ruby

Ruby 설치 (Apple에도 기본적으로 제공하지만…)

~|⇒ brew install ruby

Miscellaneous graphical libraries -optional

~|⇒ brew install freetype fontconfig pixman gettext

Libxml2

~|⇒ brew install libxml2
~|⇒ brew link libxml2 --force

Boost -optional

Boost 는 C나 C++ 프로그램을 한다면 설치할만 하다. (Libxml2를 먼저 설치한 후에~)

~|⇒ brew install icu4c libiconv libxslt
~|⇒ brew install boost --with-icu4c --without-single

Latex

 MacTex ( MacTeX installer ,Latex  )

Rmarkdown문서를 PDF로 내보내기 위해 RStudio는 MacTeX가 필요하다. (가능하면 Full version으로 설치, 약 3GB필요)

~|⇒ brew cask install mactex

java

~|⇒ brew cask install caskroom/versions/java8

apache-ant

http://stackoverflow.com/questions/3222804/how-can-i-install-apache-ant-on-mac-os-x

Apache Ant –  Java library, command-line tool  (Java설치 필요)
Java (뿐만아니라, C 또는 C++) application 을 build하는 tool로 가장 많이 사용되며,
Java Application을 compile, assemble, test , run하는 일을 수행한다.

~|⇒ brew install ant

RStudio server 설치

https://www.r-bloggers.com/rstudio-server-on-os-x-sierra/
github.com/Homebrew/ homebrew-science /blob/master/ rstudio-server.rb
stackoverflow.com/questions/39916715/compilation-error-when-compiling-rstudio-server
web.mit.edu/r/current/RStudio/INSTALL

 homebrew/science was deprecated!!

Add this tap and install rstudio-server

~|⇒ brew tap randy3k/r
~|⇒ brew install rstudio-server
==> Installing rstudio-server from randy3k/r
==> Downloading https://github.com/randy3k/homebrew-r/releases/download/rstudio-server-1.1.442/rstudio-server-1.1.442_3.sierra.bottle.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/60392032/ded43734-2c61-11e8-82a9-b891eb8d2445?X-Amz-Algorithm=AW
######################################################################## 100.0%
==> Pouring rstudio-server-1.1.442_3.sierra.bottle.tar.gz
Warning: randy3k/r/rstudio-server dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
==> Caveats
- To test run RStudio Server,
    /usr/local/opt/rstudio-server/bin/rserver --server-daemonize=0

- To complete the installation of RStudio Server
    1. register RStudio daemon
        If it is an upgrade or the plist file exists, unload the plist first
        sudo launchctl unload -w /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

        sudo cp /usr/local/opt/rstudio-server/extras/launchd/com.rstudio.launchd.rserver.plist /Library/LaunchDaemons/
        sudo launchctl load -w /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

    2. install the PAM configuration
        sudo cp /usr/local/opt/rstudio-server/extras/pam/rstudio /etc/pam.d/

    3. sudo rstudio-server start

- In default, only users with id >1000 are allowed to login. To relax the
  requirement, add the following line to the configuration file located
  at `/etc/rstudio/rserver.conf`

    auth-minimum-user-id=500
==> Summary

To test run RStudio Server

/usr/local/Cellar/rstudio-server/버전/bin/rserver 와 /usr/local/Cellar/rstudio-server/버전/bin/rstudio-server는 
/usr/local/bin에 재Link된다

~|⇒ sudo /usr/local/opt/rstudio-server/bin/rserver --server-daemonize=0

로그 확인 /var/log/system.log 

To complete the installation of RStudio Server

1. register RStudio Server daemon

업그레이드를 했거나 이미 plist가 로딩되어 있다면, Unload 한다. (신규설치시 필요없음)

~|⇒ sudo launchctl unload -w /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

~|⇒ sudo rm /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

1) plist 서비스폴더에 복사 

“com.rstudio.launchd.rserver.plist”파일을 copy하여, own와 mod를 변경후에,  자동으로 서버가 시작되도록 컨텐츠를 추가한다. 

~|⇒ sudo cp /usr/local/opt/rstudio-server/extras/launchd/com.rstudio.launchd.rserver.plist   /Library/LaunchDaemons/

2)  plist 수정

~|⇒ sudo vi /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist 

1) rstudio 서버의 기본값으로 auth-minimum-user-id 는 1000 인데,  일반적으로  OS X user’s first ID 는 501이므로 ( the second user’s ID는 502 …) 아래와 같이 수정한다. replace 8번재줄부터

<key>ProgramArguments</key>
<array>
    <string>/usr/local/opt/rstudio-server/bin/rserver</string>
    <string>--server-daemonize=0</string>
</array>

to 

<key>ProgramArguments</key>
<array>
    <string>/usr/local/opt/rstudio-server/bin/rserver</string>
    <string>--server-daemonize=0</string>
    <string>--auth-minimum-user-id=500</string>

2) 부팅시 RStudio Sever 런칭 설정,  plist 파일 수정 (14번째줄)

<key>RunAtLoad</key>
<false/>

to

<key>RunAtLoad</key>
<true/>

2. install the PAM configuration

~|⇒ sudo cp /usr/local/opt/rstudio-server/extras/pam/rstudio /etc/pam.d/

— 또는 

~|⇒ sudo cp /etc/pam.d/ftpd         /etc/pam.d/rstudio
# login: auth account password session
auth       required       pam_opendirectory.so
account    required       pam_permit.so
password   required       pam_deny.so
session    required       pam_permit.so

3. 서비스 등록 (로딩)

~|⇒ sudo launchctl load -w /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

4. start rstudio-server

~|⇒ sudo rstudio-server start

참고> stop rstudio

~|⇒ sudo rstudio-server stop

5. 실행

localhost:8787

참고>  “Invalid username/password” 에러 발생시 , rstudio PAM 을 설치다시 확인 

추가작업

rstudio group 생성  (System Preferences -> Users & Groups -> Add)

===========================

설치에러관련

~|⇒ sudo /usr/local/opt/rstudio-server/bin/rserver --server-daemonize=0
21 Dec 2016 07:30:08 [rserver] ERROR system error 48(Address already in use); 
OCCURRED AT: rstudio::core::Error rstudio::core::http::initTcpIpAcceptor
(SocketAcceptorService<boost::asio::ip::tcp> &, const std::string &, const std::string &) 
/tmp/rstudio-server-20161017-7559-tvra0w/rstudio-0.99.902/src/cpp/core/include/core/http/TcpIpSocketUtils.hpp:103;
LOGGED FROM: int main(int, char *const *) 
/tmp/rstudio-server-20161017-7559-tvra0w/rstudio-0.99.902/src/cpp/server/ServerMain.cpp:438
 http://stackoverflow.com/questions/31081426/initctl-unknown-instance-error-after-rstudio-conf-change/32851419#32851419

Port 에러

1) 8787 Port 사용중인지 확인

~|⇒ sudo fuser 8787/tcp

fuser명령어는 특정파일을 어떤프로세스에서 사용하고 있는지 확인해야 할 필요성이 있을 때, 지정된 파일이 사용되고 있는 프로세스 ID를 확인하는 명령어로 지정된 파일과 PID를 KILL 또는 재시작 할 수도 있다.

2) kill all process.

~|⇒ sudo fuser -k 8787/tcp

Permissions 에러

~|⇒ sudo chown root:wheel /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist
~|⇒ sudo chmod 644 /Library/LaunchDaemons/com.rstudio.launchd.rserver.plist

 

https://support.rstudio.com/hc/en-us/articles/200713883-Optimizing-your-Browser-for-RStudio-Server

Disable Pop-Up Blockers

There are a number of instances where RStudio needs to show a new external popup window (e.g to display a PDF file). We therefore recommend that you disable pop-up blocking for the RStudio domain. Most browsers will prompt you regarding whether you want to enable popups for RStudio the first time one is blocked. Some browsers (such as Safari) may require you to globally enable and disable popups.

Disable Browser Spell Checking

If you are using a browser with built-in spell-checking, you may find it desirable to disable “Check Spelling While Typing” (available from the Edit menu) since many of the words you enter in the Source and Console will not be in the built-in dictionary and thus will show up with a red underline when entered.

 

 

 

 

Categories: R Basic

onesixx

Blog Owner

1 Comment

Leave a Reply

Your email address will not be published.