background
Install on a CentOS6.10
host with the operating system ClickHouse
(in fact, the original plan was to install it first Docker
, and then Docker
quickly start it in ClickHouse
, but because CentOS6
it Docker
does not support well, just install it directly on the system ); but follow the official command ClickHouse
on the operating system : After installation, start an error:ClickHouse
curl https://clickhouse.com/ | sh
./clickhouse: /lib64/libc.so.6: version `GLIBC_2.14’ not found (required by ./clickhouse)
Check online: GLIBC_2.14
the problem of "libc.so.6: version not found" appears because glibc
the version is too low and needs to be upgraded glibc
. Since the current glibc
highest version of the CentOS system RPM source is 2.12, it can only be upgraded with the source code. After a short operation, check the version supported by the system glibc strings /lib64/libc.so.6 |grep GLIBC
, and there is GLIBC_2.14; after a long time of tossing, it still cannot be started successfully ClickHouse
.
Finally, choose to install the lower version offline ClickHouse19.9.5.36
; in addition, the system also mounts a 600G data disk, modify the ClickHouse
default data storage directory, and put the data and logs into the data disk; configure remote access and password, establish a connection through the command line client, and finally build the database and table.
system environment
[root@iiot ~]# uname -a
Linux iiot 2.6.32-754.15.3.el6.x86_64 #1 SMP Tue Jun 18 16:25:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@iiot ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
[root@iiot ~]# cat /proc/version
Linux version 2.6.32-754.15.3.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #1 SMP Tue Jun 18 16:25:32 UTC 2019
Download and install
- download
https://packagecloud.io/app/altinity/clickhouse/search?q=&filter=all&dist=el%2F6
- Install
rpm -ivh clickhouse-server-common-19.9.5.36-1.el6.x86_64.rpm
rpm -ivh clickhouse-server-19.9.5.36-1.el6.x86_64.rpm --force --nodeps
rpm -ivh clickhouse-client-19.9.5.36-1.el6.x86_64.rpm --force --nodeps
rpm -ivh clickhouse-common-static-19.9.5.36-1.el6.x86_64.rpm --force --nodeps
- start up
# 啊呜,启动报错
[root@iiot mpp]# service clickhouse-server start
Start clickhouse-server service: /usr/bin/clickhouse-extract-from-config: error while loading shared libraries: libicui18n.so.42: cannot open shared object file: No such file or directory
Cannot obtain value of path from config file: /etc/clickhouse-server/config.xml
Download libicu
and libicu-devel
and follow to solve the above error: error while loading shared libraries: libicui18n.so.42
.
wget http://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/libicu-4.2.1-14.el6.x86_64.rpm
wget http://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/libicu-devel-4.2.1-14.el6.x86_64.rpm
rpm -ivh libicu-4.2.1-14.el6.x86_64.rpm
rpm -ivh libicu-devel-4.2.1-14.el6.x86_64.rpm
# 启动成功
[root@iiot mpp]# service clickhouse-server start
Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
DONE
# 查看状态,竟然停止了。。
[root@iiot mpp]# service clickhouse-server status
clickhouse-server: process unexpectedly terminated
# 到日志目录看下啥原因
[root@iiot clickhouse-server]# cd /var/log/clickhouse-server/
[root@iiot clickhouse-server]# ll
总用量 8
-rw-r----- 1 clickhouse clickhouse 0 6月 7 11:22 clickhouse-server.err.log
-rw-r----- 1 clickhouse clickhouse 3190 6月 7 11:35 clickhouse-server.log
-rw-r----- 1 clickhouse clickhouse 1969 6月 7 11:34 stderr.log
-rw-r----- 1 clickhouse clickhouse 0 6月 7 11:22 stdout.log
# 原来是服务器时区问题
[root@iiot clickhouse-server]# tailf clickhouse-server.log
Poco::Exception. Code: 1000, e.code() = 0, e.displayText() = Exception: Could not determine local time zone: custom time zone file used. (version 19.9.5.36)
# 解决ClickHouse时区报错问题
[root@iiot ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 重启ClickHouse后,连接8123端口,成功~
[root@iiot ~]# curl localhost:8123
Ok.
[root@iiot ~]# service clickhouse-server status
clickhouse-server service is running
# 停止ClickHouse服务
[root@iiot ~]# service clickhouse-server stop
Stop clickhouse-server service:
DONE
Modify the default data and log directories
ClickHouse
Default data directory: /var/lib/clickhouse/
.
ClickHouse
Default log directory: /var/log/clickhouse-server/
.
Mounted a 600G data disk ( /mnt
under ), and ClickHouse
put the data and logs in the data disk.
[root@iiot ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 3.8G 34G 11% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/vdb1 591G 16G 546G 3% /mnt
# 修改clickhouse的默认数据目录和日志目录
[root@iiot ~]# cd /mnt/mpp
[root@iiot mpp]# mkdir -p clickhouse/data
[root@iiot mpp]# mkdir -p clickhouse/log
[root@iiot mpp]# mv /var/lib/clickhouse/ /mnt/mpp/clickhouse/data/
[root@iiot mpp]# cd /var/lib/
[root@iiot lib]# ln -s /mnt/mpp/clickhouse/data/clickhouse/ .
[root@iiot lib]#
[root@iiot lib]# mv /var/log/clickhouse-server/ /mnt/mpp/clickhouse/log/
[root@iiot lib]# cd /var/log/
[root@iiot log]# ln -s /mnt/mpp/clickhouse/log/clickhouse-server/ .
[root@iiot log]#
[root@iiot log]# chown -Rc clickhouse:clickhouse /mnt/mpp/clickhouse/data/clickhouse/
[root@iiot log]# chown -Rc clickhouse:clickhouse /mnt/mpp/clickhouse/log/clickhouse-server/
Restart ClickHouse
the service and start successfully.
Turn on remote access and configure a password
- Enable remote access
# 放开注释,当然记得开放安全组,默认端口8123
[root@iiot clickhouse-server]# vi /etc/clickhouse-server/config.xml
70 <listen_host>::</listen_host
- configuration password
Security awareness must be raised. Now that remote access is enabled, security support must keep up (it is not recommended to open the database port in actual production).
# 这里使用明文密码,还可以通过sha256对密码进行加密配置
[root@iiot clickhouse-server]# vi /etc/clickhouse-server/users.xml
<!-- If user name was not specified, 'default' user is used. -->
47 <password>CK666%</password>
# 重启服务
[root@iiot clickhouse-server]# service clickhouse-server restart
Stop clickhouse-server service: DONE
Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
DONE
Build database and table
ClickHouse
It supports the operation of class SQL
statements, so if you are familiar with relational databases, you can get started quickly (however, unlike , the MySQL
update ClickHouse
and delete statements in are not the same, which ClickHouse
will be encountered after the subsequent integration of SpringBoot and MyBatisPlus, and will be solved in the next article).
-- 通过命令行客户端工具无密码连接(没配置密码可以这样连)
[root@iiot ~]# clickhouse-client
-- 通过命令行客户端工具带密码连接(-m参数含义:允许执行多行sql)
[root@iiot ~]# clickhouse-client --password -m
-- 建库
CREATE DATABASE IF NOT EXISTS helloworld;
-- 建表
CREATE TABLE helloworld.my_first_table
(
user_id UInt32,
message String,
timestamp DateTime,
metric Float32
)
ENGINE = MergeTree()
PRIMARY KEY (user_id, timestamp);
Code: 36. DB::Exception: Received from localhost:9000, ::1. DB::Exception: You must provide an ORDER BY expression in the table definition. If you don't want this table to be sorted, use ORDER BY tuple().
Different from the higher version, ClickHouse19
the table creation statement in is also required ORDER BY
. .
CREATE TABLE helloworld.my_first_table
(
user_id UInt32,
message String,
timestamp DateTime,
metric Float32
)
ENGINE = MergeTree()
ORDER BY (user_id)
PRIMARY KEY (user_id, timestamp);
Code: 36. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Primary key must be a prefix of the sorting key, but its length: 2 is greater than the sorting key length: 1.
CREATE TABLE helloworld.my_first_table
(
user_id UInt32,
message String,
timestamp DateTime,
metric Float32
)
ENGINE = MergeTree()
ORDER BY (user_id, timestamp)
PRIMARY KEY (user_id, timestamp);
Finally OK. ClickHouse
After the service is successfully started, a large amount of data in our relational database can be migrated to later ClickHouse
, and experience this columnar database management system known for its fast online analysis ( ).OLAP
Note: The higher version ClickHouse
has an PlayGround
endpoint: http://IP:8123/play
, which can directly interact Web
with the database through the way to query; this time does not have.OLAP
ClickHouse19.9.5.36
Reference
If you have any questions or any bugs are found, please feel free to contact me.
Your comments and suggestions are welcome!