首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ClickHouse安装和使用

ClickHouse安装和使用

作者头像
bisal
发布2021-12-03 08:13:58
3.1K0
发布2021-12-03 08:13:58
举报

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/,尚未有这个最新的版本,因此下载会失败,

2a2c273708e865ffc9b2a36cb30680c9.png
2a2c273708e865ffc9b2a36cb30680c9.png

可以从github,下载最新的版本,但是要注意,找结尾是stable的,这才是稳定版本,https://github.com/ClickHouse/ClickHouse/tags,

5b6895431bc8cff81895c57e0d9c8023.png
5b6895431bc8cff81895c57e0d9c8023.png

curl返回的是json格式版本的信息,

2d279af000c3efb86b1ee3d83c130601.png
2d279af000c3efb86b1ee3d83c130601.png

下载这几个,

f4dc210c4685bee99874e4eb7e610bd9.png
f4dc210c4685bee99874e4eb7e610bd9.png

进入这几个文件夹执行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执行,

e6f4a274b070ab0615f6cdde47b9a015.png
e6f4a274b070ab0615f6cdde47b9a015.png

登录数据库,执行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;

创建一张测试表,

6bd09b3f8eb865e6eeb72dff86c4f9be.png
6bd09b3f8eb865e6eeb72dff86c4f9be.png

插入测试数据,

8457cd4e9b211c5b64b9daf12eeca60c.png
8457cd4e9b211c5b64b9daf12eeca60c.png

检索数据,

6657154e37816ae771c45b16d901ddc9.png
6657154e37816ae771c45b16d901ddc9.png

都是标准SQL,有点基础的,都可以操作,而且很多操作,和MySQL很像,

821c9856756c98768978a3e9a634d2b3.png
821c9856756c98768978a3e9a634d2b3.png

show databases、use database、show tables,

2f7116fa36c0c49094c1ccd3e042c60d.png
2f7116fa36c0c49094c1ccd3e042c60d.png

ClickHouse支持很多种客户端连接形式,

16223a5082dc16ef61cc68cefba59c1c.png
16223a5082dc16ef61cc68cefba59c1c.png

https://clickhouse.com/docs/zh/interfaces/third-party/gui/

DBeaver都支持了,

024015bc3b85981ba841a41ab5da44a3.png
024015bc3b85981ba841a41ab5da44a3.png

命令行跟着query,就可以执行SQL,方便在脚本中用,

[clickhouse@bisal ~]$ ck --query "select count(*) from datasets.city"
0

参考资料,

https://blog.51cto.com/u_15127645/2777968

https://blog.csdn.net/weixin_45727359/article/details/114421863

https://blog.csdn.net/wbl381/article/details/106995351/

https://clickhouse.com/docs/en/introduction/distinctive-features/

https://www.jianshu.com/p/350b59e8ea68

https://clickhouse.com/docs/zh/getting-started/example-datasets/ontime/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-12-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档