📜 ⬆️ ⬇️

R and Information Security. How to eliminate the contradiction of interests and run R on Linux in offline mode

It is a continuation of previous publications .


Very often, attempts to apply DataScience tools in a corporate environment are in complete contradiction with the requirements of the Information Security Service (SIS). In the world of DataScience, the recommendation “put on a githaba” becomes practically unsolvable when the analytical machine is completely isolated from the Internet. Nevertheless, the task of launching the linux infrastructure of the R in an offline environment is quite solvable. Below is a sequence of mantras that allow this to be performed. If some steps are not completely transparent, then I will correct as comments appear. The same steps can be used for online installations, skipping steps related to clever tricks or creating local repositories. Collected bit by bit on the basis of multiple installations for a variety of tasks. Practice has shown that the topic is very relevant.



Initial assumptions and notation



Installing packages in the OS required for the R App to work


Steps are executed on srchost and dsthost . As a srchost can be just a Windows analyst machine, then the steps to deploy srchost can be omitted.


On srchost packages are installed from the Internet, on dsthost - from the local repository. Further srchost will be used to create miniCRAN.


 sudo yum update sudo yum -y install chrony sudo systemctl start chronyd sudo systemctl enable chronyd sudo systemctl status chronyd sudo yum -y install epel-release uname -a sudo yum -y install wget tree sudo yum -y install wget libcurl-devel openssl-devel cyrus-sasl-devel libxml2-devel libpng-devel libjpeg-devel python python-devel proj proj-devel mesa-libGL mesa-libGL-devel mesa-libGLU mesa-libGLU-devel gmp-devel mpfr-devel cairo-devel libXt-devel gtk2-devel v8-devel udunits2 udunits2-devel xorg-x11-server-Xvfb unixODBC* postgresql-devel mariadb-devel mysql-devel gcc-gfortran* texlive*, ufw, dejavu*, psmisc, rrdtool, wireshark, lrzsz sudo yum -y install dejavu-fonts-common dejavu-sans-mono-fonts rrdtool psmisc lrzsz gdal* proj-devel proj-epsg proj-nad protobuf-devel geos-devel devel libXt-devel gtk2-devel v8-devel udunits2 udunits2-devel xorg-x11-server-Xvfb unixODBC * postgresql-devel mariadb-devel mysql-devel gcc-gfortran * texlive *, ufw, dejavu sudo yum update sudo yum -y install chrony sudo systemctl start chronyd sudo systemctl enable chronyd sudo systemctl status chronyd sudo yum -y install epel-release uname -a sudo yum -y install wget tree sudo yum -y install wget libcurl-devel openssl-devel cyrus-sasl-devel libxml2-devel libpng-devel libjpeg-devel python python-devel proj proj-devel mesa-libGL mesa-libGL-devel mesa-libGLU mesa-libGLU-devel gmp-devel mpfr-devel cairo-devel libXt-devel gtk2-devel v8-devel udunits2 udunits2-devel xorg-x11-server-Xvfb unixODBC* postgresql-devel mariadb-devel mysql-devel gcc-gfortran* texlive*, ufw, dejavu*, psmisc, rrdtool, wireshark, lrzsz sudo yum -y install dejavu-fonts-common dejavu-sans-mono-fonts rrdtool psmisc lrzsz gdal* proj-devel proj-epsg proj-nad protobuf-devel geos-devel 

We put everything that concerns LaTeX


Required for RMarkdown


 sudo yum -y install texlive texlive-latex texlive-xetex texlive-collection-fontsrecommended texlive-collection-latex texlive-collection-latexrecommended texlive-xetex-def texlive-collection-xetex 

Install fonts


Add Cyrillic support:


 sudo yum -y install texlive-cyrillic texlive-collection-langcyrillic texlive-cyrillic-doc texlive-framed texlive-titling texlive-*font* linux-liber* 

Installing Roboto Condensed:


 wget http://li.nux.ro/download/nux/dextop/el7/x86_64//google-roboto-common-1.2-2.el7.nux.noarch.rpm wget http://li.nux.ro/download/nux/dextop/el7/x86_64//google-roboto-condensed-fonts-1.2-2.el7.nux.noarch.rpm sudo yum localinstall google-roboto-common-1.2-2.el7.nux.noarch.rpm sudo yum localinstall google-roboto-condensed-fonts-1.2-2.el7.nux.noarch.rpm sudo fc-cache 

R installation


 sudo yum -y install R 

