【Hbase】容器编译hbase2.2.6

目标想用腾讯开源的TencentKona11编译hbase2.2.6

由于TencentKona11目前不支持Mac OS,服务器环境又不支持外网访问,所以通过容器环境在mac上编译hbase2.2.6

1. 容器环境准备

  • Dockerfile 定义容器,负责安装hbase编译需要的maven,jdk等
  • start-build-env.sh  负责启动容器,并将目录与容器目录映射
  • 下载要编译的hbase源

目录关系

# 把他们放到一个目录就好
$ ll
total 16
-rw-r--r--   1 xxx  staff   3.5K  7 14 10:20 Dockerfile
drwxr-xr-x@ 48 xxx  staff   1.5K  7 14 11:02 hbase-rel-2.2.6
-rwxr-xr-x   1 xxx  staff   3.6K  7 14 11:00 start-build-env.sh
# 然后通过脚本会帮我记启动容器,并进入容器,就可以build代码了
$ ./start-build-env.sh
xxx@7d5dc0954351:~/hbase$ mvn clean package -DskipTests -Dhadoop-two.version=2.9.2 assembly:single

1.1 Dockerfile

注意事项:

  • TENCENTKONA11_SHA256 需要通过命令获取再替换到Dockerfile中
# mac sha512sum需要安装
$ brew install coreutils
$ sha256sum TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz
d8beea1b580673ede0cd70a9da5337f1b1da6a385276b0bab621552536c956e5  TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz
  • Dockerfile中maven和jdk版本都可以根据个人需要替换

Dockerfile

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:18.04 AS base_image
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN DEBIAN_FRONTEND=noninteractive apt-get -qq update && \
  DEBIAN_FRONTEND=noninteractive apt-get -qq install --no-install-recommends -y \
    ca-certificates=20180409 \
    curl='7.58.0-*' \
    git='1:2.17.1-*' \
    locales='2.27-*' \
    && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8

FROM base_image AS MAVEN_DOWNLOAD_IMAGE
ENV MAVEN_VERSION='3.6.3'
ENV MAVEN_URL "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
ENV MAVEN_SHA512 'c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0'
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl --location --fail --silent --show-error --output /tmp/maven.tar.gz "${MAVEN_URL}" && \
  echo "${MAVEN_SHA512} */tmp/maven.tar.gz" | sha512sum -c -

FROM base_image AS TENCENTKONA11_DOWNLOAD_IMAGE
ENV TENCENTKONA11_URL 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.11/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz'
ENV TENCENTKONA11_SHA256 'd8beea1b580673ede0cd70a9da5337f1b1da6a385276b0bab621552536c956e5'
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl --location --fail --silent --show-error --output /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz "${TENCENTKONA11_URL}" && \
  echo "${TENCENTKONA11_SHA256} */tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz" | sha256sum -c -

FROM base_image
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# hadolint ignore=DL3010
COPY --from=MAVEN_DOWNLOAD_IMAGE /tmp/maven.tar.gz /tmp/maven.tar.gz
RUN tar xzf /tmp/maven.tar.gz -C /opt && \
  ln -s "/opt/$(dirname "$(tar -tf /tmp/maven.tar.gz | head -n1)")" /opt/maven && \
  rm /tmp/maven.tar.gz

# hadolint ignore=DL3010
COPY --from=TENCENTKONA11_DOWNLOAD_IMAGE /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz
RUN mkdir -p /usr/lib/jvm && \
  tar xzf /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz -C /usr/lib/jvm && \
  ln -s "/usr/lib/jvm/$(basename "$(tar -tf /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz | head -n1)")" /usr/lib/jvm/jdk-11-tencentkona && \
  ln -s /usr/lib/jvm/jdk-11-tencentkona /usr/lib/jvm/jdk-11 && \
  rm /tmp/TencentKona-11.0.11.b1-jdk_linux-x86_64.tar.gz

ENV MAVEN_HOME '/opt/maven'
ENV JAVA_HOME '/usr/lib/jvm/jdk-11'
ENV PATH '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
ENV PATH "${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${PATH}"

1.2 start-build-env.sh

注意事项:

  • 最后docker run时注意挂载目录是否正确
    如本机的hbase-rel-2.2.6映射到容器hbase目录,-v "/hbase

start-build-env.sh

#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e               # exit on error

cd "$(dirname "$0")" # connect to root

DOCKER_DIR=${PWD}
DOCKER_FILE="${DOCKER_DIR}/Dockerfile"

CPU_ARCH=$(echo "$MACHTYPE" | cut -d- -f1)
if [ "$CPU_ARCH" = "aarch64" ]; then
  DOCKER_FILE="${DOCKER_DIR}/Dockerfile_aarch64"
fi

docker build -t hbase-build -f $DOCKER_FILE $DOCKER_DIR

USER_NAME=${SUDO_USER:=$USER}
USER_ID=$(id -u "${USER_NAME}")

if [ "$(uname -s)" = "Darwin" ]; then
  GROUP_ID=100
