开发环境安装apache livyCloudera

Livy 安装和配置

2018-01-17  本文已影响565人  Alex90

一个基于Spark的开源REST服务,它能够通过REST的方式将代码片段或是序列化的二进制代码提交到Spark集群中去执行。它提供了以下这些基本功能:


安装启动

  1. 安装maven
  2. 下载livy
$ git clone git@github.com:cloudera/livy.git
$ export MAVEN_OPTS="-Xmx2g -XX:ReservedCodeCacheSize=512m -XX:MaxPermSize=512M"
$ mvn -Dmaven.test.skip clean package
  1. 修改配置文件
    注释spark.master
vim conf/spark-blacklist.conf
# spark.master
  1. 启动
./bin/livy-server

pyspark测试

查看当前存在的会话

$ curl localhost:8998/sessions
> {"from":0,"total":0,"sessions":[]}

创建pyspark会话

$ curl -X POST --data '{"kind": "pyspark"}' -H "Content-Type:application/json" localhost:8998/sessions
> {"id":0,"owner":null,"proxyUser":null,"state":"starting","kind":"pyspark","log":[]}

$ curl localhost:8998/sessions
> {"from":0,"total":1,"sessions":[{"id":0,"owner":null,"proxyUser":null,"state":"idle","kind":"pyspark","log":[]}]}

查看当前会话状态

$ curl localhost:8998/sessions/0 | python -m json.tool
> {
    "id": 0,
    "kind": "pyspark",
    "log": [],
    "owner": null,
    "proxyUser": null,
    "state": "idle"
}

state为idle表示该会话存活,已经准备就绪,可以向该会话提交任务了。
| python -m json.tool 这是管道命令,把返回的结果格式化显示

提交任务

$ curl localhost:8998/sessions/0/statements -X POST -H 'Content-Type: application/json' -d '{"code":"1 + 1"}'
> {"id":0,"state":"running","output":null}

查看任务结果

$ curl localhost:8998/sessions/0/statements/0
> {"id":0,"state":"available","output":{"status":"ok","execution_count":0,"data":{"text/plain":"2"}}}

如果返回异常,可能是json4s版本兼容问题导致的
修改:$SPARK_HOME目录下的pom.xml文件

<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
<version>3.2.10</version>

将该jar包的版本更改为3.2.10

查看任务结果

$ curl localhost:8998/sessions/0/statements/{id}
$ curl localhost:8998/sessions/0/statements

删除会话

$ curl localhost:8998/sessions/0 -X DELETE
> {"msg":"deleted"}
上一篇下一篇

猜你喜欢

热点阅读