前言
在大数据数仓实践过程中,hive技术栈充当了非常重要的环节,很多大数据平台,中台都是基于hive+hadoop+spark来搭建的,所以我们对于hive的编译,构建,安装是需要掌握的非常清楚。
而我们大数据的研发人员比较常用mac电脑来开发,mac 最新的 m1/m2 arm版本的系统在编译hive/hadoop的过程中会遇到protobuf编译失败的问题。
下面就是在编译过程中,遇到的问题,希望能给大家带来清晰的指导
编译命令
mvn -B -e clean package -Pdist -DskipTests
[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: com.google.protobuf:protoc:exe:osx-aarch_64:2.5.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.17.3/
[INFO] Resolving artifact: com.google.protobuf:protoc:3.17.3, platform: osx-aarch_64
需要修改os.arch
mvn -B -e clean package -Pdist -DskipTests -Dos.arch=x86_64
直接编译会遇到:
[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: Could not find artifact com.google.protobuf:protoc:exe:osx-aarch_64:2.5.0 in central (https://repo.maven.apache.org/maven2)
这是由于Hive依赖于protoc-2.5.0的库在Maven的central repo, 没有ARM64版本的,有两种方式来规避该问题,一种是修改依赖库的版本,另一种是手动编译。
规避方式:
直接编译,也会报错,需要打上补丁,脚本如下:
# install dependencies for protobuf buildapt-get install autoconf automake libtool -y# build protobuf-2.5.0 for ARM64 archpushd /usr/local/src/
wget https://github.com/google/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.gz# Fix protobuf-2.5.0 building on ARM64wget -O protobuf-2.5.0-arm64.patch https://www.dropbox.com/s/713wql5cw9dfxhx/protobuf-2.5.0-arm64.patch?dl=0
tar xfz protobuf-2.5.0.tar.gzcd protobuf-2.5.0
patch -p1 < ../protobuf-2.5.0-arm64.patch
apt-get install build-essential
apt-get install automake libtool autoconf
./autogen.sh
./configure --prefix=/usr
make
make installpopdldconfig
protoc --version
下载 protobuf 包
wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v2.5.0.tar.gz
tar -xvzf v2.5.0.tar.gz
下载自github的代码需要首先执行 $ ./autogen.sh 生成configure文件但注意autogen.sh 需要gtest包,默认是从 googletest.googlecode.com下载,国内需要FQ才能访问,autogen.sh运行失败
修改一下autogen.sh
将这段:
echo "Google Test not present. Fetching gtest-1.5.0 from the web..."
curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
mv gtest-1.5.0 gtest
修改为:
wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
tar xzvf release-1.5.0.tar.gz
mv googletest-release-1.5.0 gtest
编译:
$ ./configure
$ make
$ make check
$ make install
我使用的是centos系统
/usr/local/bin
/usr/local/lib,
/usr/local/include 是也系统默认路径之一,所以到这一步就可以使用protobuf了
$ protoc -I=./ --cpp_out=./ test.proto
到你的test.proto文件所在目录使用命令
protoc -I=./ --cpp_out=./ 生成C++版本的协议文件
一切OK的话,你回在当前目录看到.h和.cc文件
希望对正在查看文章的您有所帮助,记得关注、评论、收藏,谢谢您