fi

if [ "$(uname -s)" = "Linux" ]; then
  GROUP_ID=$(id -g "${USER_NAME}")
  # man docker-run
  # When using SELinux, mounted directories may not be accessible
  # to the container. To work around this, with Docker prior to 1.7
  # one needs to run the "chcon -Rt svirt_sandbox_file_t" command on
  # the directories. With Docker 1.7 and later the z mount option
  # does this automatically.
  if command -v selinuxenabled >/dev/null && selinuxenabled; then
    DCKR_VER=$(docker -v|
    awk '$1 == "Docker" && $2 == "version" {split($3,ver,".");print ver[1]"."ver[2]}')
    DCKR_MAJ=${DCKR_VER%.*}
    DCKR_MIN=${DCKR_VER#*.}
    if [ "${DCKR_MAJ}" -eq 1 ] && [ "${DCKR_MIN}" -ge 7 ] ||
        [ "${DCKR_MAJ}" -gt 1 ]; then
      V_OPTS=:z
    else
      for d in "${PWD}" "${HOME}/.m2"; do
        ctx=$(stat --printf='%C' "$d"|cut -d':' -f3)
        if [ "$ctx" != svirt_sandbox_file_t ] && [ "$ctx" != container_file_t ]; then
          printf 'INFO: SELinux is enabled.\n'
          printf '\tMounted %s may not be accessible to the container.\n' "$d"
          printf 'INFO: If so, on the host, run the following command:\n'
          printf '\t# chcon -Rt svirt_sandbox_file_t %s\n' "$d"
        fi
      done
    fi
  fi
fi

# Set the home directory in the Docker container.
DOCKER_HOME_DIR=${DOCKER_HOME_DIR:-/home/${USER_NAME}}

docker build -t "hbase-build-${USER_ID}" - <<UserSpecificDocker
FROM hbase-build
RUN rm -f /var/log/faillog /var/log/lastlog
RUN groupadd --non-unique -g ${GROUP_ID} ${USER_NAME}
RUN useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME} -d "${DOCKER_HOME_DIR}"
RUN mkdir -p "/etc/sudoers.d/"
RUN echo "${USER_NAME} ALL=NOPASSWD: ALL" > "/etc/sudoers.d/hbase-build-${USER_ID}"
ENV HOME "${DOCKER_HOME_DIR}"
UserSpecificDocker

#If this env varible is empty, docker will be started
# in non interactive mode
DOCKER_INTERACTIVE_RUN=${DOCKER_INTERACTIVE_RUN-"-i -t"}

# By mapping the .m2 directory you can do an mvn install from
# within the container and use the result on your normal
# system.  And this also is a significant speedup in subsequent
# builds because the dependencies are downloaded only once.
docker run --rm=true $DOCKER_INTERACTIVE_RUN \
  -v "${PWD}/hbase-rel-2.2.6:${DOCKER_HOME_DIR}/hbase${V_OPTS:-}" \
  -w "${DOCKER_HOME_DIR}/hbase" \
  -v "${HOME}/.m2:${DOCKER_HOME_DIR}/.m2${V_OPTS:-}" \
  -v "${HOME}/.gnupg:${DOCKER_HOME_DIR}/.gnupg${V_OPTS:-}" \
  -u "${USER_ID}" \
  "hbase-build-${USER_ID}" "$@"

2. 编译

2.1 编译前准备

pom.xml

<!--1.8改成11-->
<!--<compileSource>11</compileSource>-->

hbase-protocol-shaded/pom.xml

hbase-protocol/pom.xml

<dependencies>
   <dependency>
       <groupId>javax.annotation</groupId>
       <artifactId>javax.annotation-api</artifactId>
       <version>1.3.1</version>
    </dependency>
</dependencies>

hbase-it/pom.xml

<dependencies>
   <dependency>
      <groupId>jakarta.xml.ws</groupId>
      <artifactId>jakarta.xml.ws-api</artifactId>
      <version>2.3.3</version>
    </dependency>
</dependencies>

2.2 编译命令

