Clickhouse在Mac OS上的编译、运行及在VSCode中的调试

组合苔藓
• 阅读 1413

系统环境

MacOS Monterey 12.2.1
Intel i9 2.3 GHz 8 Cores
32GB DDR4 RAM
1TB SSD Storage

官方教程地址

https://clickhouse.com/docs/en/development/build-osx

下载代码

配置Github IP加速

如果你没有配置过Github IP,访问Github可能会很慢。

你可以访问以下四个网址,将页面上的IP配置到/etc/hosts里:
https://www.ipaddress.com/site/github.global.ssl.fastly.net#i...
https://www.ipaddress.com/site/github.com#ipinfo
https://www.ipaddress.com/site/raw.githubusercontent.com#ipinfo
https://www.ipaddress.com/site/pkg-containers.githubuserconte...

作为参考,我的hosts配置如下:

# https://www.ipaddress.com/site/github.global.ssl.fastly.net#ipinfo
# 151.101.1.194
# 151.101.65.194
# 151.101.129.194
# 151.101.193.194
151.101.1.194 github.global.ssl.fastly.net

# https://www.ipaddress.com/site/github.com#ipinfo
# 140.82.113.4
140.82.113.4 github.com

# https://www.ipaddress.com/site/raw.githubusercontent.com#ipinfo
# 185.199.108.133
# 185.199.109.133
# 185.199.110.133
# 185.199.111.133
185.199.108.133 githubusercontent.com

# https://www.ipaddress.com/site/pkg-containers.githubusercontent.com#ipinfo
# 185.199.108.154
# 185.199.109.154
# 185.199.110.154
# 185.199.111.154
185.199.108.154 pkg-containers.githubusercontent.com

如果你有自己的代理服务器,你也可以通过proxychains4或其他方式来访问git。

Fork代码并下载

不建议直接下载官方代码,而是自己fork一份到自己的Github账号,这样修改代码会更方便。
访问https://github.com/ClickHouse/ClickHouse即可创建自己的fork。
以从我的代码库clone为例:

git clone https://github.com/paxoscn/ClickHouse.git

环境准备

安装Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
brew update

安装脚本作者捐赠地址:
https://brew.idayer.com/reward/
安装脚本作者点赞地址:
https://github.com/ineo6/homebrew-install
https://gitee.com/ineo6/homebrew-install
Homebrew捐赠地址:
https://github.com/Homebrew/brew#donations

安装工具库

brew install ccache cmake ninja libtool gettext llvm gcc gdb binutils grep findutils

编译代码

cd ClickHouse
mkdir build
export PATH=$(brew --prefix llvm)/bin:$PATH
export CC=$(brew --prefix llvm)/bin/clang
export CXX=$(brew --prefix llvm)/bin/clang++
git submodule update --init
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -S . -B build
cmake --build build

编译可能遇到的问题

Clang版本问题

注意编译器需要使用Homebrew's vanilla Clang。cmake正确的输出开头应为类似“Homebrew clang version 15.0.7”的文字,而不是“Apple clang version ... ”之类。若版本错误请检查是否成功通过brew install安装了必要的工具库,并清空build目录后重试。

缺失cctz/testdata目录

可以从另一目录中找到并拷贝:

cp -r contrib/abseil-cpp/absl/time/internal/cctz/testdata contrib/cctz/
某个头文件缺失错误

当看到某个头文件缺失的错误提示时,请检查contrib目录下是否存在空文件夹,空文件夹可能是因为“git submodule update --init”命令失败导致的。你可以在.git/config里查看缺失的子模块的git地址,并手动clone到contrib目录下。

运行

修改系统最大文件数配置

执行:

ulimit -n

来查看系统最大文件数,若为2560或更小则需要进行配置修改:

sudo vi /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

最后重启系统并查看“ulimit -n”命令返回的系统最大文件数是否已经改变为524288。

启动进程

./build/programs/clickhouse-server --config-file ./programs/server/config.xml

使用客户端进行连接

./build/programs/clickhouse-client

可以执行以下命令来验证服务是否正常:

:) select 1;

SELECT 1

Query id: 3477a16a-894c-4c7b-8290-4874b6f4ed21

┌─1─┐
│ 1 │
└───┘

1 row in set. Elapsed: 0.001 sec. 

VSCode设置

Kit设置

在VSCode中打开Clickhouse目录后,若你没有安装过C++插件,则VSCode会自动提示安装。安装完后,在菜单选择“查看”>“命令面板...”,并输入“CMake: Edit User-Local CMake Kits”来打开文件“~/.local/share/CMakeTools/cmake-tools-kits.json”,将自己的Clang编译器路径加进去:

[
  {
    "name": "Homebrew clang version 15.0.7",
    "compilers": {
      "C": "/usr/local/opt/llvm/bin/clang",
      "CXX": "/usr/local/opt/llvm/bin/clang++"
    }
  }
]

拷贝lldb-mi

若文件“/usr/local/opt/llvm/bin/lldb-mi”不存在,可执行以下命令从~/.vscode中拷贝一份:

cp ~/.vscode/extensions/ms-vscode.cpptools-1.14.4-darwin-x64/debugAdapters/lldb-mi/bin/lldb-mi /usr/local/opt/llvm/bin/

启动配置

在项目目录下编辑文件.vscode/launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "ClickHouse目录/build/programs/clickhouse",
            "args": ["server",  "--config-file=ClickHouse目录/programs/server/config.xml"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "sourceFileMap": { "build/src/": "ClickHouse目录/src/" },
            "setupCommands": [
                {
                    "description": "pretty",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

其中的“ClickHouse目录”是绝对路径。
如果在后续调试断点时VSCode无法跳到正确的源码,并提示“找不到源码 ... SourceRequest not supported”,则可能是sourceFileMap配置有误,请检查路径或尝试去掉该配置。

确认配置选择

保存后,请在下方活动栏确认配置选择是否正确:
调试配置名称:(lldb) Launch
build variant:RelWithDebInfo
active kit:Homebrew clang version 15.0.7

开始调试

在你关心的代码中打一个断点,例如Disks/DiskLocal.cpp的tryReserve处。随后在菜单点击“运行”>“启动调试”开始调试。

点赞
收藏
评论区
推荐文章
blmius blmius
4年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Wesley13 Wesley13
4年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Wesley13 Wesley13
4年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Wesley13 Wesley13
4年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Stella981 Stella981
4年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Wesley13 Wesley13
4年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
4年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Easter79 Easter79
4年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Wesley13 Wesley13
4年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Python进阶者 Python进阶者
2年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
组合苔藓
组合苔藓
Lv1
不知何岁月,得与尔同归?
文章
3
粉丝
0
获赞
0