一、依赖镜像制作
1.基准环境安装
本次安装通过同源的Centos7系统为环境进行依赖处理,以Docker容器为基准环境:
1 2 3 4 5
| docker pull centos:7
docker run -itd --name centos7 centos:7 docker exec -it centos7
|
2.依赖解决
采用二进制包的方式安装:
https://docs.posit.co/resources/install-r/
本环节用以解决R环境安装的依赖,本次安装采用了RStudio的推荐步骤,本依赖处理同样适用于[源代码安装方式](https://docs.posit.co/resources/install-r-source/)
1 2 3 4 5 6 7 8 9 10
| yum update yum install yum-utils yum install createrepo
yum-builddep R
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm export R_VERSION=4.2.1 curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm sudo yum install R-${R_VERSION}-1-1.x86_64.rpm
|
2.1 R依赖处理
1 2 3 4 5 6 7 8
| mkdir -p /root/R-requires/{R-linux-repo,R-packages}
cd /root/R-requires/R-linux-repo
repotrack bzip2-devel cairo cpp fontconfig freetype fribidi gcc gcc-c++ gcc-gfortran glibc-devel glibc-headers graphite2 harfbuzz hwdata jbigkit-libs kernel-headers libICE libSM libX11 libX11-common libXau libXdamage libXext libXfixes libXft libXmu libXrender libXt libXxf86vm libcurl-devel libdrm libgfortran libglvnd libglvnd-egl libglvnd-glx libgomp libicu libicu-devel libjpeg-turbo libmpc libpciaccess libpng libquadmath libquadmath-devel libstdc++-devel libthai libtiff libwayland-client libwayland-server libxcb libxshmfence make mesa-libEGL mesa-libGL mesa-libgbm mesa-libglapi mpfr openblas openblas-devel openblas-openmp openblas-openmp64 openblas-openmp64_ openblas-serial openblas-serial64 openblas-serial64_ openblas-threads openblas-threads64 openblas-threads64_ pango pcre2 pcre2-devel pcre2-utf16 pcre2-utf32 pixman tcl tk unzip xz-devel zip zlib-devel openssl-devel libxml2-devel
createrepo --database ./
|
2.2 R packages依赖处理
进入R
1 2 3 4 5
| install.packages('miniCRAN') library(miniCRAN) pkgs <- c("openssl","dplyr","stringr","stringi","lubridate","DescTools","reshape2","readxl","tidyverse","this.path","formattable","data.table") pkgList <- pkgDep(pkgs, type = "source", suggests = TRUE, depends = TRUE, includeBasePkgs = TRUE, enhances =TRUE) makeRepo(pkgList, path="/root/R-requires/R-packages", type = c("source"))
|
其中stringi
需要额外下载icu4c-69_1-data-bin-l.zip
进入linux:
1 2
| cd /root/R-requires/R-packages wget https://raw.githubusercontent.com/gagolews/stringi/master/src/icu69/data/icu4c-69_1-data-bin-l.zip
|
3.编写一键安装脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
echo "【Created by fyfq】" echo "本脚本仅在RHEL7.9环境下安装R环境使用" echo "你的发行版为:" cat /etc/os-release | grep PRETTY_NAME
read -r -p "是否开始安装? [Y/n] " input R_VERSION=4.2.1 case $input in [yY][eE][sS]|[yY]) echo "Yes" ;; [nN][oO]|[nN]) echo "No" exit 1 ;; *) echo "Invalid input..." exit 1 ;; esac
echo "开始安装" echo "1.新建本地yum源" cur_dir=$(pwd) if [ ${cur_dir} != "/root/R-requires" ] then mkdir -p /root/R-requires && cp -rf ./* /root/R-requires else echo "ok" fi
`echo "[R-offline-repo] name=R-offine-repo baseurl=file:///root/R-requires/R-linux-repo enabled=1 gpgcheck=0" > /etc/yum.repos.d/R-offline-repo.repo` echo "2.开始安装依赖" yum makecache yum install -y bzip2-devel cairo cpp fontconfig freetype fribidi gcc gcc-c++ gcc-gfortran glibc-devel glibc-headers graphite2 harfbuzz hwdata jbigkit-libs kernel-headers libICE libSM libX11 libX11-common libXau libXdamage libXext libXfixes libXft libXmu libXrender libXt libXxf86vm libcurl-devel libdrm libgfortran libglvnd libglvnd-egl libglvnd-glx libgomp libicu libicu-devel libjpeg-turbo libmpc libpciaccess libpng libquadmath libquadmath-devel libstdc++-devel libthai libtiff libwayland-client libwayland-server libxcb libxshmfence make mesa-libEGL mesa-libGL mesa-libgbm mesa-libglapi mpfr openblas openblas-devel openblas-openmp openblas-openmp64 openblas-openmp64_ openblas-serial openblas-serial64 openblas-serial64_ openblas-threads openblas-threads64 openblas-threads64_ pango pcre2 pcre2-devel pcre2-utf16 pcre2-utf32 pixman tcl tk unzip xz-devel zip zlib-devel openssl-devel libxml2-devel echo "3.依赖安装完毕" echo "4.开始安装R-4.2.1" yum install -y R-4.2.1 echo "5.检查安装结果" if [ -f "/usr/local/bin/R" ] then rm -rf /usr/local/bin/R fi
if [ -f "/usr/local/bin/Rscript" ] then rm -rf /usr/local/bin/Rscript fi ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript R --version || error_exit "安装失败" echo "6.R安装成功!!!" echo "7.开始安装R-Packages,这会持续一段时间,请勿中断操作!!!" sleep 5 Rscript -e 'install.packages("stringi", configure.vars="ICUDT_DIR=/root/R-requires/R-packages", repos="file:/root/R-requires/R-packages", type="source")' Rscript -e 'install.packages(c("openssl", "gargle", "ids", "httr", "googledrive", "googlesheets4", "rvest"), repos="file:/root/R-requires/R-packages", type="source")' Rscript -e 'install.packages(c("dplyr","stringr","lubridate","DescTools","reshape2","readxl","tidyverse","this.path","formattable","data.table"), repos="file:/root/R-requires/R-packages", type="source")' echo "8.开始检查R-Packages安装情况" Rscript -e 'library(dplyr)' Rscript -e 'library(stringr)' Rscript -e 'library(stringi)' Rscript -e 'library(lubridate)' Rscript -e 'library(DescTools)' Rscript -e 'library(reshape2)' Rscript -e 'library(readxl)' Rscript -e 'library(tidyverse)' Rscript -e 'library(this.path)' Rscript -e 'library(formattable)' Rscript -e 'library(data.table)' echo "9.安装完成!!!!" sleep 5
|
重点关注:
1
| Rscript -e 'install.packages("stringi", configure.vars="ICUDT_DIR=/root/R-requires/R-packages", repos="file:/root/R-requires/R-packages", type="source")'
|
99.其它杂项
获取RHEL7.9容器镜像,在注册REDHAT账号时务必选择非中国区。
https://catalog.redhat.com/software/containers/rhel7/rhel/57ea8cdc9c624c035f96f344?container-tabs=gti>i-tabs=red-hat-login
容器中文乱码解决
https://cloud.tencent.com/developer/article/1435512
1 2 3 4 5 6 7
| yum install bzip2-devel cairo cpp fontconfig freetype fribidi gcc gcc-c++ gcc-gfortran glibc-devel glibc-headers graphite2 harfbuzz hwdata jbigkit-libs kernel-headers libICE libSM libX11 libX11-common libXau libXdamage libXext libXfixes libXft libXmu libXrender libXt libXxf86vm libcurl-devel libdrm libgfortran libglvnd libglvnd-egl libglvnd-glx libgomp libicu libicu-devel libjpeg-turbo libmpc libpciaccess libpng libquadmath libquadmath-devel libstdc++-devel libthai libtiff libwayland-client libwayland-server libxcb libxshmfence make mesa-libEGL mesa-libGL mesa-libgbm mesa-libglapi mpfr openblas openblas-devel openblas-openmp openblas-openmp64 openblas-openmp64_ openblas-serial openblas-serial64 openblas-serial64_ openblas-threads openblas-threads64 openblas-threads64_ pango pcre2 pcre2-devel pcre2-utf16 pcre2-utf32 pixman tcl tk unzip xz-devel zip zlib-devel openssl-devel libxml2-devel
dplyr","stringr","stringi","lubridate","DescTools","reshape2","readxl","tidyverse","this.path","formattable","data.table") install.packages(pkgs, repos="file:/root/R-requires/R-packages", type="source") ```bash Rscript -e 'install.packages("drat", repos="https://cloud.r-project.org")'
|
卸载原有的R可以使用make uninstall