Mac M1安装Hive

news/2024/9/17 0:40:35/ 标签: macos, hive, hadoop

一、下载解压Hive

1.官网地址

https://dlcdn.apache.org/hive/

2.选择对应版本进行下载,这里我以3.1.3为例;

在这里插入图片描述
在这里插入图片描述

hive313_7">3.下载好后,进行解压,并重命名为hive-3.1.3,放到资源库目录下;

二、配置系统环境

1.打开~/.bash_profile文件

open -e ~/.bash_profile

2.添加Hadoop、Hive环境变量

export HADOOP_HOME=/Library/hadoop-3.4.0
export PATH=$PATH:$HADOOP_HOME/binexport HIVE_HOME=/Library/hive-3.1.3
export PATH=$HIVE_HOME/bin:$PATH

3.使得配置生效

source ~/.bash_profile

hadoop_26">4.停止hadoop并重启

如果hadoop正在运行暂停hadoop

# 进入hadoop目录
cd /Library/hadoop-3.4.0
# 停止hadoop服务
./sbin/stop-all.sh
# 启动hadoop
./sbin/start-all.sh

hive_37">5.查看hive版本

hive --version

如果出现mac权限问题,解决方法参考链接

hive --versionSLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Library/hive-3.1.3/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Library/hadoop-3.4.0/libexec/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Library/hive-3.1.3/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Library/hadoop-3.4.0/libexec/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive 4.0.0
Git git://MacBook-Air.local/Users/xxx/projects/hive/fork/hive -r 183f8cb41d3dbed961ffd27999876468ff06690c
Compiled by xxx on Mon Mar 25 12:44:09 CET 2024
From source with checksum e3c64bec52632c61cf7214c8b545b564

三、修改Hive配置文件

hivedefaultxmltemplate_62">1.重命名conf文件夹下的hive-default.xml.template

cd /Library/hive-3.1.3/confmv hive-default.xml.template hive-default.xml

hivesitexml_68">2.新建hive-site.xml

vim hive-site.xmlopen -e hive-site.xml

hive-site.xml文件中添加如下内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&amp;useSSL=false&amp;allowPublicKeyRetrieval=true</value><description>JDBC connect string for a JDBC metastore</description></property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value><description>Driver class name for a JDBC metastore</description></property><property><name>javax.jdo.option.ConnectionUserName</name><value>hive</value><description>username to use against metastore database</description></property><property><name>javax.jdo.option.ConnectionPassword</name><value>hive</value><description>password to use against metastore database</description></property>
</configuration>

保存并关闭;

四、安装并配置mysql

1.下载Mysql驱动

MySQL 驱动下载网址

在这里插入图片描述

hive313lib_109">2.将下载的压缩包解压,找到mysql-connector-j-8.2.0.jar文件,将该文件拷贝到/Library/hive-3.1.3/lib目录下。

3.确保你的电脑安装过mysql

打开终端,执行如下命令:

mysql -u root -p

如果你确定装过mysql,但是执行上述命令后,发现不存在mysql命令,那说明你的系统环境没有配置。

# 查看 mysql 安装路径
which mysql

在这里插入图片描述
若出现路径,则存在mysql。

# 打开如下配置文件
open -e ~/.bash_profile
export PATH=${PATH}:/usr/local/mysql/bin/

配置好后保存,使配置文件生效。

source ~/.bash_profile

4.重新执行mysql 登录

mysql -u root -p

回车,输入密码。

hive_143">五、创建hive数据库

hive_144">1.创建hive数据库

create database hive; CREATE USER 'hive'@'localhost' IDENTIFIED BY 'hive';GRANT ALL ON *.* TO 'hive'@'localhost';#刷新mysql系统权限关系表
flush privileges;

2.使用Hive自带的schematool工具升级元数据

cd /Library/hive-3.1.3
./bin/schematool -initSchema -dbType mysql

出现一段空白,接着出现Initialization script completed。

六、修改Hadoop配置文件并重启

1.编辑Hadoop的core-site.xml配置文件

cd /Library/hadoop-3.4.0
open -e core-site.xml

在文件中补充如下内容:

<property><name>hadoop.proxyuser.用户名.hosts</name><value>*</value>
</property>
<property><name>hadoop.proxyuser.用户名.groups</name><value>*</value>
</property>

保存并推出。

用户名通过如下命令查看

whoami

2.重启Hadoop集群

cd /Library/hadoop-3.4.0/sbin
./stop-all.sh
./satrt-all.sh

七、启动Hive并访问

hive_193">1.启动hive

cd /Library/hive-3.1.3/bin
hive --service hiveserver2&

启动后,出现如下命令证明启动成功:

