暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Spark Thrift

碧茂大数据 2021-09-09
313

更多精彩,请点击上方蓝字关注我们!

部署Spark-assembly Jar包

  • 下载spark-1.6.3-bin-hadoop2.6.tgz,下载地址如下:

https://www.apache.org/dyn/closer.lua/spark/spark-1.6.3/spark-1.6.3-bin-hadoop2.6.tgz

  • 将下载的spark-1.6.3-bin-hadoop2.6.tgz上传至集群的任意节点并解压,这里以cdh02节点为例

[root@cdh02 ~]# tar -zxvf spark-1.6.3-bin-hadoop2.6.tgz 

  • 将解压出来的spark-assembly-1.6.3-hadoop2.6.0.jar拷贝至CDH的jars目录

<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">[root@cdh02 spark-1.6.3-bin-hadoop2.6]# scp root/spark-1.6.3-bin-hadoop2.6/lib/spark-assembly-1.6.3-hadoop2.6.0.jar opt/cloudera/parcels/CDH/jars/</pre>

  • 替换CDH中spark默认的spark-assembly jar包

  • 将spark-assembly-1.6.3-hadoop2.6.0.jar包上传至HDFS目录

  • 在CM上对Spark进行配置,保存配置并重启Spark服务。

  • 修改/etc/spark/conf/ classpath.txt文件在末尾增加如下内容

    • 由于CDH5.11以后版本,Navigator2.10增加了Spark的血缘分析,所以这里需要添加spark-lineage_2.10-1.6.0-cdh5.13.0.jar包,否则连接Spark会报错找不到com.cloudera.spark.lineage.ClouderaNavigatorListener类。

<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">/opt/cloudera/parcels/CDH-5.13.0-1.cdh5.13.0.p0.29/jars/spark-lineage_2.10-1.6.0-cdh5.13.0.jar</pre>

部署Spark ThriftServer启动和停止脚本

  • 拷贝Spark ThriftServer启动和停止脚本

    • 将 spark-1.6.3-bin-hadoop2.6/sbin/目录下的 start-thriftserver.sh 和 stop-thriftserver.sh 脚本拷贝到/opt/cloudera/parcels/CDH/lib/spark/sbin目录下,并设置执行权限。

[root@cdh02 sbin]# scp start-thriftserver.sh stop-thriftserver.sh opt/cloudera/parcels/CDH/lib/spark/sbin/
[root@cdh02 sbin]# chmod +x opt/cloudera/parcels/CDH/lib/spark/sbin/*thriftserver.sh
[root@cdh02 sbin]# ll opt/cloudera/parcels/CDH/lib/spark/sbin/

  • 修改 load-spark-env.sh 脚本,这个脚本是启动 spark 相关服务时加载环境变量信息的

[root@ip-172-31-5-190 sbin]# cd opt/cloudera/parcels/CDH/lib/spark/bin
[root@ip-172-31-5-190 bin]# pwd
/opt/cloudera/parcels/CDH/lib/spark/bin
[root@ip-172-31-5-190 bin]#
## 将注释掉exec "$SPARK_HOME/bin/$SCRIPT""$@",因为在start-thriftserver.sh脚本中会执行这个命令

测试Spark Thrift

  • 使用beeline通过JDBC连接Spark,可以发现连接的是Spark SQL

[root@ip-172-31-5-190 ~]# beeline
beeline> !connect jdbc:hive2://ip-172-31-5-190:10000
Enter username for jdbc:hive2://ip-172-31-5-190:10000: hive
Enter password for jdbc:hive2://ip-172-31-5-190:10000:

  • 运行SQL测试

<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">*0:* jdbc:hive2://ip-172-31-5-190:10000*> show* tables;
0: jdbc:hive2://ip-172-31-5-190:10000*>* **select** count(*) *from* test_table;
0: jdbc:hive2://ip-172-31-5-190:10000*>* **select** * from test;
0: jdbc:hive2://ip-172-31-5-190:10000*>* **select** * from test_table;
0: jdbc:hive2://ip-172-31-5-190:10000*>* **select** count(test_table.s2) *from* test_table join test on test_table.s1=test.s1;</pre>

  • 在Yarn的8088中查看Spark任务,可以发现都是通过Spark执行的。

总结

  • CDH默认不支持Spark Thrift,需要使用Spark原生的spark-assembly jar包替换CDH自带的jar包

  • CDH5.11版本以后,Navigator2.10增加了Spark的血缘分析,所以需要将spark-lineage的jar加载的Spark的运行环境。

    • 否则连接Spark会报错找不到com.cloudera.spark.lineage.ClouderaNavigatorListener类。

关注公众号:领取精彩视频课程&海量免费语音课程




文章转载自碧茂大数据,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论