本文基于 CentOS7 (3.10.0-693.el7.x86_64 GNU/Linux)
本文基于 ClickHouse-v23.3.2.37-lts
准备工作
- 需要 cmake 3.20 or newer
- 需要 clang 15.0 or newer
- 需要 lld 15 or newer
- 需要 Ninja
- 需要 Yasm
- 需要 Gawk
- 需要 arm 交叉编译环境
安装必要工具
# add extra repos yum -y install epel-release centos-release-scl centos-release-scl-rh
# installing needed libs yum -y install readline-devel unixODBC-devel openssl-devel libicu-devel libtool-ltdl-devel openssl-devel scl-utils
# installing build tools yum -y install git devtoolset-9 tar wget rh-python36 yum -y install http://repo.okay.com.mx/centos/7/x86_64/release/okay-release-1-5.el7.noarch.rpm yum -y install ninja-build yasm gawk yum -y update binutils
|
安装 cmake
安装步骤如下:
cd /opt wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz tar xzf cmake-3.26.3-linux-x86_64.tar.gz ln -svf /opt/cmake-3.26.3-linux-x86_64/bin/* /usr/bin/ # 查看版本,验证是否安装成功 cmake --version
|
安装 clang 与 lld
先下载好安装包
# 你想要安装的目录 export basedir=/opt
cd "$basedir" # 此部分最好科学上网,否则速度感人 # git config --global http.proxy socks5://127.0.0.1:7890 # git config --global https.proxy socks5://127.0.0.1:7890 git clone https://github.com/llvm/llvm-project.git git tag git checkout -b remotes/origin/release/16.x git checkout llvmorg-16.0.3
|
执行编译安装 clang 与 lld 步骤
export basedir=/opt cd "$basedir"
export THREADS=$(grep -c ^processor /proc/cpuinfo) mkdir $basedir/clang-build-16.0.3 && cd $basedir/clang-build-16.0.3 scl enable devtoolset-9 rh-python36 'cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" -G Ninja ../llvm-project/llvm' ninja -j $THREADS && ninja install
|
此过程会耗费大量时间,请耐心等待。
编译 Clickhouse
下载 ClickHouse 源码:
cd /opt git clone https://github.com/ClickHouse/ClickHouse.git
|
安装交叉编译环,前往 arm developer 官网 下载交叉编译的环境。下载名为 x86_64 Linux hosted cross toolchains
的资源包。
cd /opt wget https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz?rev=6750d007ffbf4134b30ea58ea5bf5223&hash=0F1CE8273B8A30129CA04BD61FFB547D mkdir -p /opt/ClickHouse/build-aarch64/cmake/toolchain/linux-aarch64 tar xJf arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz -C /opt/ClickHouse/build-aarch64/cmake/toolchain/linux-aarch64/ --strip-components=1
|
开始编译操作
export codedir=/opt/ClickHouse cd $codedir git tag # 好像切换了分支没生效,编译的版本为23.3.2.1 git checkout -b v23.3.2.37-lts git submodule sync # 此部分最好科学上网,否则速度感人 # git config --global http.proxy socks5://127.0.0.1:7890 # git config --global https.proxy socks5://127.0.0.1:7890 git submodule update --init --recursive
mkdir build-arm64
scl enable devtoolset-9 rh-python36 'CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++ cmake . -Bbuild-arm64 -DCOMPILER_CACHE=disabled -DCMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/ninja -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-aarch64.cmake'
# THREADS根据CPU个数自行进行设置 export THREADS=$(grep -c ^processor /proc/cpuinfo) ninja -j $THREADS clickhouse -C build-arm64
|
其中 CC 为 clang 的安装目录,CXX 为 clang++ 的安装目录,需要根据自己的实际情况进行替换。
此过程需要较长时间,请耐心等待。
编译完毕之后,可执行文件将会生成 /opt/ClickHouse/build-arm64/programs/clickhouse
可执行的二进制文件。可以执行如下命令来查看
Use one of the following commands: clickhouse local [args] clickhouse client [args] clickhouse benchmark [args] clickhouse server [args] clickhouse extract-from-config [args] clickhouse compressor [args] clickhouse format [args] clickhouse copier [args] clickhouse obfuscator [args] clickhouse git-import [args] clickhouse keeper [args] clickhouse keeper-converter [args] clickhouse install [args] clickhouse start [args] clickhouse stop [args] clickhouse status [args] clickhouse restart [args] clickhouse static-files-disk-uploader [args] clickhouse su [args] clickhouse hash-binary [args] clickhouse disks [args]
|
启动 server
使用 ./clickhouse server
来启动服务
Processing configuration file 'config.xml'. There is no file 'config.xml', will use embedded config. 2023.05.10 15:30:34.434959 [ 4253 ] {} <Information> SentryWriter: Sending crash reports is disabled 2023.05.10 15:30:34.446996 [ 4253 ] {} <Trace> Pipe: Pipe capacity is 1.00 MiB 2023.05.10 15:30:34.813067 [ 4253 ] {} <Information> Application: Starting ClickHouse 23.3.2.1 (revision: 54472, git hash: 1b144bcd101ddf23466ba67e4fa0fd27afb9c060, build id: <unknown>), PID 4253 2023.05.10 15:30:34.813124 [ 4253 ] {} <Information> Application: starting up
|
启动 client
使用 ./clickhouse client
来连接 server
ClickHouse client version 23.3.2.1. Connecting to localhost:9000 as user default. Connected to ClickHouse server version 23.3.2 revision 54462.
Warnings: * Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
localhost :)
|