《ClickHouse介绍》我们介绍了ClickHouse,学习技术,最重要的,就是实践,通过step by step,来体验下ClickHouse。
一款软件,到底好用不好用,安装是第一印象。
ClickHouse可以在任何具有x86_64,AArch64或PowerPC64LE CPU架构的Linux,FreeBSD或Mac OS X上运行。官方预构建的二进制文件通常针对x86_64进行编译,并利用SSE 4.2指令集,因此,除非另有说明,支持他的CPU使用将成为额外的系统需求。
下面是检查当前CPU是否支持SSE 4.2的命令,
[root@bisal ~]# grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported
ClickHouse支持很多种安装,
(1) DEB安装包
(2) RPM安装包
(3) Tgz安装包
(4) Docker安装包
(5) 其他环境安装包,对于非linux操作系统和Arch64 CPU架构,ClickHouse将会以master分支的最新提交的进行编译提供
(6) 源代码安装
我在一套1C2G的云资源上通过Tgz尝试安装ClickHouse。
按照官方文档的指令,将最新的版本号,存储至LATEST_VERSION,再通过curl下载最新的4个tgz,
export LATEST_VERSION=`curl https://api.github.com/repos/ClickHouse/ClickHouse/tags 2>/dev/null | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1`
curl -O https://repo.clickhouse.com/tgz/clickhouse-common-static-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/clickhouse-server-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/clickhouse-client-$LATEST_VERSION.tgz
如下所示,最新的是21.12.1.8816,
[root@bisal ~]# echo $LATEST_VERSION
21.12.1.8816
但是截止到目前,curl的地址https://repo.clickhouse.com/tgz/,尚未有这个最新的版本,因此下载会失败,
可以从github,下载最新的版本,但是要注意,找结尾是stable的,这才是稳定版本,https://github.com/ClickHouse/ClickHouse/tags,
curl返回的是json格式版本的信息,
下载这几个,
进入这几个文件夹执行install/doinst.sh,就安装完成了,
sudo clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
sudo clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh
sudo clickhouse-server-$LATEST_VERSION/install/doinst.sh
sudo clickhouse-client-$LATEST_VERSION/install/doinst.sh
可以有以下几种形式启动ClickHouse Server,
sudo /etc/init.d/clickhouse-server start
sudo service clickhouse-server start
clickhouse-server --config-file=/etc/clickhouse-server/config.xml(从控制台启动,日志将打印到控制台)
日志路径是/var/log/clickhouse-server/,配置文件路径是/etc/clickhouse-server/config.xml。
此时可以通过客户端连接到数据库,
clickhouse-client
如果改了密码,可能会提示错误,
ClickHouse client version 21.11.3.6 (official build).
Connecting to localhost:9000 as user default.
If you have installed ClickHouse and forgot password you can reset it in the configuration file.
The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml
and deleting this file will reset the password.
See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed.
Code: 516. DB::Exception: Received from localhost:9000. DB::Exception: default: Authentication failed: password is incorrect or there is no user with such name. (AUTHENTICATION_FAILED)
此时可以用--password,指定具体的密码,
clickhouse-client --user=default --password=clickhouse --host=127.0.0.1 --multiline
请注意,这里用到了--multiline,他的意思是,对长的SQL进行转义,否则执行跨行SQL时,会提示错误,如下所示,他会将每行都当作独立的SQL执行,
登录数据库,执行select 1,很可能出现乱码,此时要将你的secureCRT之类的软件字符集调整为UTF-8,重启生效,
VM-24-12-centos :) select 1
SELECT 1
Query id: e10f42f2-92f9-426e-88ba-6a22f5a84fc5
鈹屸攢1鈹€鈹
鈹1 鈹
鈹斺攢鈹€鈹€鈹
1 rows in set. Elapsed: 0.001 sec.
再次登录,执行就正常了,
VM-24-12-centos :) select 1
SELECT 1
Query id: 141db667-bfca-41da-bffd-e85f8d62cbc6
┌─1─┐
│ 1 │
└───┘
1 rows in set. Elapsed: 0.002 sec.
登录数据库执行的每条SQL,ClickHouse都会自动记录到根路径的.clickhouse-client-history,
### 2021-11-13 10:50:14.109
show tables;
### 2021-11-13 10:56:56.225
show processlist;
### 2021-11-13 10:57:27.228
exit
### 2021-11-13 10:58:02.519
select 1
### 2021-11-13 10:58:13.384
select * from system.processes;
创建一张测试表,
插入测试数据,
检索数据,
都是标准SQL,有点基础的,都可以操作,而且很多操作,和MySQL很像,
show databases、use database、show tables,
ClickHouse支持很多种客户端连接形式,
https://clickhouse.com/docs/zh/interfaces/third-party/gui/
DBeaver都支持了,
命令行跟着query,就可以执行SQL,方便在脚本中用,
[clickhouse@bisal ~]$ ck --query "select count(*) from datasets.city"
0
参考资料,
https://blog.51cto.com/u_15127645/2777968
https://clickhouse.com/docs/en/introduction/distinctive-features/
https://www.jianshu.com/p/350b59e8ea68
https://clickhouse.com/docs/zh/getting-started/example-datasets/ontime/