hive通过外表整合es,超详细过程。

news2024/9/28 3:19:18

参考官网 

Apache Hive integration | Elasticsearch for Apache Hadoop [7.17] | Elastic

官网的介绍很简单,我看了很多博客,写的也很简单,但是我搞了半天才勉强成功,分享下,免得各位多走弯路。

环境准备

官网也很贴心的给了几种方式。

1.$ bin/hive --auxpath=/path/elasticsearch-hadoop.jar  

2.$ bin/hive -hiveconf hive.aux.jars.path=/path/elasticsearch-hadoop.jar  

3.修改hive-site.xml

看似方法很多 其实有问题,首先我们现在都是beeline模式登录,bin/hive已经被废弃了。那么beeline能用吗?貌似可以用 第1和第2基本上是一样的

网上还有一种办法  直接把jar上传到这个目录/opt/cloudera/parcels/CDH/lib/hive/auxlib/   auxlib很明显就是上面的变量

beeline -u "jdbc:hive2://cdp-node02:2181,cdp-node03:2181,cdp-node04:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"   -hiveconf hive.aux.jars.path=/path/elasticsearch-hadoop.jar

发现还是没有读取到jar 算了吧

第3种貌似是最好的,但是要动集群配置很麻烦,

于是只有用最简单的方式add jar,注意这个只是当前会话有效;

下载jar包

这个时候有小伙伴会问了 这个jar怎么来的,我看官网好像也没给例子呀。

通过maven,新建一个工程,记住这个工程还有用的

网上看到还有可以直接在服务器wget的。。

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-hadoop</artifactId>
    <version>7.14.2</version>
</dependency>

对了低版本的es可能没有个http-client的jar

<dependency>

         <groupId>commons-httpclient</groupId>

        <artifactId>commons-httpclient</artifactId>

        <version>3.1</version>

</dependency> 

通过maven把这个jar下下来 ,然后再上传到服务,记住改下es.version

添加到hdfs 

 进入beeline add jar

add jar hdfs:///user/hive/elasticsearch-hadoop-7.5.1.jar;

add jar hdfs:///user/hive/commons-httpclient-3.1.jar;

或者

add jar hdfs:///user/hive/elasticsearch-hadoop-7.14.2.jar;

list jar 可以看是否添加成功

 至此 我们的hive已经有了这个jar。

开始建表

官网很多demo,肯定找最简单的来。

参考配置

 但是此时我又有问题了。这个demo 明显不对,es的地址都没有啊。

Configuration | Elasticsearch for Apache Hadoop [7.17] | Elastic

这里提到了essential 和required看来都是必须的,还有写defalut的就不说了。

用户认证

因为我的es还有认证所以需要输入用户密码继续在配置里找参数

 create  external table  esdata.cc_test2
 (id string ,name string ,des string )
 STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'  
 TBLPROPERTIES(
 'es.net.http.auth.user'='xxxxx',
 'es.net.http.auth.pass'='xxxxxx' , 
 'es.nodes'='9.134.161.140',        --连接地址        
 'es.resource' = 'i_dw_cc_test' )   --es7的时候没有type了,这里不需要写type

 至此参考了了很多人的文章,感觉也差不多了。结果还是有问题。

报错1

先说一个问题。建好表后,insert into的时候报错了

我已经认证了,为什么这里还是报权限错误呢?我这个用户在es是可以查和插入这个index的数据的 确定以及肯定。

分析报错原因,查看源码,这里就提到刚刚那个工程了。

搜索RestClient.getHttpNodes 

这个熟不熟悉。这个不就是kibana的get请求么,我在es试了确实没权限,要组长帮忙开通这个权限后,这个错就解决了。

报错2

接着建表。然后又出错了!!!!!!

先给大家看下代码 注意这个node =9.134.161.140

 连接 正常。我hive建表的es.node也是这个地址

 但是当我执行select count(1) from cc_test;时报错了。

