Spark on Hive 环境配置
Hive Tables - Spark 3.1.2 Documentation (apache.org)
搭建准备
① 准备 Hadoop
和 Hive
环境
② 准备 Spark on Yarn
环境
③ 启动 Hive
的 metastore
服务
# 进入 Hive 安装目录
cd /opt/server/hive-2.1.0
nohup bin/hive --service metastore &
配置修改
修改 hive-site.xml
配置文件:在 3 台 Spark
服务器上都操作
# 进入 Spark 安装目录
cd /opt/server/spark/conf
# 增加 hive-site.xml 配置文件
vim hive-site.xml
# 增加以下配置信息
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://node1:9083</value>
</property>
</configuration>
启动及测试
① 启动
# 第一种: Local 方式启动 Spark
cd /opt/server/spark
bin/spark-sql --master local[2] --conf spark.sql.shuffle.partitions=2
# 第二种:Standalone 方式启动 Spark
cd /opt/server/spark
bin/spark-sql --master spark://node1:7077 --executor-memory 512m --total-executor-cores 1
② 测试
show databases;
show tables;
Hive SQL 的交互方式
Distributed SQL Engine - Spark 2.4.5 Documentation (apache.org)
开启 Spark
的 ThriftServer
Spark Thrift Server 将 Spark Applicaiton 当做一个服务运行,提供 Beeline 客户端和JDBC方式访问,与 Hive 中 HiveServer2 服务一样的
① 启动 ThriftServer
服务
# 进入 Spark 目录
cd /opt/server/spark
# 启动服务
sbin/start-thriftserver.sh \
--hiveconf hive.server2.thrift.port=10001 \
--hiveconf hive.server2.thrift.bind.host=node1 \
--master local[2]
# 停止使用
sbin/stop-thriftserver.sh
② 查看 WEB-UI
界面
http://node1:4040/jobs/
③ 使用 SparkSQL
的 beeline
客户端命令行连接 ThriftServer
# 进入 Spark 目录
cd /opt/server/spark
# 启动 beeline
bin/beeline
# 输入连接信息
!connect jdbc:hive2://node1:10001
# 依次输入用户名和密码