官網地址:https://clickhouse.com/docs/en/development/build-osx/
構建應該適用於基於x86_64(Intel)和arm64(Apple Silicon)的macOS 10.15(Catalina)及更高版本,並使用Homebrew的Clang。
始終建議使用 Clang
編譯器。
可以使用 Xcode 的 AppleClang
或 gcc
,但強烈建議不要這樣做。
安裝 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安裝 Xcode and Command Line Tools
安裝最新的Xcode來自應用商店。
至少打開一次以接受最終用戶許可協議並自動安裝所需組件。
然后,確保在系統中安裝並選擇了最新的命令行工具:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
重新啟動
安裝 所需的編譯器、工具和庫
brew update
brew install cmake ninja libtool gettext llvm gcc binutils
拉取 ClickHouse 源碼
git clone --recursive https://github.com/ClickHouse/ClickHouse.git
或者使用代理
git clone --recursive https://hub.fastgit.org/ClickHouse/ClickHouse.git
構建 ClickHouse
要使用Homebrew的Clang編譯器構建:
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_BUILD_TYPE=RelWithDebInfo ..
cmake --build . --config RelWithDebInfo
cd ..
要使用Xcode的本機AppleClang編譯器生成(強烈建議不要使用此選項;請使用上面的選項):
cd ClickHouse
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake --build . --config RelWithDebInfo
cd ..
使用Homebrew的GCC編譯器構建(絕對不推薦使用此選項,我想知道我們為什么會有此選項):
cd ClickHouse
rm -rf build
mkdir build
cd build
cmake -DCMAKE_C_COMPILER=$(brew --prefix gcc)/bin/gcc-11 -DCMAKE_CXX_COMPILER=$(brew --prefix gcc)/bin/g++-11 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake --build . --config RelWithDebInfo
cd ..
警告
如果要運行clickhouse server
,請確保增加系統的maxfiles變量。
注意, 可能需要用 sudo
為此,請使用以下內容創建/Library/LaunchDaemons/limit.maxfiles.plist
文件:
sudo vim /Library/LaunchDaemons/limit.maxfiles.plistk
<?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
命令。
運行 ClickHouse Server
cd ClickHouse
./build/programs/clickhouse-server --config-file ./programs/server/config.xml