linux服务器安装R语言及Rstudio server

Python010

linux服务器安装R语言及Rstudio server,第1张

在linux服务器上使用R语言及Rstudio server

cat /etc/redhat-release: 查看服务器系统版本

wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-3/R-3.6.1.tar.gz

checking for rl_callback_read_char in -lreadline... no

configure: error: --with-readline=yes (default) and headers/libs are not available

configure: WARNING: you cannot build info or HTML versions of the R manuals

configure: WARNING: you cannot build PDF versions of the R manuals

configure: WARNING: you cannot build PDF versions of vignettes and help pages

6.安装

make

make install

安装成功!

R #在命令行直接输入“R”即可进入R 编辑。

q() ##退出R编辑

7.安装R-studio-server

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

yum install rstudio-server-rhel-1.2.1335-x86_64.rpm

8.R-studio-server的一些命令

rstudio-server start ##启动 rstudio

rstudio-server stop ## 关闭rstudio

rstudio-server status ## 查看rstudio 运行状态

运行rstudio-server status出现 “Active: active (running) ” 表示rstudio 已启动

rstudio-server verify-installation ## 查看rstudio 安装错误

rstudio-server restart ##重启

ifconfig ##查看服务器ip地址。

查看运行中R进程

rstudio-server active-sessions

指定PID,停止运行中的R进程

rstudio-server suspend-session <pid>

停止所有运行中的R进程

rstudio-server suspend-all

强制停止运行中的R进程,优先级最高,立刻执行

rstudio-server force-suspend-session <pid>

rstudio-server force-suspend-all

RStudio Server临时下线,不允许web访问,并给用户友好提示

rstudio-server offline

RStudio Server临时上线

rstudio-server online

8.rstudio-server系统设置

主要有两个配置文件,默认文件不存在(非必要,可不做修改)

/etc/rstudio/rserver.conf

/etc/rstudio/rsession.conf

vi /etc/rstudio/rserver.conf

www-port=8080#监听端口,默认是8787,可以不做修改

www-address=127.0.0.0#允许访问的IP地址,默认0.0.0.0

rstudio-server restart

vi /etc/rstudio/rsession.conf

session-timeout-minutes=30#会话超时时间

r-cran-repos= http://ftp.ctex.org/mirrors/CRAN #CRAN资源库

rsession-which-r=/usr/local/bin/R ## 如果非root安装,更改R所在目录。

9.通过浏览器连接Rstudio-server

直接打开浏览器,输入http://<服务器ip>:8787 ## 如果修改过rserver.conf文件,后面的8787端口改为相应的端口即可。

这里需要我们输入用户名和密码。关于用户名有2点注意事项:

(1).不允许使用system 用户登陆,即用户ids小于100的用户。只能用普通用户登录

(2).用户的认证可以使用RSA。

如果没有普通用户,可以添加:

useradd newname # 添加一个名为newname的用户

passwd newname###给新用户newname 设置密码,密码需是复杂密码,否则可能通不过。

usermod -G happy newname ####将新用户newname添加到happy 用户组中,

在用useradd添加用户之后,在默认的情况下,该账号是暂时被封锁的, 也就是说,该账号是无法登录,须要用passwd命令来给新创建的用户设置密码之后才可以使用。

10可能存在的问题

10.1如果你的rstudio-server没有启动 很大程度是安装有误,这里我将我遇到的错误分享出来

rstudio-server verify-installation

There is a libR.so in /usr/lib/R/lib, but (weirdly) ls -l reveals that

it dates from the my previous install of R-3.5.1 for which I did not

configure with --enable-R-shlib.

这里就提到无法找到libR.so文件,原因是配置R语言文件时,没有加参数--enable-R-shlib.

这就必须要重新安装R语言。使用make uninstall 删除之前的安装,最好也删除R-3.6.1所在的文件夹,用“rm -r -f R-3.6.1".

使用rm 命令 -r 参数表示全部删除, -f 参数表示强制删除,不会提醒。 同时使用这两个参数要小心。

10.2 普通用户无法启动rstudio-server

sudo rstudio-server start## 以管理员方式执行命令

这时会需要输入密码并提示

xxx is not in the sudoers file.This incident will be reported.

如果不想出现上面的提示,就是给该用户提高权限,添加用户使用sudo的权利。

su root ###切换到root用户,如果有root权限的话。

chmod u+w /etc/sudoers ###添加sudo文件的写权限

vi /etc/sudoers ###编辑sudoers文件,添加权限。

找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)

youuserALL=(ALL)ALL

%youuser ALL=(ALL)ALL

youuserALL=(ALL)NOPASSWD: ALL

%youuser ALL=(ALL)NOPASSWD: ALL

chmod u-w /etc/sudoers ##撤销sudoers文件写权限

可以。

(一) 在R里下载“Rserve”包,并安装

安装好后,

运行如下命令启动“Rserver”

>library(Rserve)

>Rserve()

Starting Rserve...

"D:\PROGRA~1\R\R-30~1.1\library\Rserve\libs\i386\Rserve.exe"

>

(二) 建立java工程,导入必要的包,写出测试用例

目录结构如下(标红色的是需要的):

Test.java 内容

package com.rTest

import org.rosuda.REngine.REXP

import org.rosuda.REngine.Rserve.RConnection

public class Test {

public static void main(String[] args) {

try {

RConnection c = new RConnection()

REXP x = c.eval("R.version.string")

System.out.println(x.asString())

} catch (Exception e) {

e.printStackTrace()

}

}

}

运行即可

2.3 可能出现的错误

2.3.1 Connection refused: connect

org.rosuda.REngine.Rserve.RserveException: Cannot connect: Connection refused: connect

at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:88)

at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:60)

at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:44)

at com.rTest.Test.main(Test.java:9)

这是由于“Rserve” 服务器没有启动起来的原因,试试在R内运行如下语句

>library(Rserve)

>Rserve()

1.在myeclipse里面,window菜单最后一个preferences,左边点开myclispe,点servers下面找到tomcat,选择tomcat版本,TomcatServer设置为enable,再选择tomcat的路径,OK。2.在myclipse新建一个WEB项目,然后在下面你就可以写jsp程序了,默认会有个index.jsp3.点工具栏上的发布按钮,点右边的ADD,选择你刚才第一步建的tomcat,就会把你的项目发布到tomcat下面4。启动tomcat,在发布按钮旁边,是启动按钮,选择创建的tomcat5.在浏览器里面输入地址:localhost:8080/myeclipse项目名称/index.jsp