Create a miniCRAN repository on srchost


We use the miniCRAN package to initialize the repository on srchost . We assume that it is running under CentOS and that it is R. We /opt/miniCRAN that the local directory /opt/miniCRAN , where the necessary packages will be downloaded, has already been created.


We put miniCRAN


 sudo -i R install.packages("miniCRAN") #  miniCRAN 

We extort the packages we need (to add what is missing for your project) along with the dependencies


 sudo -i R library("miniCRAN") tags <- c("tidyverse", "lubridate", "glue", "scales", "forcats", "readxl", "magrittr", "stringi", "stringr", "futile.logger", "jsonlite", "Cairo", "RColorBrewer", "extrafont", "hrbrthemes", "DBI", "RPostgreSQL", "config", "shiny", "shinyjqui", "shinythemes", "shinyBS", "shinyjs", "shinyWidgets", "shinycssloaders", "formattable", "anytime", "tictoc", "digest", "officer", "openxlsx", "assertr", "checkmate", "udunits2", "devtools", "DT", "data.table") pkgList <- pkgDep(tags, suggests=TRUE, enhances=FALSE) makeRepo(pkgList, path="/opt/miniCRAN", repos="https://cloud.r-project.org/", type=c("source")) 

manually copy the contents of /opt/miniCRAN


set miniCRAN dir as default CRAN URI


On dsthost in the file /usr/lib64/R/library/base/R/Rprofile add


 local({ uri <- paste0("file://", normalizePath("/opt/miniCRAN", winslash="/")) options(repos = c(CRAN = uri)) }) 

Hands add the library ICU version> 52


On srchost



Connecting to MS SQL from under linux requires an extra. driver installation steps


"Installing Microsoft ODBC Driver for SQL Server for Linux and macOS" :


 sudo su curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo exit sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts sudo ACCEPT_EULA=Y yum install msodbcsql 

update packages in R


on dsthost


 sudo -i R update.packages(ask=FALSE) 

Manually collect the package udunits2


After installing the libraries, look for the location of the h files using the following command find . -type f -name udunits2.h find . -type f -name udunits2.h and run the package installation from the console R with the following parameters:


 install.packages("udunits2", configure.args='--with-udunits2-include=/usr/include/udunits2/') 

Put the packages in R using standard install.packages()


 sudo -i R install.packages(c("tidyverse", "lubridate", "glue", "scales", "forcats", "readxl", "magrittr", "stringi", "stringr", "futile.logger", "jsonlite", "Cairo", "RColorBrewer", "extrafont", "hrbrthemes", "DBI", "RPostgreSQL", "config", "shiny", "shinyjqui", "shinythemes", "shinyBS", "shinyjs", "shinyWidgets", "shinycssloaders", "formattable", "anytime", "tictoc", "digest", "officer", "openxlsx", "assertr", "checkmate", "udunits2", "devtools", "DT", "data.table")) 

Changing environment variables used in scripts



Installing RStudio Products


on dsthost
Create a separate user with uid> 100! on behalf of whom we will log into RStudio Server:


 sudo useradd ruser sudo passwd XXX sudo usermod -aG wheel ruser # to make user 'sudo-user' 

Installing RStudio Server free


on srchost


  1. download RStidio Server from link below Download Page
  2. Copy RPM to remote server dsthost
    on dsthost
  3. install it using rpm -ihv ./rstudio-server ... .rpm

Install RStudio Shiny Server free


on srchost


  1. download Shiny Server from link below download page
  2. Copy RPM to remote server dsthost
  3. install it using rpm -ihv ./shiny-server ... .rpm

We check web access


Shiny server



Application installation


on srchost :


  1. Installing your own packages with Github
    • cd /tmp && git clone https://github.com/path1/pack.git (from bash on local server)
    • copy server to remote folder dsthost
    • R: devtools::install_local(path="/tmp/pack")
  2. Unpacking application scripts from the provided distribution package to the home directory ~/R/ user ruser
  3. We leave the Shiny Server mode of operation for one analyst (ruser), map its home directory R to /srv/shiny-server command ln -s <SOURCE> <LINK_NAME> :
    sudo ln -s /home/ruser/R/<app> /srv/shiny-server/<app>
  4. We give the right to write (written application log)
    chmod -R go+rwx /home/ruser

Can work


Previous publication - "Using R for" industrial "development . "


')

Source: https://habr.com/ru/post/345000/


All Articles