使用confluent将Kafka中的数据入库hive失败的解决方案
应用场景:
用户想在 HD平台使用confluent开源组件将Kafka中的数据直接导入到hive中,测试环境中已经实现,但生产环境中由于平台开启了Kerberos安全认证服务,所以一直报认证失败的日志.

confluent:
confluent将数据导入hive库: 先将数据导入到hdfs上指定的目录下,然后通过外表的形式入库hive.
confluent通过metastore服务(thirft://url:9083))获取hive的元数据.
官网配置文档:
数据导入hdfs的配置:
`name=hdfs-sink`
`connector.class=io.confluent.connect.hdfs.HdfsSinkConnector`
`tasks.max=1`
`topics=test_hdfs`
`hdfs.url=hdfs://localhost:9000`
`flush.size=3`
数据直接入户hive需要增加的配置:
`hive.integration=true`
`hive.metastore.uris=thrift://localhost:9083 `
`schema.compatibility=BACKWARD`
如果平台有Kerberos安全认证需要增加的配置:
`hdfs.authentication.kerberos=true`
`connect.hdfs.principal=connect-hdfs/_HOST@YOUR-REALM.COM`
`connect.hdfs.keytab=path to the connector `
`keytab
hdfs.namenode.principal=namenode principal`
问题排查:
通过查看confluent和hive的部分代码发现confluent导入数据到hive共需要两次认证:
第一次登陆是在io.confluent.connect.hdfs.DataWriter中使用confluent配置文件中connect.hdfs.principal提供的principal登陆

第二次登陆是在org.apache.hadoop.hive.metastore.HiveMetaStoreClient中通过hive-site.xml文件中的配置信息登陆
如果sasl参数设置为true则先认证,然后获取client,如果sasl参数为false,则先获取client,然后进行非安全模式下的认证.两种模式通过不同的方式获取道德用户信息是不同的,安全模式下用户为Kerberos用户(如principal=connect-hdfs/_HOST@YOUR-REALM.COM,则用户名为connect-hdfs),非安全模式下的用户为Linux上的用户(whoami).

hive-site.xml文件加载


由于confluent的配置文件中没有配置hive.conf.dir参数,因此使用了sasl的默认值false,导致认证失败.

网友评论