由于clickhouse的发布比较频繁,目前版本为20.7 尚未支持与mysql同步,故编译了git上最新的版本 20200909--版本号为20.9。
环境信息
系统版本:Red Hat Enterprise Linux Server release 7.7 (Maipo)
uname -a:3.10.0-1062.el7.x86_64服务器配置:32c 250g 1T(使用8c16g虚拟机编译失败,原因为内存不足导致编译进程OOM)
mysql版本:8.0.19
gcc版本:9.3.0
cmake版本:3.14.5
ninja版本:1.9.0
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
yum install git cmake ninja-build libicu-devel clang libicu-devel readline-devel mysql-devel openssl-devel unixODBC_devel bzip2 -y
git clone --recursive https://github.com/ClickHouse/ClickHouse
ftp://gnu.mirror.iweb.com/gcc/gcc-9.3.0/gcc-9.3.0.tar.xz
tar xvf gcc-9.3.0.tar.xz
cd gcc-9.3.0
./contrib/download_prerequisites
此步骤会下载依赖包,如无无法连接外网可通过链接下载
链接:https://pan.baidu.com/s/1JHv1WAS43S89LXA6PkevTg 提取码:nb35
包名如下
gmp-6.1.0.tar.bz2mpfr-3.1.4.tar.bz2
mpc-1.0.3.tar.gzisl-0.18.tar.bz2
使用方式: 将包cp到gcc-9.3.0目录下即可
然后执行
./contrib/download_prerequisites ---与上一步相同无需重复执行
mkdir build
cd build../configure --prefix=/opt/gcc9 --enable-languages=c,c++ --disable-multilib
export THREADS=$(grep -c ^processor /proc/cpuinfo)
make -j $THREADS
make install
编译所需时间较长=。=
ninja: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ninja)
解决办法如下
find / -name "libstdc++.so.6*"
找到系统中版本最高的gcc目录,例如此前的安装目录
/opt/gcc9/lib64/libstdc++.so.6.0.28
/opt/gcc9/lib64/libstdc++.so.6
/opt/gcc9/lib64/libstdc++.so.6.0.28-gdb.py
备份报错的 libstdc++.so
mv /lib64/libstdc++.so.6 /lib64/libstdc++.so.6_bak
将高版本的libstdc++复制到/lib64目录下
cp /opt/gcc9/lib64/libstdc++.so.6 /lib64/libstdc++.so.6
ln -s /opt/gcc9/lib64/libstdc++.so.6.0.28 /lib64/libstdc++.so.6 ----(一般执行上一步就可以了)
验证
[root@mini test]# ./ninja --version
1.9.0
安装cmake 3,保留替换系统默认的 准备软件
wget https://cmake.org/files/v3.14/cmake-3.14.5-Linux-x86_64.tar.gz
tar zxvf cmake-3.14.5-Linux-x86_64.tar.gz -C /opt
ln -s cmake-3.14.5-Linux-x86_64 cmake
添加环境变量
vim /etc/profile
export CMAKE_HOME=/opt/cmake
export PATH=$CMAKE_HOME/bin:$PATH
source /etc/profile
验证
[root@mini test]# cmake --version
cmake version 3.14.5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
下载
wget https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip
unzip ninja-linux.zip -d /usr/local/bin/
添加环境变量
测试版本:
# ninja --version
1.9.0
[root@mini test]# ./ninja
./ninja: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./ninja)
./ninja: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./ninja)
处理方法见:gcc 9.3.0编译安装
cd ClickHouse
mkdir build
cd build
export CC=gcc-9
export CXX=g++-9
cmake ..ninja
该过程耗时大概3小时
安装成功后,将clickhouse命令以及参数文件拷贝到指定目录
mkdir -p /usr/local/clickhouse/etccd /tools/ClickHouse/programs/server ---其中/tools/ClickHouse 为clickhouse git文件根目录
cp config.xml /usr/local/clickhouse/etc
cp users.xml /usr/local/clickhouse/etc
将clickhouse执行文件copy 到/usr/local/clickhouse/bin
mkdir -p /usr/local/clickhouse/bin
cp /tools/ClickHouse/build/programs/clickhouse /usr/local/clickhouse/bin
配置环境变量
vim /etc/profile添加:/usr/local/clickhouse/bin
source /etc/profiel
启动clickhouse-server,注意启动之前设置配置文件中PATH目录(clickhouse数据目录 并给对应目录赋权)
nohup clickhouse server --config-file=/usr/local/clickhouse/etc/config.xml > /tmp/clickhouse.log 2>&1 &
启动客户端
clickhouse client
输出:
ClickHouse client version 20.9.1.1.
Connecting to localhost:9000 as user default.
to ClickHouse server version 20.9.1 revision 54439.
XXXXXXXX :)
至此clickhouse编译安装完成,以下为搭建mysql复制过程
准备一套与clickhouse服务器网络通畅的mysql,本文使用的MySQL版本为8.0.19
mysql> create user clickhouse@'%' identified WITH mysql_native_password by 'rpl_user';
mysql> grant ALL PRIVILEGES on *.* to clickhouse@'%';
clickhouse :) SET allow_experimental_database_materialize_mysql=1;
clickhouse创建复制(目前以 database 为单位进行复制,不同的 database 可以来自不同的 MySQL master,这样就可以实现多个 MySQL 源数据同步到一个 ClickHouse 做 OLAP 分析功能。)
CREATE DATABASE sbtest ENGINE = MaterializeMySQL(
'MYSQL_IP:MYSQL_PORT', 'DATABASE_NAME', 'USER_NAME', 'PASSWORD');
CREATE DATABASE sbtest ENGINE = MaterializeMySQL(
'XXXXXXXX:3306', 'clickhouse', 'clickhous', 'rpl_user');
如报错
Received exception from server (version 20.9.1):Code: 537. DB::Exception: Received from localhost:9000. DB::Exception: Illegal MySQL variables, the MaterializeMySQL engine requires default_authentication_plugin='mysql_native_password'.
在MYSQL端调整改参数并重启(read_only参数)default_authentication_plugin='mysql_native_password'
mysql> create database clickhouse;
mysql> use clickhouse;mysql> CREATE TABLE `sbtest1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_1` (`k`))
ENGINE = InnoDB AUTO_INCREMENT = 5000001 DEFAULT CHARSET = utf8mb4 MAX_ROWS = 1000000;
mysql> INSERT INTO `sbtest1` VALUES (1,49929,...; ---sysbench数据
clickhouse> use sbtest;
clickhouse> show tables;SHOW TABLES
┌─name────┐
│ sbtest1 │
└─────────┘
1 rows in set. Elapsed: 0.002 sec.
clickhouse>select * from sbtest1;
SELECT *
FROM sbtest1
┌─id─┬─────k─┬─c───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─pad─────────────────────────────────────────────────────────┐
│ 12 │ 48776 │ 06636928111-91412549319-87017689961-79500497523-29051692073-64380774874-78643769852-73373361096-34215043106-34370178281 │ 89292458800-98111883088-45119613990-18776802947-72334127545 │
.......略
20 rows in set. Elapsed: 0.004 sec.
查看同步位点
看下 ClickHouse 的同步位点
cat /var/lib/clickhouse/metadata/clickhouse/.metadata
Version: 2
Binlog File: bin.000004
Executed GTID: 45b22def-f329-11ea-acf1-3497f600d5bb:1-69:1000068
Binlog Position: 10006
至此slave搭建成功。
| 作者简介
赵梓州 | 现职于甜橙金融(中国电信翼支付),数据库工程师。
主要负责 MySQL、Redis、MongoDB、TIDB等相关开源数据库运维工作。
喜欢学习分享技术,和大家共同提高!
全文完。