原理图
配置原理
- MetaStore需要存在并开启
- Spark知道MetaSpark在哪里(ip,端口)
配置具体步骤
进入spark的conf目录,添加hive-default.xml
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://node3:9083</value>
</property>
</configuration>
上传mysql的驱动jar包到spark的jars目录
- 注意版本对应,5.7和8.0对应的jar包不一样
编辑hive的配置文件 hive-site.xml
<property>
<name>hive.metastore.uris</name>
<value>thrift://node3:9083</value>
</property>
构建seesion对象时添加配置
if __name__ == '__main__':
spark = SparkSession.builder.\
appName('test').\
master('local[*]').\
config('spark.sql.shuffle.partitions',2).\
config('spark.sql.warehouse.dir','hdfs://node1:9001/user/hive/warehouse').\
config('hive.metastore.uris','thrift://node3:9083').\
enableHiveSupport().\
getOrCreate()
sc = spark.sparkContext
启动spark的第三方连接服务
/export/server/spark/sbin/start-thriftserver.sh --hiveconf hive.server2.thrift.port=10000 --hiveconf hive.server2.thrift.bind.host=node1 --master local[*]