在Mac上安装Hive.4.0.0(M3:基于arm架构)

本文详细描述了如何在Mac上安装ApacheHive4.0.0,解决ARM架构下brew下载Hive的问题,配置MySQL连接,以及设置HiveServer2和HiveCLI。包括环境变量设置、配置文件编辑、SLF4J绑定管理和Hive服务的启动与停止。
摘要由CSDN通过智能技术生成

要先装好Hadoop,mysql哦!!jdk也自己装好,要装1.8的。

由于M系列芯片使用的是arm架构所以,在mac使用brew下载的hive会报错

这里我直接去阿里镜像上下载

apache-hive-hive-4.0.0安装包下载_开源镜像站-阿里云

下载这个带着bin的

然后解压(在mac里面可以不用tar命令,直接点压缩包它自己会解压,然后把压缩包找个目录保存好,重命名mac里也可以不用mv命令直接control点击文件就可以重命名了)

然后我们vim ~/.bash_profile

#Hive
export HIVE_HOME=/opt/homebrew/Cellar/hive-4.0.0
export PATH=$HIVE_HOME/bin:$PATH

 然后再source ~/.bash_profile

输入hive --version就可以查看版本了

hive --version

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/hive-4.0.0/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/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:/opt/homebrew/Cellar/hive-4.0.0/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/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-Pro.local/Users/denyskuzmenko/projects/hive/fork/hive -r 183f8cb41d3dbed961ffd27999876468ff06690c
Compiled by denyskuzmenko on Mon Mar 25 12:44:09 CET 2024
From source with checksum e3c64bec52632c61cf7214c8b545b564

 然后我们cd到hive的conf(这里目录自己随便在哪里都可以)

/opt/homebrew/Cellar/hive-4.0.0/conf

 把hive-default.xml.template重命名

mv hive-default.xml.template hive-default.xml

使用vim新建一个配置文件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>

 wq退出

安装并配置mysql

去Mysql的官网下载驱动 

MySQL :: Download MySQL Connector/J (Archived Versions)

 

我这里用的是8.2.0版本的,操作系统选择:与平台无关,下载好以后和上面一样解压,重命名

cp /opt/homebrew/Cellar/mysql-connector-j-8.2.0/mysql-connector-j-8.2.0.jar  /opt/homebrew/Cellar/hive-4.0.0/lib

将驱动拷贝到hive的lib目录下,记得用ls看看有没有在了

开一个新的终端sudo mysql.server status(sudo输入的是开机密码,记得mysql要装好)

mysql -u root -p
#新建Hive数据库。
create database hive;    
#这个hive数据库与hive-site.xml中localhost:3306/hive的hive对应,两者名称必须一致,用来保存hive元数据

登陆mysql创建hive数据库 

#先输入
CREATE USER 'hive'@'localhost' IDENTIFIED BY 'hive';
#再输入
GRANT ALL ON *.* TO 'hive'@'localhost';
#将所有数据库的所有表的所有权限赋给hive用户,后面的hive是配置hive-site.xml中配置的连接密码

然后再输入

#刷新mysql系统权限关系表
flush privileges;

在hive目录下执行 

./bin/schematool -initSchema -dbType mysql
#使用Hive自带的schematool工具升级元数据,也就是把最新的元数据重新写入MySQL数据库中。
可以在终端中执行如下命令(注意,不是在“mysql>”命令提示下执行):

如果上面的步骤没问题的话就会出现一大段空白然后最后是Initialization script completed





Initialization script completed

 之后切换到hive的bin目录下执行./hive但是发现进入的是beeline会话,而且会发现在bin目录下执行 ./hive或者./beeline进入的都是beeline(beeline是hive的一个命令行客户端,用于连接本地或者远程服务器上的HiveServer2实例,并执行HSQL查询),这是因为在Hive4.0.0中,HiveCLI已经被弃用了,代替它的是Beeline。所以,启动Hive4.0.0时,会默认进入Beeline命令行界面,而不是HiveCLI。如果想使用HiveCLI,可以考虑降低Hive的版本。

 这样我们就那个都无所谓了,那我这里就使用HiveServer2

先到Hadoop下的这个目录里(我这里的Hadoop是用brew下载的,brew下载的,下载完以后目录自己就是我给出的样子,如果是你自己安装那就不同了,但是只要找到core-site.xml这个文件就可以了,mac上安装Hadoop请参考其他博主的)

/opt/homebrew/Cellar/hadoop/3.4.0/libexec/etc/hadoop

vim编辑core-site.xml加入以下的配置

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

@前面的就是用户名

然后重启集群

Hadoop的sbin下执行./stop-all.sh 再./satrt-all.sh

然后输入这段代码启动hiveserver2(不用在hive目录下执行也可以,如果没反应就到hive的bin目录下./执行)

hive --service hiveserver2&

启动以后会出现这样的会话

SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/hive-4.0.0/lib/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/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

 再去浏览器里输入http://localhost:10002

就可以看见web界面了

然后输入开一个新窗口输入beeline(没反应和上面一样去bin目录里执行./beeline),进去以后就是这样

SLF4J: Found binding in [jar:file:/opt/homebrew/Cellar/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]
Beeline version 4.0.0 by Apache Hive
beeline> 

 输入!connect jdbc:hive2://localhost:10000输入用户hive,密码hive(用户密码之前配置hive-site.xml的时候配置过了)如果成功登陆就会出现0: jdbc:hive2://localhost:10000> 

beeline> !connect jdbc:hive2://localhost:10000
Connecting to jdbc:hive2://localhost:10000
Enter username for jdbc:hive2://localhost:10000: hive
Enter password for jdbc:hive2://localhost:10000: ****
Connected to: Apache Hive (version 4.0.0)
Driver: Hive JDBC (version 4.0.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000> 

刚刚这个是进去beeline以后输入的命令,如果还没有进去beeline的话可以输入下面这个 后面哪里是自己的用户名

beeline -u jdbc:hive2://localhost:10000 -n [自己的用户名]

然后可以show databases;有的话就是配置完成了

想要关闭刚刚那个hiveServer2

先用命令ps aux | grep hive 查看进程大概就是这样的

 51712   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=/opt/homebrew/Cellar/hive-4.0.0/conf/parquet-logging.properties -Djline.terminal=jline.Unsuppo

然后我们kill -9 51712就可以了 会发现localhost:10002那个web页面打不开了就是杀死进程了

  • 26
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值