栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Hive 连接 secured ES 踩坑日记

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Hive 连接 secured ES 踩坑日记

环境

hive 1.2

es cluster: 6.8.2 [secured ES, SSL]

 建表语句

CREATE EXTERAL TABLE test(

....
) TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='false', 
  'es.nodes'='secured-nodes',
  'es.port'='9200',
  'es.nodes.client.only'='true',
  'es.input.use.sliced.partitions'='false',
  'es.net.http.auth.user'='username',
  'es.net.http.auth.pass'='password',
  'es.net.ssl' = 'true',
  'es.net.ssl.keystore.location' = 'hdfs:///nameserver1/hive/es_certificates/prod-es-secured-key-store.p12',
  'es.net.ssl.keystore.pass' = '***',
  'es.net.ssl.keystore.type' = 'pkcs12',
  'es.net.ssl.truststore.location' = 'hdfs:///nameservice1/hive/es_certificates/prod-es-secured-trusted-store.p12',
  'es.net.ssl.truststore.pass' = '***',
  'transient_lastDdlTime'='1533294367')

异常1 Cannot initialize SSL

.EsHadoopIllegalStateException: Cannot initialize SSL - Expected to find keystore file at [hdfs:///nameservice1/application/lib/es_certificates/fds-prod-es-secured-key-store.p12] but was unable to. Make sure that it is available on the classpath, or if not, that you have specified a valid URI.', sqlState=None, infoMessages=['*org.apache.hive.service.cli.HiveSQLException:java.io.IOException: org.elasticsearch.hadoop.EsHadoopIllegalStateException: Cannot initialize SSL - Expected to find keystore file at [hdfs:///nameservice1/application/lib/es_certificates/fds-prod-es-secured-key-store.p12] but was unable to. 

我把证书文件上传到HDFS上,然后使用hdfs路径,可惜不认识。把证书下载到集群的每个节点,路径改成file:///path/to/*.p12 上述问题解决。 

CREATE EXTERAL TABLE test(

....
) TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='false', 
  'es.nodes'='secured-nodes',
  'es.port'='9200',
  'es.nodes.client.only'='true',
  'es.input.use.sliced.partitions'='false',
  'es.net.http.auth.user'='username',
  'es.net.http.auth.pass'='password',
  'es.net.ssl' = 'true',
  'es.net.ssl.keystore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-key-store.p12',
  'es.net.ssl.keystore.pass' = '***',
  'es.net.ssl.keystore.type' = 'pkcs12',
  'es.net.ssl.truststore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-trusted-store.p12',
  'es.net.ssl.truststore.pass' = '***',
  'transient_lastDdlTime'='1533294367')

启用调试功能:

hive --hiveconf hive.root.logger=DEBUG, console -e "your create table hql"

可以看到加载证书的日志:

DEBUG commonshttp.SSLSocketFactory: Loading keystore located at [file:///opt/hive/es_certificates/prod-es-secured-key-store.p12]

DEBUG commonshttp.SSLSocketFactory: Loading keystore located at [file:///opt/hive/es_certificates/prod-es-secured-trusted-store.p12]

异常2  Cannot initialize SSL - parseAlgParameters failed: ObjectIdentifier() -- data isn't an object ID (tag = 48)
Caused by: org.elasticsearch.hadoop.EsHadoopIllegalStateException: Cannot initialize SSL - parseAlgParameters failed: ObjectIdentifier() -- data isn't an object ID (tag = 48)
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.createSSLContext(SSLSocketFactory.java:173)
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.getSSLContext(SSLSocketFactory.java:158)
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.createSocket(SSLSocketFactory.java:127)
	at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
	at org.elasticsearch.hadoop.rest.commonshttp.CommonsHttpTransport.execute(CommonsHttpTransport.java:482)
	at org.elasticsearch.hadoop.rest.NetworkClient.execute(NetworkClient.java:112)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:380)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:344)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:348)
	at org.elasticsearch.hadoop.rest.RestClient.get(RestClient.java:158)
	at org.elasticsearch.hadoop.rest.RestClient.remoteEsVersion(RestClient.java:574)

在安装了jdk的系统上,执行下面命令

keytool -importkeystore -srckeystore test.p12 [3] -destkeystore test.jks [4] -deststoretype jks

使用jks模式证书

  'es.net.ssl.keystore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-key-store.jks',
  'es.net.ssl.keystore.pass' = '***',
  'es.net.ssl.keystore.type' = 'JKS',
  'es.net.ssl.truststore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-trusted-store.p12',
  'es.net.ssl.truststore.pass' = '***',

异常3  Cannot initialize SSL - Invalid keystore format
Caused by: org.elasticsearch.hadoop.EsHadoopIllegalStateException: Cannot initialize SSL - Invalid keystore format
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.createSSLContext(SSLSocketFactory.java:173)
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.getSSLContext(SSLSocketFactory.java:158)
	at org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.createSocket(SSLSocketFactory.java:127)
	at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
	at org.elasticsearch.hadoop.rest.commonshttp.CommonsHttpTransport.execute(CommonsHttpTransport.java:482)
	at org.elasticsearch.hadoop.rest.NetworkClient.execute(NetworkClient.java:112)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:380)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:344)
	at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:348)
	at org.elasticsearch.hadoop.rest.RestClient.get(RestClient.java:158)
	at org.elasticsearch.hadoop.rest.RestClient.remoteEsVersion(RestClient.java:574)
	at org.elasticsearch.hadoop.rest.InitializationUtils.discoverEsVersion(InitializationUtils.java:320)

出现这个问题,是由于truststore的证书没有改成jks,全部改成jks。

  'es.net.ssl.keystore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-key-store.jks',
  'es.net.ssl.keystore.pass' = '***',
  'es.net.ssl.keystore.type' = 'JKS',
  'es.net.ssl.truststore.location' = 'file:///opt/hive/es_certificates/prod-es-secured-trusted-store.jks',
  'es.net.ssl.truststore.pass' = '***',

参考文章:

spark 读写elasticsearch v7.x之1 建立连接 - 知乎

Spark ElasticSearch EsHadoopIllegalArgumentException unable to find keystore with valid URI - Stack Overflow

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1013871.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号