# 编译命令
$ mvn clean package -DskipTests -Dhadoop-two.version=2.9.2 assembly:single
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Apache HBase 2.2.6:
[INFO]
[INFO] Apache HBase ....................................... SUCCESS [ 14.671 s]
[INFO] Apache HBase - Checkstyle .......................... SUCCESS [  4.792 s]
[INFO] Apache HBase - Annotations ......................... SUCCESS [  5.352 s]
[INFO] Apache HBase - Build Configuration ................. SUCCESS [  0.713 s]
[INFO] Apache HBase - Shaded Protocol ..................... SUCCESS [01:42 min]
[INFO] Apache HBase - Common .............................. SUCCESS [01:09 min]
[INFO] Apache HBase - Metrics API ......................... SUCCESS [ 27.666 s]
[INFO] Apache HBase - Hadoop Compatibility ................ SUCCESS [ 27.896 s]
[INFO] Apache HBase - Metrics Implementation .............. SUCCESS [ 26.277 s]
[INFO] Apache HBase - Hadoop Two Compatibility ............ SUCCESS [ 34.053 s]
[INFO] Apache HBase - Protocol ............................ SUCCESS [ 37.792 s]
[INFO] Apache HBase - Client .............................. SUCCESS [01:15 min]
[INFO] Apache HBase - Zookeeper ........................... SUCCESS [ 43.374 s]
[INFO] Apache HBase - Replication ......................... SUCCESS [ 35.344 s]
[INFO] Apache HBase - Resource Bundle ..................... SUCCESS [  1.402 s]
[INFO] Apache HBase - HTTP ................................ SUCCESS [01:14 min]
[INFO] Apache HBase - Procedure ........................... SUCCESS [ 41.548 s]
[INFO] Apache HBase - Server .............................. SUCCESS [05:16 min]
[INFO] Apache HBase - MapReduce ........................... SUCCESS [01:27 min]
[INFO] Apache HBase - Testing Util ........................ SUCCESS [ 18.120 s]
[INFO] Apache HBase - Thrift .............................. SUCCESS [01:57 min]
[INFO] Apache HBase - RSGroup ............................. SUCCESS [01:33 min]
[INFO] Apache HBase - Shell ............................... SUCCESS [01:31 min]
[INFO] Apache HBase - Coprocessor Endpoint ................ SUCCESS [01:35 min]
[INFO] Apache HBase - Integration Tests ................... SUCCESS [02:08 min]
[INFO] Apache HBase - Rest ................................ SUCCESS [01:37 min]
[INFO] Apache HBase - Examples ............................ SUCCESS [01:20 min]
[INFO] Apache HBase - Shaded .............................. SUCCESS [  1.249 s]
[INFO] Apache HBase - Shaded - Client (with Hadoop bundled) SUCCESS [ 44.090 s]
[INFO] Apache HBase - Shaded - Client ..................... SUCCESS [ 24.783 s]
[INFO] Apache HBase - Shaded - MapReduce .................. SUCCESS [ 30.958 s]
[INFO] Apache HBase - External Block Cache ................ SUCCESS [01:03 min]
[INFO] Apache HBase - HBTop ............................... SUCCESS [ 16.704 s]
[INFO] Apache HBase - Assembly ............................ SUCCESS [17:27 min]
[INFO] Apache HBase - Shaded - Testing Util ............... SUCCESS [01:44 min]
[INFO] Apache HBase - Shaded - Testing Util Tester ........ SUCCESS [ 11.492 s]
[INFO] Apache HBase Shaded Packaging Invariants ........... SUCCESS [  6.089 s]
[INFO] Apache HBase Shaded Packaging Invariants (with Hadoop bundled) SUCCESS [  3.188 s]
[INFO] Apache HBase - Archetypes .......................... SUCCESS [  0.221 s]
[INFO] Apache HBase - Exemplar for hbase-client archetype . SUCCESS [ 12.394 s]
[INFO] Apache HBase - Exemplar for hbase-shaded-client archetype SUCCESS [ 12.485 s]
[INFO] Apache HBase - Archetype builder ................... SUCCESS [  4.008 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  52:17 min
[INFO] Finished at: 2021-07-19T07:51:29Z
[INFO] ------------------------------------------------------------------------

2.3 编译完成

$ ll hbase-rel-2.2.6/hbase-assembly/target
total 333248
-rw-r--r--    1 xxx  staff   539K  7 14 11:58 NOTICE.aggregate
drwxr-xr-x    2 xxx  staff    64B  7 14 11:58 archive-tmp
drwxr-xr-x  199 xxx  staff   6.2K  7 14 11:58 dependency
drwxr-xr-x  199 xxx  staff   6.2K  7 14 11:58 dependency-maven-plugin-markers
-rw-r--r--    1 xxx  staff    33M  7 14 11:59 hbase-2.2.6-bin.tar.gz
-rw-r--r--    1 xxx  staff   122M  7 14 12:02 hbase-2.2.6-client-bin.tar.gz
drwxr-xr-x    3 xxx  staff    96B  7 14 11:58 maven-shared-archive-resources
-rw-r--r--    1 xxx  staff    95K  7 14 11:58 supplemental-models.xml

3. 遇到的问题及解决办法

3.1 javax.annotation does not exist

hbase-protocol-shaded/pom.xml

hbase-protocol/pom.xml

<dependencies>
   <dependency>
       <groupId>javax.annotation</groupId>
       <artifactId>javax.annotation-api</artifactId>
       <version>1.3.1</version>
    </dependency>
</dependencies>

3.2 javax.xml.ws.http not exist

hbase-it/pom.xml

<dependencies>
   <dependency>
      <groupId>jakarta.xml.ws</groupId>
      <artifactId>jakarta.xml.ws-api</artifactId>
      <version>2.3.3</version>
    </dependency>
</dependencies>
posted @ 2022-03-06 11:09  大梦想家  阅读(248)  评论(0)    收藏  举报