Rserve安装、配置和远程操控

来源:互联网 发布:查看淘宝店铺排名 编辑:程序博客网 时间:2024/06/03 17:07

关于ubuntu下R的安装在上一篇博文《Ubuntu安装更新最新版本R》中已经讲过了,这篇博文主要介绍的是如何使用Java来调用R。

1. Rserve的安装与配置
Rserve是个什么东西?从这个词面的意思来理解就是R的一个服务,主要是提供远程连接的服务,当然功能是很多的,具体可参考:https://rforge.net/Rserve/

在安装Rserve之前确保R能够正常运行,并正确配置了R的环境变量(Linux与windows用户都需要注意)。
在此,强烈建议安装R 3.2.5 以上的R版本,否则可能会遇到这种奇葩错误。废话不多说,我们直接进入Rserve的安装与配置。

  • 运行R,安装Rserve包
~ sudo R> install.packages("Rserve")
  • 查看Rserve配置
~ R CMD Rserve --RS-settingsRserve v1.7-3config file: /etc/Rserv.confworking root: /tmp/Rservport: 6311local socket: [none, TCP/IP used]authorization required: noplain text password: not allowedpasswords file: [none]allow I/O: yesallow remote access: nocontrol commands: nointeractive: yesmax.input buffer size: 262144 kB

config file: 本地无此文件/etc/Rserv.conf
working root: R运行时工作目录 /tmp/Rserv
port: 端口6311
local socket: TCP/IP协议
authorization: 认证未开启
plain text password: 不允许明文密码
passwords file: 密码文件,未指定
allow I/O: 允许IO操作
allow remote access: 远程访问未开启
control commands: 命令控制未开启
interactive: 允许通信
max.input buffer size: 文件上传限制262mb

  • 创建配置文件
~ sudo vi /etc/Rserv.confworkdir /tmp/Rservremote enablefileio enableauth requiredplaintext enablefileio enableinteractive yesport 6311maxinbuf 262144encoding utf8control enable

开启远程访问权限后配置信息

~ R CMD Rserve --RS-settingsRserve v1.7-3config file: /etc/Rserv.confworking root: /tmp/Rservport: 6311local socket: [none, TCP/IP used]authorization required: yesplain text password: allowedpasswords file: [none]allow I/O: yesallow remote access: yescontrol commands: yesinteractive: yesmax.input buffer size: 262144 kB
  • 指定配置文件
~ R CMD Rserve --RS-conf /etc/Rserv.conf
  • 启动Rserve远程模式
~ R CMD Rserve --RS-enable-remote
  • 查看启动后Rserve端口
~ netstat -nltp|grep Rservetcp  0   0 0.0.0.0:6311   0.0.0.0:*   LISTEN  73821/Rserve 

0.0.0.0:6311 代表不受限的IP访问

2. Java远程连接Rserve

首先,我们需要下载Rserve所使用到的两个Jar包:REngine.jarRserveEngine.jar,下载地址:http://www.rforge.net/Rserve/files/
如果项目使用maven进行管理,那么将下面的内容放入pom.xml文件中:

<dependency>   <groupId>org.rosuda.REngine</groupId>   <artifactId>REngine</artifactId>   <version>2.1.0</version></dependency><dependency>   <groupId>org.rosuda.REngine</groupId>   <artifactId>Rserve</artifactId>   <version>1.8.1</version></dependency>

具体的Java连接代码在这就不给出了,大家可以参考官网给出的Example(https://rforge.net/Rserve/example.html).

在项目中我主要是使用Rsession来和R进行通信,我将在下一篇文章详细介绍Rsession的用法和”keng”。

参考:

  • http://blog.fens.me/r-rserve-java/
  • http://blog.fens.me/r-rserve-server/
  • http://www.rforge.net/Rserve/files/
  • http://www.rforge.net/Rserve/doc.html
  • https://rforge.net/Rserve/example.html
  • http://blog.csdn.net/zhyh1986/article/details/13074395
0 0
原创粉丝点击