一.ThriftServer介绍
ThriftServer是一个JDBC/ODBC接口,用户可以通过JDBC/ODBC连接ThriftServer来访问SparkSQL的数据。ThriftServer在启动的时候,会启动了一个sparkSQL的应用程序,而通过JDBC/ODBC连接进来的客户端共同分享这个sparkSQL应用程序的资源,也就是说不同的用户之间可以共享数据;ThriftServer启动时还开启一个侦听器,等待JDBC客户端的连接和提交查询。所以,在配置ThriftServer的时候,至少要配置ThriftServer的主机名和端口,如果要使用hive数据的话,还要提供hive metastore的uris。
二.ThriftServer配置
1.基于hive的thrift server2服务的配置:
比如监听端口: hive.server2.thrift.port=10000
hive.server2.thrift.bind.host=localhost
一般情况下,需要将hive.server2.thrift.bind.host改成具体的hostname
2.与SparkSQL一样,需要进行hive的集成
3.启动
sbin/start-thriftserver.sh
http://hadoop-senior01:4040/sqlserver/
sbin/stop-thriftserver.sh ## 关闭命令
4.连接测试
bin/beeline
beeline> !connect jdbc:hive2://localhost:10000
Connecting to jdbc:hive2://localhost:10000
Enter username for jdbc:hive2://localhost:10000: hadoop
Enter password for jdbc:hive2://localhost:10000: ******
bin/beeline
beeline> !connect jdbc:hive2://localhost:10000 gerry 123456
bin/beeline -u jdbc:hive2://localhost:10000 -n gerry -p 123456
5.相关参数说明
driver、url和hive的thriftserver2服务是完全一样的,包括ssl权限验证相关参数
url: jdbc:hive2://localhost:10000
username、password:要求给定的username可以在hdfs进行数据操作,具有hdfs写权限
作用:
提供JDBC给其他应用使用,比如tableau、需要通过jdbc+spark的方式获取hive数据的应用.........
beeline
https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients
hive中提供的方式数据库服务的工具,要求数据库提供JDBC连接方式
命令:!help查看帮助信息
6.测试beeline连接mysql
将驱动添加到spark的classpath中
bin/beeline
beeline> !connect jdbc:mysql://localhost:3306/test root 123456