当前最新版本:22.3.3.2
编译日期:2022-04-19
编译环境:MacBookPro M1
官方编译安装链接:
https://clickhouse.com/docs/en/getting-started/install/
https://clickhouse.com/docs/en/development/build-osx/
1. 安装准备
# homebrew安装略
# xcode和Command Line Tools安装略
# 安装必须的编译器、编译工具及库
brew update
brew install cmake ninja libtool gettext llvm gcc binutils
2. 下载代码
git clone --recursive git@github.com:ClickHouse/ClickHouse.git
# ...alternatively, you can use https://github.com/ClickHouse/ClickHouse.git as the repo URL.
cd Clickhouse
git checkout
#或者下载好自己经编译版本
cd ClickHouse-22.3.3.44-lts
3. 开始编译
$ cd ClickHouse
$ rm -rf build
$ mkdir build
$ cd build
$ cmake -DCMAKE_C_COMPILER=$(brew --prefix llvm)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ -DCMAKE_AR=$(brew --prefix llvm)/bin/llvm-ar -DCMAKE_RANLIB=$(brew --prefix llvm)/bin/llvm-ranlib -DOBJCOPY_PATH=$(brew --prefix llvm)/bin/llvm-objcopy -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
日志...略
-- Will build ClickHouse 22.3.3.2 revision 54460
INFONot generating debugger info for ClickHouse functions
-- StorageFileLog is only supported on Linux
-- ClickHouse modes:
-- Server mode: ON
-- Client mode: ON
-- Local mode: ON
-- Benchmark mode: ON
-- Extract from config mode: ON
-- Compressor mode: ON
-- Copier mode: ON
-- Format mode: ON
-- Obfuscator mode: ON
-- ODBC bridge mode: OFF
-- Library bridge mode: ON
-- ClickHouse install: ON
-- ClickHouse git-import: ON
-- ClickHouse keeper mode: ON
-- ClickHouse keeper-converter mode: ON
-- bash_completion will be written to /usr/local/share/bash-completion/completions
-- Target check already exists
-- /Users/momo/studySpace/opensource/clone/ClickHouse/utils: Have 2677 megabytes of memory.
Limiting concurrent linkers jobs to 1 and compiler jobs to OFF (system has 8 logical cores)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/momo/studySpace/opensource/clone/ClickHouse/build
$ cmake --build . --config RelWithDebInfo
# The resulting binary will be created at: ./programs/clickhouse
..略
[7716/7716] cd /Users/momo/studySpace/opensource/clone/ClickHouse/build/programs && /opt/homebrew/Cellar/cmake/3.23.0/bin/cmake -E create_symlink clickhouse clickhouse-client
如果报如下错误:
CMake Error at CMakeLists.txt:67 (message):
Submodules are not initialized. Run
git submodule update --init --recursive解决办法:按照提示执行命令
git submodule update --init --recursive
4. 修改机器配置
修改系统 maxfiles配置
sudo vim /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>524288</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
添加权限
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
验证文件是否正确
plutil /Library/LaunchDaemons/limit.maxfiles.plist
重新加载配置(或重启)
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
检查配置是否生效
ulimit -n 或者 launchctl limit maxfiles
5. 运行Clickhouse
启动server
./build/programs/clickhouse-server --config-file ./programs/server/config.xml
启动client
./build/programs/clickhouse-client
数据库目录就在${clickhouse_src}/data目录下