Error: Error while compiling statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.tez.TezTask. Vertex failed, vertexName=Map 1, vertexId=vertex_1690006488152_0865_1_00, diagnostics=[Vertex vertex_1690006488152_0865_1_00 [Map 1] killed/failed due to:ROOT_INPUT_INIT_FAILURE, Vertex Input: cc_test initializer failed, vertex=vertex_1690006488152_0865_1_00 [Map 1], org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: [GET] on [_nodes/http] failed; server[9.10.132.27:9200] returned [403|Forbidden:]

--注意这里9.10.132.27 怎么这是个啥ip。
    at org.elasticsearch.hadoop.rest.RestClient.checkResponse(RestClient.java:486)
    at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:443)
    at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:437)
    at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:397)
    at org.elasticsearch.hadoop.rest.RestClient.execute(RestClient.java:401)
    at org.elasticsearch.hadoop.rest.RestClient.get(RestClient.java:177)
    at org.elasticsearch.hadoop.rest.RestClient.getHttpNodes(RestClient.java:134)
    at org.elasticsearch.hadoop.rest.RestClient.getHttpDataNodes(RestClient.java:151)
    at org.elasticsearch.hadoop.rest.InitializationUtils.filterNonDataNodesIfNeeded(InitializationUtils.java:157)

因为es不是我搭建的,所以我也很难搞。但是没关系,我刚刚不是java客户端连接上了吗? 我根据客户端查下, 其实上面的那张图片也说明了这个问题,就是怎么连接到DATANODE了呢? 

添加参数

无奈,继续查找参数。

es.nodes.ingest.only (default false) -- 这个感觉也有用懒得试了。

es.nodes.wan.only (default false) --反正是加了这个参数就好了。其中过程复杂就不说了。

简单的理解,我们最开始写的地址没有错,但是es这个家伙会发现其他节点的ip,然后用其他ip去连,你这个为true了就只能用我写的那个了。后面看了下这个和腾讯云 阿里云部署有关。

成功案例

最后的建表语句

  create  external table  esdata.cc_test3
 (id string ,name string ,des string )
 STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'  
 TBLPROPERTIES(
 'es.net.http.auth.user'='xxxx',
 'es.net.http.auth.pass'='xxxx' ,
 'es.nodes'='9.134.161.140',
 'es.nodes.wan.only'='true',
 'es.resource' = 'i_dw_cc_test',
 'es.index.auto.create' = 'false'); 

count

 group by

insert 

遗留问题

以为到这里就大功告成了吗? 我遇到了一个最大的问题。。。。一直没说

就是我不能select * 。 上面的那个查询是可以select id,name from t group by id,name

但是tm的就是不能直接select *!!!!!!!!!!!!!!

 关键是这个报错我连错误日志都看不懂,感觉就是连接hive出错了。但是select 其他都是正常呀。。 等待研究。。。。 这个报错我仔细看了下源码,好像是读取我的输入内容 也就是select *

读取之后解析的时候出问题了(我select 普通表是ok的)

又没有好心人遇到过同样的问题,留个言。

-----------2023-08-02---------------------------

最近又试了下发现这个问题神奇的自己好了。目前怀疑是和我当初在es建的index有关,但是又没有证据。

目前select insert各种正常。

但是注意

hive可以insert 和select 但是是无法truncate es的数据的!!

delete因为没有建事务表暂时不知道

进一步探索

以为到这就完了吗?还有!!

比如我上面创建外表的时候tblproperties里会有user和pass,当其他人show create table的时候就可以看到账号密码,不安全。或者其他同事也想创建es外表,但是呢es的账户又不好直接告诉别人,那怎么办?

这玩意让我想到了以前用jdbc外表的时候,也有类似的操作

jdbc外表加密

JDBC Storage Handler - Apache Hive - Apache Software Foundation

CREATE EXTERNAL TABLE student_jdbc

(

  name string,

  age int,

  gpa double

)

STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'

TBLPROPERTIES (

    "hive.sql.database.type" "MYSQL",

    "hive.sql.jdbc.driver" "com.mysql.jdbc.Driver",

    "hive.sql.jdbc.url" "jdbc:mysql://localhost/sample",

    "hive.sql.dbcp.username" "hive",

    "hive.sql.dbcp.password" "hive",

    "hive.sql.table" "STUDENT",

    "hive.sql.dbcp.maxActive" "1"

);

