当前位置: 代码迷 >> 综合 >> CentOS7 配置R语言及Rstudio-serve
  详细解决方案

CentOS7 配置R语言及Rstudio-serve

热度:57   发布时间:2023-12-23 07:02:50.0

今天找了个导师给了一个CentOS7的服务器,打算安装上R语言的环境,用来跑R脚本,但是由于没有学习和尝试过,所以特此记录一下安装过程,为以后安装提供一些思路

参考一些人的方法后,发现使用rpm包管理器安装的R语言的版本只有3.6,这就可能导致后面很多的包安装不上,所以果断更改方法 , 安装4.1版本的R语言.

1.下载R包

清华下载源 : The Comprehensive R Archive Network (tsinghua.edu.cn)

  1. 右键点击复制连接得到到下载地址如下所示
https://cran.r-project.org/src/base/R-4/R-4.1.1.tar.gz
  1. 然后在centos使用wget下载

    1. 创建文件夹下载 , 或者在/home中下载,我选择下载在home所以先切换到home
    cd /home
    
    1. 下载文件 , 先确保安装wget , 否则先安装wget .使用yum install命令安装
    wget https://cran.r-project.org/src/base/R-4/R-4.1.1.tar.gz
    
    1. 解压
    tar -zxvf R-4.1.1.tar.gz
    
  2. 接下来就是进入解压缩的文件夹

cd R-4.1.1

安装R需要的依赖

因为是导师的服务器 , 没有root权限,只能暂时获取权限来下载 , 如果有root权限的可以去掉后文中的所有sudo

sudo yum install -y gcc
sudo yum install -y gcc-gfortran
sudo yum install -y gcc-c++
sudo yum install -y glibc-headers
sudo yum install -y libreadline6-dev gfortran 
sudo yum install -y readline-devel
sudo yum install -y wget libXt-devel
sudo yum install -y fonts-chinese tcl tcl-devel tclx tk tk-devel
sudo yum install -y mesa-libGLU mesa-libGLU-devel
sudo yum install -y install bzip2-devel 
sudo yum install -y install xz-devel.x86_64 
sudo yum install -y install pcre-devel
sudo yum install -y install libcurl
sudo yum install -y install libcurl-devel
sudo yum install -y  texinfo.x86_64
sudo yum install -y texlive-pdftex-doc.noarch
sudo yum install -y texlive
sudo yum install -y xorg-x11-server-Xvfb
sudo yum install -y xorg-x11-fonts-75dpi
sudo yum install -y xorg-x11-fonts-100dpi
sudo yum install -y libXtst-devel
sudo yum install -y libssh2-devel
sudo yum install -y libgit2-devel
sudo yum install -y mysql-devel
sudo yum install pcre2-devel
./configure --enable-R-shlib=yes --with-tcltk --prefix=/usr/local/R
make
make install

然后我们需要添加环境变量使得我么能在任意地方打开R

  1. 打开配置文件
vi /etc/profile
  1. 添加以下内容
export R_HOME=/usr/local/R
PATH=$PATH:$R_HOME/bin

问题

在安装的时候发现 , 发现缺少了jni.h文件 , 查阅后好像是安装环境和依赖没有装完 , 重新安装一遍后发现还是同样的错误 , 然后更新了源地址更新了所有的包之后 , 再次尝试运行 .

再看一下 , 貌似是因为本机的jdk没有找到jni.h这个文件 , 果断解决办法就是重装jdk1.8

删除旧版jdk

先看一下安装了那些java的包

rpm -qa |grep java

norch结尾的可以不用删除,其他的都需要是删除

然后删除这些包就行

rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

删除后还可以看看还有没有残留,同样是使用rpm -qa |grep java命令

安装jdk

查找一下有那些版本

yum search java|grep jdk
Repository updates is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository cr is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository fasttrack is listed more than once in the configuration
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.i686 : OpenJDK Demos 11
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in a
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in
java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.i686 : OpenJDK libraries for static linking 11
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking
ldapjdk.noarch : The Mozilla LDAP Java SD
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle

安装这两个版本就好

所以运行

yum install java-1.8.0-openjdk-devel.x86_64
yum install java-1.8.0-openjdk-src.x86_64

安装完毕后执行 java -version 命令即可查看当前的版本。有版本就证明安装完成

安装完可看到 java 安装目录下出现 binlib 等文件夹。

再次输入 javac 说明安装成功:

配置 JAVA_HOME 等环境变量

通过 yum install 安装 jdk,是不会自动配置 JAVA_HOME 环境变量的。如果有一些服务依赖这个环境变量就会启动失败。下面演示如何手动配置 JAVA_HOME 环境变量。

找到 JDK 安装路径

(1)首先我们依次执行如下命令,一步步找到正确的 JAVA_HOME 位置:

which java``
输出:/usr/bin/java ls -lrt usr/bin/java
输出:/usr/bin/java -> /etc/alternatives/javals -lrt /etc/alternatives/java输出:/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java(2)可以发现最终找到的位置如下:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64

配置 JAVA_HOME

(1)执行如下命令打开配置环境变量的文件:

vi /etc/profile

(2)在里面添加以下配置(JAVA_HOME 参数根据前面找到的目录路径设置):

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

(3)最后执行如下命令让配置生效:

source /etc/profile

3,测试

执行 echo $JAVA_HOME 如果能正确输出路径则说明配置成功了:

安装宝塔

在运行R脚本的时候我们因为是远程的 , 无法正确看到具体的占用情况 . 所以我们在8080端口安装上宝塔 , 我们就可以在浏览器看到整机的运行情况了

安装宝塔很简单 , 我们只需要打开官网宝塔面板 - 简单好用的Linux/Windows服务器运维管理面板 (bt.cn)

点击立即安装,找到对应的版本安装代码就行

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

这是centos7的安装版本代码 , 运行时发现权限不足.所以我先下载再升权

wget http://download.bt.cn/install/install_6.0.sh
chmod 777 install_6.0.sh
sudo ./install_6.0.sh

就可以顺利安装了

安装RstudioServe

wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.2.1335-x86_64.rpm
sudo yum install rstudio-server-rhel-1.2.1335-x86_64.rpm

安装完RStudio Server,默认就会部署好了,只是最后是IP:8787(例如:222.116.86.11:8787)。

登录验证 . 接下来使用服务器原本的账号密码即可登录。这里需要注意,使用root账号以及对应的密码不能登录,必须创建一个新的账号。

过程中遇到的问题

若我们对服务进行了重启,使用222.116.86.11:8787再登录可能会遇到出现登录卡住的问题,这时候我们需要使用222.116.86.11:8787/auth-sign-in重新登录即可。

配置相关文件

$HIVE_HOME/conf/若没有hive-site.xml文件,直接touch新建一个,编辑:

<configuration><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true&amp;useSSL=false</value></property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value></property><property><name>javax.jdo.option.ConnectionUserName</name><value>root</value></property><property><name>javax.jdo.option.ConnectionPassword</name><value>Zhuqian#1992</value></property>	<property><name>hive.metastore.warehouse.dir</name><value>/usr/local/src/hive/hive-1.2.2/warehouse</value></property><property><name>hive.exec.scratchdir</name><value>/usr/local/src/hive/hive-1.2.2/tmp</value></property><property><name>hive.querylog.location</name><value>/usr/local/src/hive/hive-1.2.2/log</value></property><property><name>hive.metastore.schema.verification</name><value>false</value></property><property> <name>hive.cli.print.current.db</name><value>true</value></property><property> <name>hive.cli.print.header</name><value>true</value></property><property> <name>hive.groupby.skewindata</name><value>true</value></property><!-- 这是hiveserver2 --><property><name>hive.server2.thrift.port</name><value>10000</value></property><property><name>hive.server2.thrift.bind.host</name><value>192.168.44.10</value></property></configuration>

$HADOOP_HOME/etc/hadoop文件下:

core-site.xml编辑如下:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. See accompanying LICENSE file. -->
<!-- Put site-specific property overrides in this file. --><configuration><property><name>fs.defaultFS</name><value>hdfs://192.168.44.10:9000</value></property><property><name>hadoop.tmp.dir</name><value>file:/usr/local/src/hadoop/hadoop-2.6.1/tmp/</value></property><!-- 如果连接不上10000 --><property>     <name>hadoop.proxyuser.root.hosts</name>     <value>*</value></property> <property>     <name>hadoop.proxyuser.root.groups</name>    <value>*</value> </property><property>     <name>hadoop.proxyuser.zhaoshb.hosts</name>     <value>*</value> </property> <property>     <name>hadoop.proxyuser.zhaoshb.groups</name>     <value>*</value> </property>
</configuration>

hdfs-site.xml编辑如下:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. See accompanying LICENSE file. --><!-- Put site-specific property overrides in this file. --><configuration><property><name>dfs.namenode.secondary.http-address</name><value>master:9001</value></property><property><name>dfs.namenode.name.dir</name><value>file:/usr/local/src/hadoop/hadoop-2.6.1/dfs/name</value></property><property><name>dfs.datanode.data.dir</name><value>file:/usr/local/src/hadoop/hadoop-2.6.1/dfs/data</value></property><property><name>dfs.replication</name><value>1</value></property><property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property>
</configuration>

测试连接

执行语句:

hiveserver2

执行jps 查看是否有“Runjar”进程

执行beeline 启动beeline客户端

!connect jdbc:hive2://master:10000

启动hiveserver2,然后才能进行连接:

hive --service hiveserver2

教程到此结束 , 欢迎在评论区指正错误 , 我们互相探讨.

  相关解决方案