centos7下ClickHouse编译记录

一、准备工作 (双cpu双核心,8G内存,centos7)

1.检查是否支持SSE4.2

grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

2. 安装依赖项
 yum install git clang 		#如果直接上github下载zip,可以不用安装git
yum install libicu-devel
yum install readline-devel
yum install mysql-devel
yum install openssl-devel 
yum install unixODBC_devel

3. 编译安装gcc6 (因为clickhouse使用了c++11相关特性,所以需要安装高版本gcc,默认yum源的gcc版本太低)

wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-6.2.0/gcc-6.2.0.tar.bz2       # (也可以自己换个其他地址下载,这个不快)
tar -jxvf gcc-6.2.0.tar.bz2
cd gcc-6.2.0
./contrib/download_prerequisites
cd ..
mkdir build
cd build
../gcc-6.2.0/configure --enable-languages=c,c++   --disable-multilib  #disable-multilib表示编译64位
export THREADS=$(grep -c ^processor /proc/cpuinfo)  #获取cpu核心数
make -j $THREADS   #漫长的等待
make install
hash gcc g++  #这一步改变版本,这样就能使用刚刚安装的gcc6了
gcc --version  #即可看到最新版本
ln -s /usr/local/bin/gcc /usr/local/bin/gcc-6
ln -s /usr/local/bin/g++ /usr/local/bin/g++-6
ln -s /usr/local/bin/gcc /usr/local/bin/cc
ln -s /usr/local/bin/g++ /usr/local/bin/c++   

4. 修改动态链接库

虽然安装了新版gcc,但是某些程序编译时会报以下错误:

libstdc++.so.6: version `GLIBCXX_3.4.21' not found error  (这是在编译安装cmake3时出现,可能也是文章中遇到的其中一个编译问题的原因)

这是因为虽然安装了最新版本gcc,但是链接库还是旧的,解决办法是删除原有链接库,并创建软连接到新版gcc对应的链接库

rm -f /usr/lib64/libstdc++.so.6
ln -s /usr/local/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6


5.编译安装cmake3 

cmake官网下载cmake3.9 ,按官方文档说明编译(./bootstrap ;  gmake  ;  make install)


二、 开始正式编译

1. 获取源码 (本文使用的是主干版本)

git clone  [email protected]:yandex/ClickHouse.git

####git clone -b stable --recursive --depth=10 [email protected]:yandex/ClickHouse.git ##这是clickhouse官网上推荐的稳定版本,但是稳定版本没编译通过,查看github上编译相关的issue,只有一个,其中提到使用主干版本试试,于是就换主干版本。虽然编译也有出现问题,但是主干版本最终编译通过OK了。


2. 开始编译

cd ClickHouse
mkdir build
cd build
cmake .. #这一步出现错误,问题请看文章中,三、遇到的问题 cmake问题
make -j $THREADS  #这一步出现的错误,请看 三、遇到的问题 make问题
make install
终于编译通过,好开心

3. 启动

首先将源码包中的配置文件拷贝出来,放置到一个目录,我放置在/etc/clickhose-server/目录下(目录不存在就创建一个)

cd ../ClickHouse/dbms/src/Server/
mkdir /etc/clickhouse-server
cp config.xml /etc/clickhouse-server/
cp user.xml /etc/clickhouse-server/
clickhouse-server --config-file=/etc/clickhouse-server/config.xml #启动服务
clickhouse-client -m  #启动客户端,-m表示开启多行输入,最后以分号表示语句结束,和mysql客户端类似(可以新开一个shell,或者服务端启动时使用nohup启动)


三、遇到的问题

     1. cmake问题

1) CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LTDL_LIB
linked by target "dbms" in directory /root/clickHouse/ClickHouse/dbms

        ===> 原因: 缺少 libtool-ltdl-devel包   

        ===> 解决: yum install libtool-ltdl-devel


2. make问题

1) 官方推荐的稳定版本编译时,出现:

In file included from /root/clickHouse/ClickHouse/dbms/src/Dictionaries/DictionarySourceFactory.cpp:6:0:
/root/clickHouse/ClickHouse/dbms/src/Dictionaries/MySQLDictionarySource.h:7:38: fatal error: mysqlxx/PoolWithFailover.h: No such file or directory
#include
^
compilation terminated.
===> 原因:未知,这个依赖项是libs/libmysqlxx下的一个头文件,可能是编译依赖配置错误,CMakeList可能需要调整
===> 解决: 放弃使用官方推荐稳定版本,使用主干版本编译

2) error: conversion from ‘HashTable, StringRefHash, HashTableGrower<>, Allocator >::iterator’ to non-scalar type ‘HashTable, StringRefHash, HashTableGrower<>, Allocator >::const_iterator’ requested

for (RefsHashMap::const_iterator it = set.begin(); i < elems_show && it != set.end(); ++it, ++i)

===>原因:对应文件的代码第217行和244行报错,原因是类型转换错误

        ===>解决:将源码中对应行的const_iterator换成iterator


3) collect2: error: ld returned 1 exit status  (DataStreams/unionn_stream2.cpp)

原因:查看 CMakeFiles/CMakeError.log日志,发现是因为无法引用pthread_create函数引起。这个问题不止这一个cpp有。
解决:最后是将虚拟机的cpu换成双cpu,双核心解决(原有的配置是单核)

4) 编译过程中磁盘空间不足

要编译源码,请预留20G空间
若和我一样是VMware下的centos7虚拟机,并且磁盘空间太小,可以 参考这个链接来拓容。

5) /usr/local/bin/cmake: error while loading shared libraries: libz.so.1: failed to map segment from shared object: Cannot allocate memory

virtual memory exhausted: Cannot allocate memory

c++: internal compiler error: Killed (program cc1plus)

原因: 碰到各种形式的c++:internal compiler error,包括但不限于这个问题本身,很有可能是内存或虚拟内存不够用了。
解决:加大内存


你可能感兴趣的:(数据库,大数据)