ClickHouse编译安装
测试环境:Redhat 7
源码:clickhouse-master(2020.09.27)
一、系统
- snippet.bash
[root@bogon ~]# adduser clickhouse [root@bogon ~]# passwd clickhouse [root@bogon ~]# vim /etc/sudoers # 添加行 clickhouse ALL=(ALL) NOPASSWD: ALL
二、源码
- snippet.bash
[clickhouse@bogon clickhouse-master]$ git clone --recursive https://github.com/ClickHouse/ClickHouse.git
网络条件不好的情况下,建议使用以下分步骤方法:
- snippet.bash
[clickhouse@bogon clickhouse-master]$ git clone https://github.com/ClickHouse/ClickHouse.git [clickhouse@bogon clickhouse-master]$ cd ClickHouse/ # 如果以下步骤失败,则删除contrib目录重试该步骤: [clickhouse@bogon ClickHouse]$ git submodule update --init --recursive
三、准备编译
创建build目录
- snippet.bash
[clickhouse@bogon ClickHouse]$ mkdir build [clickhouse@bogon ClickHouse]$ cd build
之后,如果编译失败需要重试时,直接清空build目录即可。
升级cmake
- snippet.bash
[clickhouse@bogon build]$ cmake ../ CMake Error at CMakeLists.txt:1 (cmake_minimum_required): CMake 3.3 or higher is required. You are running version 2.8.12.2 -- Configuring incomplete, errors occurred! [clickhouse@bogon build]$ cmake --version cmake version 2.8.12.2
系统自带的cmake版本无法满足要求。需要升级。
- snippet.bash
[clickhouse@bogon build]$ sudo yum install cmake3.x86_64 [clickhouse@bogon build]$ vim ~/.bashrc # 添加以下行: alias cmake='cmake3' [clickhouse@bogon build]$ source ~/.bashrc [clickhouse@bogon build]$ cmake --version cmake3 version 3.17.3
升级gcc
安装ninja
这里安装的ninja版本可能不满足编译要求,如果在cmake阶段报告以下warning,建议手动实际ninja到1.8以上版本:
- snippet.bash
CMake Warning (dev): The detected version of Ninja: 1.7.2 is less than the version of Ninja required by CMake for adding restat dependencies to the build.ninja manifest regeneration target: 1.8
四、编译
默认编译release版本:
- snippet.bash
[clickhouse@bogon build]$ cmake ../ [clickhouse@bogon build]$ ninja -j2
如果需要编译debug版本,则:
- snippet.bash
[clickhouse@bogon build]$ cmake ../ -DCMAKE_BUILD_TYPE=Debug [clickhouse@bogon build]$ ninja -j2
注:并行编译有时会发生莫名其妙的错误,此时可以使用串行继续编译“ ninja -j1 ”。
cmake报告缺少文件
…… CMake Error at contrib/CMakeLists.txt:21 (add_subdirectory): add_subdirectory given source "consistent-hashing-sumbur" which is not an existing directory.
使用以上git clone方法,获得的源码contrib目录会缺省一些文件和子目录,解决方法是:
手动从GitHub下载一份同版本的.zip源码压缩包,解压后,从其中拷贝缺少的文件和子目录:
- snippet.bash
[clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/CMakeLists.txt contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/*-cmake contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/consistent-hashing-sumbur contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/consistent-hashing contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/croaring contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/FastMemcpy contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/libdivide contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/libmetrohash contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/murmurhash contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/re2_st contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/cityhash102 contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/libfarmhash contrib/ [clickhouse@bogon ClickHouse]$ cp -r ../ClickHouse-master-zip/contrib/libbtrie contrib/
五、问题
问题1
编译阶段报错:
- snippet.bash
contrib/arrow-cmake/thrift/config.h:1:1: error: expected unqualified-id before ‘.’ token
解决方法:
- snippet.bash
cd contrib/arrow-cmake/build/cmake ln -s ../../../thrift/build/cmake/config.h.in config.h.in -f
问题2
编译阶段报错:
- snippet.bash
[11/16] Building CXX object utils/db-generator/CMakeFiles/query_db_generator.dir/query_db_generator.cpp.o …… ../utils/db-generator/query_db_generator.cpp:117:33: error: wrong number of template arguments (2, should be 4) 117 | std::map<ColumnType, std::string> type_definition =
解决方法:
在报错的cpp文件中 include <map>
- snippet.cpp
[clickhouse@bogon build]$ vim ../utils/db-generator/query_db_generator.cpp // 增加include #include <map>
六、调试
编译成功后,可执行查询在build/programs/目录下,将该目录加入PATH。
- snippet.bash
[clickhouse@bogon ~]$ vim ~/.bash_profile PATH=~/clickhouse-master/ClickHouse/build/programs/:$PATH:$HOME/.local/bin:$HOME/bin
运行server并使用client连接:
- snippet.bash
[clickhouse@bogon ~]$ clickhouse-server [clickhouse@bogon ~]$ clickhouse-client ClickHouse client version 20.10.1.1. Connecting to localhost:9000 as user default. Connected to ClickHouse server version 20.10.1 revision 54441. bogon :) show databases; SHOW DATABASES ┌─name───────────────────────────┐ │ _temporary_and_external_tables │ │ default │ │ system │ └────────────────────────────────┘ 3 rows in set. Elapsed: 0.011 sec.
七、参考
打赏作者以资鼓励: