废话不多说,在我们启动Hive的metastore、hiveserver2和spark的thriftserver 服务后,使用datagrip连接spark发现连接正常。
在控制台,创建数据库后发现Hive无法识别:
我们去查看Hive的元数据库的DBS表,发现abc 这个数据库创建的地址错误,创建在了本地,没有创建在我们的HDFS路径下:
这个原因是:
Spark未成功关联Hive Metastore,Spark对Hive表的支持依赖于Hive的元数据服务,如果Spark无法读取Hive的元数据配置,会默认使用内置的Derby数据库作为本地元数据存储,导致创建的库表只存在于Spark本地的Derby中,Hive自然无法识别。
解决方案:
1.在hive的conf中修改hive-site.xml
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
2.将hive-site.xml 复制到 spark的conf 下
cp /opt/installs/hive/conf/hive-site.xml /opt/installs/spark/conf
3.修改spark下的hive-site.xml
<property>
<name>hive.server2.thrift.port</name>
<value>10001</value>
<description>Port number of HiveServer2 Thrift interface when hive.server2.transport.mode is 'binary'.</description>
</property>
4.不要忘了分发:
xsync.sh /opt/installs/spark/conf/hive-site.xml
5.重启thrift服务:
/opt/installs/spark/sbin/stop-thriftserver.sh
/opt/installs/spark/sbin/start-thriftserver.sh --hiveconf hive.server2.thrift.port=10001 --hiveconf hive.server2.thrift.bind.host=bigdata01 --master yarn --conf spark.sql.shuffle.partitions=2
使用datagrip 重新连接一下,记得刷新一下连接。
测试一下:
至此,成功!