Hadoop集群中增加与ElasticSearch连接的操作
程序员文章站
2022-06-24 20:54:31
在没有引入elasticsearch-hadoop-xxx.jar相应的Jar包时,的在Hive中执行ElasticSearch外部表操作,会报如下的异常: [plain] view plain copy Exception in thread "main" java.io.IOException: ......
在没有引入elasticsearch-hadoop-xxx.jar相应的Jar包时,的在Hive中执行ElasticSearch外部表操作,会报如下的异常:
- Exception in thread "main" java.io.IOException: Failed on local exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.; Host Details : local host is: "ip-172-17-30-146/172.17.30.146"; destination host is: "ip-172-17-30-146":9000;
- .hadoop.mapreduce.v2.app.MRAppMaster failed in state INITED; cause: org.apache.hadoop.yarn.exceptions.YarnRuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.elasticsearch.hadoop.mr.EsOutputFormat not found
- org.apache.hadoop.yarn.exceptions.YarnRuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.elasticsearch.hadoop.mr.EsOutputFormat not found
此时报的是Yarn服务器上面找不到ES-Hadoop相关的类,此时需要做的将elasticsearch-hadoop-xxx.jar增加到Hadoop相关应用的环境中,根据目前我所用到的环境,需要增加的应用有:
- 1.Hive
- 2.Spark
- 3.Yarn
需要将elasticsearch-hadoop-xxx.jar增加到所有服务器这些应用的环境中,然后重新执行执行就不会报这个问题了。
另外:目前我的做法是手动将elasticsearch-hadoop-6.2.4.jar一台一台复制到Yarn服务器的lib目录下,不知道CDH是否有简化的管理功能,可以直接上传对应的Jar包?
为了操作上的操作,我准备了一个批命令,命令记录如下:
- #/data/share_libs是我的第三共享jar包的目录
- cd /data/share_libs
- wget https://artifacts.elastic.co/downloads/elasticsearch-hadoop/elasticsearch-hadoop-6.2.4.zip
- unzip elasticsearch-hadoop-6.2.4.zip
- cd elasticsearch-hadoop-6.2.4/dist
- #注:这里不要把所有elasticsearch-hadoop*.jar文件都拷贝过去了,否则Yarn中会报这些不同的Jar包的版本冲突
- mv elasticsearch-hadoop-6.2.4.jar /opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/jars/
- cd /data/share_libs
- #删除不必要的资源
- rm -f elasticsearch-hadoop-6.2.4.zip
- rm -rf elasticsearch-hadoop-6.2.4
- #注:目录/data/share_libs,在Spark中设置为了其第三库的目录,在Hive中也设置为了其auxlib目录,因而在这里建立软件链接后,Spark和Hive都可以使用
- #Spark中设置第三库的目录,可以参看前面一篇文章:https://blog.csdn.net/fenglibing/article/details/80437246
- ln -s /opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/jars/elasticsearch-hadoop-6.2.4.jar elasticsearch-hadoop-6.2.4.jar
- cd /opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/lib/hadoop-yarn/lib
- ln -s /opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/jars/elasticsearch-hadoop-6.2.4.jar elasticsearch-hadoop-6.2.4.jar
以下是通过创建一个外部表,然后测试查询的语句:
- create external table test_in_es
- (
- id string,
- k string,
- v string
- )
- STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
- TBLPROPERTIES(
- 'es.nodes' = 'http://vpc-es-xxxxxxxxx.eu-west-1.es.amazonaws.com:80',
- 'es.index.auto.create' = 'false',
- 'es.nodes.wan.only' = 'true',
- 'es.resource' = 'test/test',
- 'es.read.metadata' = 'true',
- 'es.mapping.names' = 'id:_metadata._id,k:k, v:v');
- select * from test_in_es;
- 如果你想了解大数据的学习路线,想学习大数据知识以及需要免费的学习资料可以加群:784789432.欢迎你的加入。