转化后

 那么推断es肯定也有类似的加密措施

es外表加密

Configuration | Elasticsearch for Apache Hadoop [7.17] | Elastic

 这里提到了es.keystore.location 好像是把密码放到一个文件里,然后通过文件去读取密码

点击secure settings

Security | Elasticsearch for Apache Hadoop [7.17] | Elastic

 Authentication

The authentication support in elasticsearch-hadoop is of two types:

Username/Password

Set these through es.net.http.auth.user and es.net.http.auth.pass properties.

PKI/X.509

Use X.509 certificates to authenticate elasticsearch-hadoop to elasticsearch-hadoop. For this, one would need to setup the keystore containing the private key and certificate to the appropriate user (configured in Elasticsearch) and the truststore with the CA certificate used to sign the SSL/TLS certificates in the Elasticsearch cluster. That is one setup the key to authenticate elasticsearch-hadoop and also to verify that is the right one. To do so, one should setup the es.net.ssl.keystore.location and es.net.ssl.truststore.location properties to indicate the keystore and truststore to use. It is recommended to have these secured through a password in which case es.net.ssl.keystore.pass and es.net.ssl.truststore.pass properties are required.

--就是这里了 可以存密码

官方案例

##基础操作 
$> java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool <command> <args>
##创建一个文件保存密码
$> java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool create
$> ls
esh.keystore
##查看文件里有哪些属性
$> java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool list
##添加属性 交互模式
$> java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool add the.setting.name.to.set
##添加属性 非交互模式
$> cat /file/containing/setting/value | java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool add --stdin the.setting.name.to.set
##移除属性
$> java -classpath path/to/eshadoop.jar org.elasticsearch.hadoop.cli.Keytool remove the.setting.name.to.set

自己操作

[root@cdp-node12 /home/cclovezbf]# pwd
/home/cclovezbf
[root@cdp-node12 /home/cclovezbf]# 
[root@cdp-node12 /home/cclovezbf]# ls
elasticsearch-hadoop-7.14.2.jar
[root@cdp-node12 /home/cclovezbf]# java -cp elasticsearch-hadoop-7.14.2.jar org.elasticsearch.hadoop.cli.Keytool create
[root@cdp-node12 /home/cclovezbf]# ls
elasticsearch-hadoop-7.14.2.jar  esh.keystore
[root@cdp-node12 /home/cclovezbf]# java -cp elasticsearch-hadoop-7.14.2.jar org.elasticsearch.hadoop.cli.Keytool add es.net.http.auth.user
Enter value for es.net.http.auth.user:  xxxx
[root@cdp-node12 /home/cclovezbf]# java -cp elasticsearch-hadoop-7.14.2.jar org.elasticsearch.hadoop.cli.Keytool list
es.net.http.auth.user

 然后我久兴高采烈的

create external table if not exists dwintdata_es.dw_f_da_websites2
(
    `eid`                   string COMMENT '新企业编码EID',
    `source_eid`            string COMMENT '数据源企业编码EID',
    `web_type`              string COMMENT '网址类型',
    `web_name`              string COMMENT '网址名称',
    `web_url`               string COMMENT '网址',
    `date`                  string COMMENT '获取日期',
    `local_row_update_time` string COMMENT '合合备库数据更新时间',
    `etl_create_time`       string COMMENT 'Kudu数据更新时间',
    `etl_update_time`       string COMMENT 'DW数据更新时间',
    data_source             string
)
    STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
    TBLPROPERTIES (
        'es.net.http.auth.pass' = 's2@enterprise',
        'es.keystore.location' = '/home/cclovezbf/esh.keystore',
        'es.nodes' = '9.134.161.140',
        'es.nodes.wan.only' = 'true',
        'es.index.auto.create' = 'false',
        'es.resource' = 'i_dm_f_da_websites'
        );

神奇的是昨天晚上这样建表后就ok了。也能select, 我今天感觉不对,想把文件放到hdfs上就把昨天的表删除了,结果今天建的也不能查了,昨天的表也删除了,找不到语句了,真是他妈的服了。

