1.包下载
下载地址:https://packages.clickhouse.com/rpm/stable/
下载以下几个包:
clickhouse-client-22.8.12.45.x86_64.rpm
clickhouse-common-static-22.8.12.45.x86_64.rpm
clickhouse-common-static-dbg-22.8.12.45.x86_64.rpm
clickhouse-keeper-22.8.12.45.x86_64.rpm【可以不下载,本文使用zk,后续更新迁移至 ckeeper】
clickhouse-server-22.8.12.45.x86_64.rpm
2.安装
rpm -ivh clickhouse-common-static-dbg-22.8.12.45.x86_64.rpm
rpm -ivh clickhouse-common-static-22.8.12.45.x86_64.rpm
rpm -ivh clickhouse-server-22.8.12.45.x86_64.rpm -- 按回车先跳过,后面再设置
rpm -ivh clickhouse-client-22.8.12.45.x86_64.rpm
3.目录说明
/etc/clickhouse-server | 服务端的配置文件目录 |
---|---|
/etc/clickhouse-client | 客户端配置 |
/var/lib/clickhouse | 默认的数据存储目录 |
/var/log/clickhouse-server | 默认保存日志的目录 |
4.修改配置文件 config.xml
1.修改时区:<timezone>Asia/Shanghai</timezone>
2.开启外部访问:<listen_host>0.0.0.0</listen_host>
3.修改数据存放目录:<path>/var/lib/clickhouse/</path>
4.修改日志存放目录:
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
5.配置文件句柄数量:<max_open_files>262144</max_open_files>
6.http默认端口8123:<http_port>8123</http_port>
7.tcp默认端口9000:<tcp_port>9000</tcp_port>
8.zk配置:
<zookeeper>
<node>
<host>hdfs1</host>
<port>2181</port>
</node>
<node>
<host>hdfs2</host>
<port>2181</port>
</node>
<node>
<host>hdfs3</host>
<port>2181</port>
</node>
</zookeeper>
9.集群配置
(3分片1副本)
<remote_servers>
<CK_3shard_1rep>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hdfs1</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hdfs2</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hdfs3</host>
<port>9000</port>
</replica>
</shard>
</CK_3shard_1rep>
</remote_servers>
10.配置宏,三台机器不一致
hdfs1:
<macros>
<shard>01</shard>
<replica>hdfs1</replica>
</macros>
hdfs2:
<macros>
<shard>02</shard>
<replica>hdfs2</replica>
</macros>
hdfs3:
<macros>
<shard>03</shard>
<replica>hdfs3</replica>
</macros>
5.修改密码
本文使用 sha256加密,官方推荐
密码为:123456
[root@hdfs2 clickhouse-server]# echo -n "123456" | sha256sum | tr -d '-'
8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
将以上密码修改到 /etc/clickhouse-server/users.d/default-password.xml
先备份下:cp /etc/clickhouse-server/users.d/default-password.xml /etc/clickhouse-server/users.d/default-password.xml_bak
<clickhouse>
<users>
<default>
<password remove='1' />
<password_sha256_hex>8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92</password_sha256_hex>
</default>
</users>
</clickhouse>
6.启动并连接
# 启动
systemctl start clickhouse-server
# 状态
systemctl status clickhouse-server
# 连接
clickhouse-client -n -m -h hdfs1 --port 9000 -udefault --password 123456
# 查看集群分片(3分片1副本)
hdfs1 :) select * from system.clusters;
SELECT *
FROM system.clusters
Query id: a34401a0-ba49-486b-88ad-6718521d0e81
┌─cluster────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name─┬─host_address────┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─slowdowns_count─┬─estimated_recovery_time─┐
│ CK_3shard_1rep │ 1 │ 1 │ 1 │ hdfs1 │ 192.168.136.221 │ 9000 │ 1 │ default │ │ 0 │ 0 │ 0 │
│ CK_3shard_1rep │ 2 │ 1 │ 1 │ hdfs2 │ 192.168.136.222 │ 9000 │ 0 │ default │ │ 0 │ 0 │ 0 │
│ CK_3shard_1rep │ 3 │ 1 │ 1 │ hdfs3 │ 192.168.136.223 │ 9000 │ 0 │ default │ │ 0 │ 0 │ 0 │
└────────────────┴───────────┴──────────────┴─────────────┴───────────┴─────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────┴─────────────────────────┘
3 rows in set. Elapsed: 0.001 sec.
7.创建本地表&分布式表
# 本地表
CREATE TABLE default.test001_local on cluster CK_3shard_1rep(
_pos UInt8,
_user UInt64,
_exposure_num UInt64,
_type String,
datekey String
)
ENGINE = ReplicatedReplacingMergeTree() PARTITION BY datekey ORDER BY (_pos)
# 分布式表
CREATE TABLE default.test001_distributed on cluster CK_3shard_1rep(
_pos UInt8,
_user UInt64,
_exposure_num UInt64,
_type String,
datekey String
)
ENGINE = Distributed('CK_3shard_1rep', 'default', 'test001_local', rand())
8.附加配置说明
<listen_host>::</listen_host> | 允许IP4和IP6源主机远程访问 |
---|---|
<listen_host>0.0.0.0</listen_host> | 仅允许IP4主机远程访问 |
<listen_host>::1</listen_host> <listen_host>127.0.0.1</listen_host> | 仅允许本地访问 |
到这边简单的clickhouse集群就部署完成,进行了简单的配置,以上配置仅供参考!!!
原理、特性、架构,还在慢慢熟悉,让我们一起学起来吧!!!