SLF4J: Found binding in [jar:file:/Library/hive-3.1.3/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Library/hadoop-3.4.0/libexec/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive Session ID = 7afcdcf2-3f5d-4912-99b9-4e57a7ef3a03
Hive Session ID = 51a21ecb-ae06-4ed3-a6b7-a62444b5836e

2.浏览器访问

再去浏览器里输入

http://localhost:10002

就可以见到hive的web界面了
在这里插入图片描述

3.客户端访问

在bin目录下,重启一个终端,输入如下命令:

beeline
!connect jdbc:hive2://localhost:10000

用户名hive,密码hive
成功登录出现
0: jdbc:hive2://localhost:10000>

show databases;

执行上面命令后,若有结果输出,则证明配置完成了。

关闭hiveServer2时,执行如下命令查看hive进程;

ps aux | grep hive 

进程大概是下面内容:

 52843   0.1  2.9 413527440 489776 s003  SN    8:58下午   0:17.23 /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/bin/java -Dproc_jar -Dproc_hiveserver2 -Dlog4j2.formatMsgNoLookups=true -Dlog4j.configurationFile=hive-log4j2.properties -Djava.util.logging.config.file=/Library/hive-3.1.3/conf/parquet-logging.properties -Djline.terminal=jline.Unsuppo

4.通过如下命令杀死该进程

kill -9 52843 

八、通过DBeaver连接Hive

主机:localhost认证:Database Native用户名:hive密码:hive

九、利用Python连接Hive库,并在库中插入数据

代码如下:

from pyhive import hivedef ConnectHive(addr, port, user, pwd, db, auth):try:# 1. Create connectionconn = hive.Connection(host=addr, port=port, username=user, password=pwd, database=db, auth=auth)print("Hive connection successful!")# 2. Use Hive SQL to create tablecreate_tab_sql = """CREATE TABLE users (id INT, name STRING, age INT, address STRING)"""# 3. Execute SQL with cursorwith conn.cursor() as cursor:cursor.execute(create_tab_sql)print("User table created successfully!")except Exception as e:print(f"An error occurred: {e}")finally:# 4. Close connectionif conn:conn.close()print("Hive connection closed.")if __name__ == '__main__':addr = '127.0.0.1'port = 10000user = 'hive'pwd = 'hive'db = 'default'auth = 'LDAP'ConnectHive(addr, port, user, pwd, db, auth)

在执行这段代码时,出现下面报错:

org.apache.hadoop.security.AccessControlException Permission denied: user=hive, access=WRITE, inode="/"

说明hive用户没有写HDFS根目录(/)的权限。

2.解决办法

# 列出hdfs根目录的内容并查看权限
hdfs dfs -ls /

在这里插入图片描述

hdfs dfs -chmod 755 /
hdfs dfs -chown hive:supergroup /

再执行如下命令:

hdfs dfs -ls /

在这里插入图片描述

3.重新运行你的Python代码就成功了。


http://www.ppmy.cn/news/1522074.html

相关文章

lesson1 输出出现重复行的文件名称

lesson1 输出出现重复行的文件名称 1. 代码 package mainimport ("bufio""fmt""io""os" )/*** Author: jiaona.chen* Description:* File: main* Version: 1.0.0* Date: 2024/09/07 15:25*/// 输出出现重复行的文件名称 func main(…

在 Qt Creator 中,输入 /** 并按下Enter可以自动生成 Doxygen 风格的注释

在 Qt Creator 中&#xff0c;当你输入 /** 时&#xff0c;确实会自动补全标准的 Doxygen 风格注释。这是因为 Qt Creator 支持 Doxygen 以及类似的文档注释风格&#xff0c;并且提供了代码自动补全功能。 以下是如何在 Qt Creator 中使用和显示这些注释标记的步骤&#xff1a…

c# 如何让应用程序崩溃时生成dump

在代码中手动生成Dump文件 研究了一下&#xff0c;可以通过代码在应用崩溃或捕获特定异常时&#xff0c;手动生成dump文件。常用的是调用Windows的MiniDumpWriteDump API。可以使用P/Invoke调用该函数&#xff0c;具体步骤如下&#xff1a; 导入必要的Windows API&#xff1a…

代码随想录算法训练营第二十天| 39. 组合总和、40. 组合总和Ⅱ、131. 分割回文串

今日内容 leetcode. 39 组合总和leetcode. 40 组合总和Ⅱleetcode. 131 分割回文串 Leetcode. 39 组合总和 文章链接&#xff1a;代码随想录 (programmercarl.com) 题目链接&#xff1a;39. 组合总和 - 力扣&#xff08;LeetCode&#xff09; 本题不太一样的是可以对同一个数…

【脚手架 第一篇章】介绍一下若依微服务版框架

若依框架&#xff08;RuoYi&#xff09;是一个广泛使用的开源框架&#xff0c;它提供了多种版本以满足不同开发需求。以下是关于若依框架微服务版&#xff08;RuoYi-Cloud&#xff09;的详细介绍&#xff1a; 一、概述 RuoYi-Cloud 是基于 Spring Cloud 和 Spring Boot 的分布…

【盖世汽车-注册安全分析报告】

前言 由于网站注册入口容易被黑客攻击&#xff0c;存在如下安全问题&#xff1a; 暴力破解密码&#xff0c;造成用户信息泄露短信盗刷的安全问题&#xff0c;影响业务及导致用户投诉带来经济损失&#xff0c;尤其是后付费客户&#xff0c;风险巨大&#xff0c;造成亏损无底洞…

dp算法练习【6】

最长公共子序列 1143. 最长公共子序列 给定两个字符串 text1 和 text2&#xff0c;返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 &#xff0c;返回 0 。 一个字符串的 子序列 是指这样一个新的字符串&#xff1a;它是由原字符串在不改变字符的相对顺序…

IntelliJ Idea 常用快捷键列表

CtrlShift Enter&#xff0c;语句完成 “&#xff01;”&#xff0c;否定完成&#xff0c;输入表达式时按 “&#xff01;”键 CtrlE&#xff0c;最近的文件 CtrlShiftE&#xff0c;最近更改的文件 ShiftClick&#xff0c;可以关闭文件 Ctrl[ OR ]&#xff0c;可以跑到大括号的…

httprunner学习笔记(自用版)

目录 一、安装二、脚本录制1、charles录制2、F12脚本录制 三、脚本生成1、har转换为json脚本2、har转换为yml脚本 四、执行脚本五、查看报告六、httpruner接口自动化项目架构 HttpRunner 是一款面向 HTTP(S) 协议的通用测试框架&#xff0c;只需编写维护一份 YAML/JSON 脚本&am…

spring 事物使用场景说明

事务使用场景。 在某些业务场景下&#xff0c;如果一个请求中&#xff0c;需要同时写入多张表的数据。为了保证操作的原子性&#xff08;要么同时成功&#xff0c;要么同时失败&#xff09;&#xff0c;避免数据不一致的情况&#xff0c;我们一般都会用到spring事务。 确实&am…

C++ 设计模式——解释器模式

目录 C 设计模式——解释器模式1. 主要组成成分2. 逐步构建解释器模式步骤1: 定义抽象表达式步骤2: 实现终结符表达式步骤3: 实现非终结符表达式步骤4: 构建语法树步骤5: 实现内存管理步骤6: 创建上下文和客户端 3. 解释器模式 UML 图UML 图解析 4. 解释器模式的优点5. 解释器模…

ActiViz实战:使用Actor2D画一个二维网格

文章目录 一、效果预览二、交互三、C#源码示例一、效果预览 二、交互 1、能实现等比缩放 2、不允许平移和旋转 3、能够与三维坐标大小匹配 三、C#源码示例 private void AddCudeAxes2D() {double scale =

攻防世界 unseping

unseping 攻防世界web新手练习 -unseping_攻防世界web新手题unseping-CSDN博客 这道题对我来说还是有点难&#xff0c;什么oct绕过命令执行第一次遇到捏&#xff0c;所以基本是跟着别人的wp写的&#xff0c;一点点记录吧 先对源码进行分析 <?php highlight_file(__FILE…

【HarmonyOS NEXT】实现截图功能

【HarmonyOS NEXT】实现截图功能 【需求】 实现&#xff1a;实现点击截图按钮&#xff0c;实现对页面/组件的截图 【步骤】 编写页面UI Entry Component struct Screenshot {BuildergetSnapContent() {Column() {Image().width(100%).objectFit(ImageFit.Auto).borderRadi…

【鸿蒙南向开发】OpenHarmony自定义构建函数:@Builder装饰器

前面章节介绍了如何创建一个自定义组件。该自定义组件内部UI结构固定&#xff0c;仅与使用方进行数据传递。ArkUI还提供了一种更轻量的UI元素复用机制Builder&#xff0c;Builder所装饰的函数遵循build()函数语法规则&#xff0c;开发者可以将重复使用的UI元素抽象成一个方法&a…

项目7-音乐播放器7(测试报告)

1.项目背景 音乐播放器采用前后端分离的方法来实现&#xff0c;基于SSM框架构建&#xff0c;同时使用了数据库来存储相关的数据&#xff0c;同时将其部署到云服务器上。 用户可以轻松注册登录&#xff0c;浏览丰富的音乐库&#xff0c;搜索喜欢的歌曲。系统支持多种音频格式播…

【EI会议截稿通知】第九届计算机技术与机械电气工程国际学术论坛(ISCME 2024)

第九届计算机技术与机械电气工程国际学术论坛&#xff08;ISCME 2024&#xff09; 2024 9th International Seminar on Computer Technology, Mechanical and Electrical Engineering 会议信息 大会官网&#xff1a;www.is-cme.com 一轮截稿时间&#xff1a;2024年9月30日&a…

java把文字转MP3语音案例

一 工具下载&#xff1a; https://download.csdn.net/download/jinhuding/89723540 二代码 <dependency><groupId>com.hynnet</groupId><artifactId>jacob</artifactId><version>1.18</version> </dependency>import com.ja…

UEFI——使用标准C库

一、C标准库 C标准库是ANSL C标准为C语言定义的标准库。C标准库包含15个头文件&#xff1a;assert.h ctype.h error.h float.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stddef.h stdio.h stdlib.h string.h time.h。标准库函数与C语言的紧密结合给我们开发程序带…

本地Docker部署Navidrome音乐服务器与远程访问听歌详细教程

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…