Error: java.io.IOException: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Expected to find keystore file at [hdfs://s2cluster/user/hive/esh.keystore] but was unable to. Make sure that it is available on the classpath, or if not, that you have specified a valid file URI. (state=,code=0)
 无奈之下继续看官网

Once your settings are all specified, you must make sure that the keystore is available on every node. This can be done by placing it on each node’s local file system, or by adding the keystore to the job’s classpath. Once the keystore has been added, its location must be specified with the es.keystore.location. To reference a local file, use a fully qualified file URL (ex file:///path/to/file). If the secure store is propagated using the command line, just use the file’s name.

这里说了两种办法 

1.是每个节点的文件系统都放keystore

2.是add keystore 我理解为 add jar/add file一样 

难搞啊

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/832323.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

论文研读|生成式文本隐写发展综述

前言&#xff1a;最近接触了文本隐写这一研究领域&#xff0c;大概率以后深入这个方向开展研究&#xff0c;以下是本人近日对该领域研究现状的调研总结&#xff0c;以及生成式文本隐写代表性工作的相关介绍&#xff0c;便于厘清生成式文本隐写的发展脉络以及探寻未来研究空间。…

Go学习第三天

map的三种声明定义方式 声明map后&#xff0c;一定要make开辟空间&#xff0c;否则会报越界且不能使用 package mainimport "fmt"func main() {// 第一种声明方式// 声明myMap1是一种map类型 key是string value是stringvar myMap1 map[string]string// 判断一下map在…

接口请求(get、post、head等)详解

一&#xff0e;接口请求的六种常见方式&#xff1a; 1、Get 向特定资源发出请求&#xff08;请求指定页面信息&#xff0c;并返回实体主体&#xff09; 2、Post 向指定资源提交数据进行处理请求&#xff08;提交表单、上传文件&#xff09;&#xff0c;又可能导致新的资源的建…

【高光谱图像的去噪算法】通过全变异最小化对受激拉曼光谱图像进行去噪研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

HCIP 交换综合实验--企业三层架构

题目 1、内网IP地址使用172.16.0.0/26分配 2、SW1和SW2之间互为备份 3、VRRP/STP/VLAN/Eth-trunk均使用 4、所有PC均通过DHCP获取IP地址 5、ISP只能配置IP地址 6、所有电脑可以正常访问ISP路由器环回 实验步骤 第一步、规划IP地址 R1-R2&#xff1a;100.1.1.0/24 R2-LSW1…

【远程桌面软件NoMachine】

Remote Access for Everybody 特色&#xff1a;快速、安全、跨平台、免费且简单易用&#xff0c;尤其是在带宽低、速率慢的网络环境下&#xff0c;NoMachine仍能保持良好的性能。 官网地址为&#xff1a;https://www.nomachine.com/

c++--简单多状态动态规划问题

PS:以下代码均为C实现 1.按摩师 力扣 一个有名的按摩师会收到源源不断的预约请求&#xff0c;每个预约都可以选择接或不接。在每次预约服务之间要有休息时间&#xff0c;因此她不能接受相邻的预约。给定一个预约请求序列&#xff0c;替按摩师找到最优的预约集合&#xff08;总…

【JAVA】正则表达式是啥?

个人主页&#xff1a;【&#x1f60a;个人主页】 系列专栏&#xff1a;【❤️初识JAVA】 文章目录 前言正则表达式正则表达式语法正则表达式的特点捕获组实例 前言 如果我们想要判断给定的字符串是否符合正则表达式的过滤逻辑&#xff08;称作“匹配”&#xff09;&#xff0c…

2023华数杯数学建模C题思路 - 母亲身心健康对婴儿成长的影响

# 1 赛题 C 题 母亲身心健康对婴儿成长的影响 母亲是婴儿生命中最重要的人之一&#xff0c;她不仅为婴儿提供营养物质和身体保护&#xff0c; 还为婴儿提供情感支持和安全感。母亲心理健康状态的不良状况&#xff0c;如抑郁、焦虑、 压力等&#xff0c;可能会对婴儿的认知、情…

搭建 Vite + Vue3 + Pinia + Element Plus 项目。

一、基础项目搭建&#xff1a; 开发工具推荐 VS Code 开发&#xff0c;配合插件如下&#xff1a; 插件名功能TypeScript Vue Plugin (Volar)用于 TypeScript 的 Vue 插件Vue Language Features (Volar)Vue3.0 语法支持 1. 创建项目 可以通过附加的命令行选项直接指定项目名…

第20节 R语言医学分析:某保险医疗事故赔偿因素分析

文章目录 某保险医疗事故赔偿因素分析源码源文件下载某保险医疗事故赔偿因素分析 我们分析数据集“诉讼”的第一个方法是确定样本数量、变量类型、缩放/编码约定(如果有)用于验证数据清理。 接下来,数据集看起来很干净,没有缺失值,并且对于分类变量,将编码约定替换为实际…

LeetCode 热题 100 JavaScript--543. 二叉树的直径

给你一棵二叉树的根节点&#xff0c;返回该树的 直径 。 二叉树的 直径 是指树中任意两个节点之间最长路径的 长度 。这条路径可能经过也可能不经过根节点 root 。 两节点之间路径的 长度 由它们之间边数表示。 var diameterOfBinaryTree function(root) {var maxDiameter…

leetcode每日一练-第88题-合并两个有序数组

一、解题方法 先合并&#xff0c;再排序 二、code class Solution { public:void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {for(int i0;i<n;i){nums1[mi]nums2[i];//将 nums2 中的元素逐个复制到 nums1 的尾部}sort(nums1.beg…

基于遗传算法的试题组卷(一)

基于遗传算法的试题组卷 IT企业每年都会在春季和秋季举行校园招聘&#xff0c;对于个性化定制的试卷需求量很大&#xff0c;如何组出又好又快的定制化试题对于IT企业非常重要。组卷技术主要针对知识点覆盖率&#xff0c;题型&#xff0c;难度系数&#xff0c;试题数量等一些试题…

为什么感觉 C/C++ 不火了?

首先C和C是两个非常不一样的编程语言。 C语言在系统开发领域地位非常稳固&#xff0c;几乎没有替代产品。应用层开发近年来略微有被Rust取代的迹象。 C由于支持的编程范式过多&#xff0c;导致不同水平的人写出来的代码质量差异太大&#xff0c;这给软件的稳健性带来了很大的…

C高级_第二讲_shell指令和shell脚本_递归练习

思维导图 递归实现&#xff0c;输入一个数&#xff0c;输出这个数的每一位 int funh(int num){if(0 num){return 0;}else{funh(num/10);printf("%d\n", num%10);} }int main(int argc, const char *argv[]) {puts("请输入一个数");int num 0;scanf(&quo…

C++11中的内存模型

一、几种关系术语 1.1、sequenced-before sequenced-before用于表示同一个线程中&#xff0c;两个操作上的先后顺序&#xff0c;这个顺序是非对称、可以进行传递的关系。 它不仅仅表示两个操作之间的先后顺序&#xff0c;还表示了操作结果之间的可见性关系。两个操作A和操作…

《长安的荔枝》阅读笔记

《长安的荔枝》阅读笔记 2023年6月9号在杭州的小屋读完&#xff0c;作者以“一骑红尘妃子笑”的典故&#xff0c;想象拓展出来的荔枝使李善德&#xff0c;为了皇帝要求在贵妃寿辰&#xff0c;六月一号那天要吃到10斤的荔枝。需要从广州运送到长安即如今的西安。本来以为这个差事…

SequenceDiagram 查看代码时序图的利器,做技术方案必备!

前言 “ 无论是快速了解业务流程&#xff0c;还是快速的熟悉系统的业务代码逻辑&#xff0c;以及各个类和方法等的调用关系&#xff0c;时序图无疑是其中一种不可获取的简便快捷的方式。一起来了解下&#xff0c;IDEA如何快速生成时序图吧。” 工作中&#xff0c;经常需要绘制…

async 和 await的用法

async 函数 async 函数是使用async关键字声明的函数。async 函数是 AsyncFunction构造函数的实例&#xff0c;并且其中允许使用 await 关键字。async 和 await 关键字让我们可以用一种更简洁的方式写出基于 Promis的异步行为&#xff0c;而无需刻意地链式调用 promise。 asyn…