在mac上用clion编译调试clickhouse流程

1、安装brew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、安装 Compilers, Tools, 及 Libraries

$ brew install cmake ninja libtool gettext

3、下载源码

$ git clone --recursive https://github.com/ClickHouse/ClickHouse.git

4、如果用clion打开clickhouse load不成功,无法正常编译debug,可以试着做以下步骤

​ 1>、brew install llvm

​ 2>、安装完之后配置clion的工具链Toolchain

在mac上用clion编译调试clickhouse流程_第1张图片

​ cmake和make,较新版就行;本人是cmake 3.18.4,make 3.81版本,配置好c 和c++ 编译器(Compiler)刚刚装完的llvm下的clang

​ 3>、到此可以试着去reload clickhouse; Tools -> cmake -> Reset Cache and Reload Project

​ 4>、load过程中的可能会遇到 Cannot find objcopy.

​ 到外层的cmakelist.txt find_program 这一行加上 PATHS “/usr/local/Cellar/llvm/11.0.0/bin”,如下:

​ find_program (OBJCOPY_PATH NAMES “llvm-objcopy” “llvm-objcopy-10” “llvm-objcopy-9” “llvm-objcopy-8” “objcopy” PATHS “/usr/local/Cellar/llvm/11.0.0/bin”)

​ 5>、重新步骤3重新reload,如果再报

CMake Error at contrib/croaring-cmake/CMakeLists.txt:22 (add_library):Cannot find source file:…

​ 这类错误,执行git submodule update --init --recursive 重新拉取相关依赖

​ 6>、到此clickhouse 代码load成功,借助clion可以提升你的阅读代码及调试代码的效率

5、接下来介绍如果编译debug clickhouse

​ 1>、可以选取一个clickhouse稳定版,如:git checkout -b 20.8.2.3 refs/tags/v20.8.2.3-stable

​ 2>、编译步骤如下:

$ cd clickhouse
$ mkdir Debug
$ cd Debug
$ cmake .. -DCMAKE_CXX_COMPILER=`which clang++` -DCMAKE_C_COMPILER=`which clang` -DCMAKE_BUILD_TYPE=Debug
$ ninja 

​ 3>、生成的各种二进制可执行文件在ClickHouse/Debug/programs目录下

​ 4>、在调试之前需要确认你确保系统的maxfiles变量,可以做如下操作

​ (1)创建/Library/LaunchDaemons/limit.maxfiles.plist具有以下内容的文件:




  
    Label
    limit.maxfiles
    ProgramArguments
    
      launchctl
      limit
      maxfiles
      524288
      524288
    
    RunAtLoad
    
    ServiceIPC
    
  

​ (2)执行 sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist

​ (3)重启生效

5>、运行./clickhouse-server (需要两个默认配置文件)放在二进制同级目录就可以了

​ 1、config.xml(把/var/lib 换成非root权限的路径,不然后续attach to process 时会报xpc error connection invalid)




    
        
        trace
        /var/log/clickhouse-server/clickhouse-server.log
        /var/log/clickhouse-server/clickhouse-server.err.log
        1000M
        10
         

        
        

        
        
    

    
        
        
        
        false
        
        false
        
        
        https://[email protected]/5226277
    

     
    8123
    9000
    9004
    
    
    
    
         
            
            /etc/clickhouse-server/server.crt
            /etc/clickhouse-server/server.key
            
            /etc/clickhouse-server/dhparam.pem
            none
            true
            true
            sslv2,sslv3
            true
        

         
            true
            true
            sslv2,sslv3
            true
            
            
                
                RejectCertificateHandler
            
        
    

    
    

    
    9009

    
    

    
    
    
    

    
    
    
    

    
    

    

    4096
    3

    
    100

    
    0

    

    10000

    
    0.9

    
    4194304

    
    0

    
    

    
    8589934592

    
    5368709120


    
    /var/lib/clickhouse/

    
    /var/lib/clickhouse/tmp/

    
    

    
    /var/lib/clickhouse/user_files/

    
    /var/lib/clickhouse/access/

    
    
        
    

    
    users.xml

    
    default

    
    

    
    

    
    default

    
    

    
    

    
    true

    
    
        
        
            
                
                
                
                
                
                    localhost
                    9000
                    
                    
                
            
        
        
             
                 
                     localhost
                     9000
                 
             
             
                 
                     localhost
                     9000
                 
             
        
        
            
                
                    127.0.0.1
                    9000
                
            
            
                
                    127.0.0.2
                    9000
                
            
        
        
            
                
                    localhost
                    9440
                    1
                
            
        
        
            
                
                    localhost
                    9000
                
            
            
                
                    localhost
                    1
                
            
        
    

    
    
        

        
    

    

    



    



    
    3600


    
    3600

    
    60

    
    
    

    
    
    

    
    
        
        system
        query_log
toYYYYMM(event_date) 7500
system trace_log
toYYYYMM(event_date) 7500
system query_thread_log
toYYYYMM(event_date) 7500
system metric_log
7500 1000
system asynchronous_metric_log
60000
system crash_log
1000
*_dictionary.xml /clickhouse/task_queue/ddl click_cost any 0 3600 86400 60 max 0 60 3600 300 86400 3600 /var/lib/clickhouse/format_schemas/ :: 0.0.0.0 1

2、user.xml



    
    
        
        
            
            10000000000

            
            0

            
            random
        

        
        
            1
        
    

    
    
        
        
            
            

            
            
                ::/0
            

            
            default

            
            default

            
            
        
    

    
    
        
        
            
            
                
                3600

                
                0
                0
                0
                0
                0
            
        
    

​ 6>、clickhouse server就可以在本机跑起来,./clickhouse-client 可以去测试一下

​ 7>、clion debug clickhouse 可以通过Run -> Attach to Process… 选择clickhouse 这时就可以本地debug了

你可能感兴趣的:(数据库,mac,调试器)