环境配置
本机环境
jdk8
mac m1 arm_x64
ssh
mac相关的配置主要包括
● 系统偏好设置-共享-勾选远程登录
● 为.ssh相关文件设置合理的权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
● 确保ssh localhost成功
hadoop安装
部分参考博客博客
已官方文档为准
hadoop包括hdfs、yarn等组件
hdfs相关命令主要包括
- bin/hdfs namenode -format 文件系统格式化
- sbin/start-dfs.sh 启动hdfs。启动后应在此页面看到hdfs相关信息
- jps可看到NameNode与DataNode。若DataNode未成功启动,则重启电脑一般可恢复
- sbin/stop-dfs.sh停止hdfs
yarn相关命令主要包括
- sbin/start-yarn.sh启动yarn主服务。启动后在此页面可看到yarn相关信息
- jps可看到ResourceManager与NodeManager
- yarn node -list确保至少有一个node。如果0个node,重启一般可解
- sbin/stop-yarn.sh关闭yarn
hive 安装
参考视频 p5 安装hive
在官方下载 apache-hive-3.1.3-bin.tar.gz 文件
hive 常用命令
- 依赖于启动hadoop,进入hive目录
- bin/schematool -dbType derby -initSchema初始化源数据库 derby,即生成metastore_db文件夹。如果已有该文件夹,需提前删除
- bin/hive进入hive命令行客户端
- show databases;
- show tables;
- create table stu(id int, name string);建stu表
- insert into stu values(1,“ss”);
- nohup hive --service metastore &在后台启动 Hive 的 Metastore 服务
- netstat -an |grep9083 确认正常启动
- exit;退出hive命令行客户端
hive-site.xml相关的问题参见博客
避免打印过多日志,参考博客
基于源码编译hive
踩坑
为什么博主要自行编译hive
因为执行insert into stu values(1,“ss”);时报错。主要报错信息为
Error: java.lang.RuntimeException: java.lang.NoSuchFieldException: parentOffset
at org.apache.hadoop.hive.ql.exec.SerializationUtilities$ArrayListSubListSerializer.<init>(SerializationUtilities.java:388)
参考博客未能解决
参考博客是源码问题,应通过修改源码重新编译解决
环境
务必使用linux编译
不要使用m1芯片的mac,因为hive依赖的com.google.protobuf:protoc:2.5.0不提供适配osx-aarch_64架构的m1芯片的可执行文件。即使在pom文件中添加<os.detected.classifier>osx-x86_64</os.detected.classifier>也无法避免。报错信息如下所示
[ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.5.1.1:run (default) on project hive-standalone-metastore: Error resolving artifact: com.google.protobuf:protoc:2.5.0:exe:osx-x86_64: Could not find artifact com.google.protobuf:protoc:exe:osx-aarch_64:2.5.0 in tbmirror-all (http://mvnrepo.alibaba-inc.com/mvn/repository)
不要使用windows,因为编译需用到bash,且有其他问题
修改源码
按照博客的建议,修改ArrayListSubListSerializer相关的源码
public ArrayListSubListSerializer() {
try {
final Class<?> clazz = Class.forName("java.util.ArrayList$SubList");
_parentField = getParentField(clazz);
_parentOffsetField = getOffsetField(clazz);
_sizeField = clazz.getDeclaredField( "size" );
_parentField.setAccessible( true );
_parentOffsetField.setAccessible( true );
_sizeField.setAccessible( true );
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
...
private static Field getOffsetField(Class<?> clazz) throws NoSuchFieldException {
try {
// up to jdk8 (which also has an "offset" field (we don't need) - therefore we check "parentOffset" first
return clazz.getDeclaredField( "parentOffset" );
} catch (NoSuchFieldException e) {
// jdk9+ only has "offset" which is the parent offset
return clazz.getDeclaredField( "offset" );
}
}
编译
在官方链接下载apache-hive-3.1.3-src.tar.gz文件并解压
参考官方文档 ,确保使用jdk 8 (mvn -v 显示的jdk版本为jdk8),在项目根目录下mvn clean install -Pdist,iceberg -DskipTests, 编译完成后,packaging/target/apache-hive-3.1.3-bin/apache-hive-3.1.3-bin路径下即为可执行文件 (对标官方apache-hive-3.1.3-bin.tar.gz解压出来的东西)