简介
ClickHouse是由俄罗斯的Yandex公司开发的开源列式数据库管理系统。它最早于2016年开源,主要用于实时数据分析。ClickHouse通过列存储、向量化执行、并行计算等技术,实现了对大规模数据集的快速查询和分析,特别适合实时数据分析和商业智能需求。
ClickHouse的特点
ClickHouse的优缺点
优点
缺点
ClickHouse的使用场景
安装部署
打开文件数限制
[root@test19-server07 ~]# cat /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 204800
* hard nofile 204800
RPM 包添加官方仓库
yum install -y yum-utils
yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
对于带有软件包管理器(openSUSE、SLES)的系统:zypper
zypper addrepo -r https://packages.clickhouse.com/rpm/clickhouse.repo -g
zypper --gpg-auto-import-keys refresh clickhouse-stable
以后 any 可以替换为 .要指定特定版本,请在软件包名称的末尾添加,例如 .yum installzypper install-$VERSIONclickhouse-client-22.2.2.22
安装ClickHouse服务器和客户端
yum install -y clickhouse-server clickhouse-client
变更目录记得创建以及授权
mkdir /jesong/clickhouse
chown -R clickhouse:clickhouse clickhouse
修改配置文件
系统级参数 config.xml
vim /etc/clickhouse-server/config.xml
开启远程机器登录
<listen_host>::</listen_host>
数据目录
<!-- Path to data directory, with trailing slash. -->
<path>/jesong/clickhouse/</path>
日志目录
<level>notice</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
设置时区为东八区
<timezone>Asia/Shanghai</timezone>
内存数5GB
<max_server_memory_usage>5000000000</max_server_memory_usage>
用户权限\查询优化参数users.xml
vim /etc/clickhouse-server/users.xml
查询使用的最大线程数
<max_threads>8</max_threads>
查询的最大执行时间
<max_execution_time>600</max_execution_time>
users.xml模版仅供参考
<!-- Settings profiles -->
<profiles>
<!-- Default settings -->
<default>
<!-- The maximum number of threads when running a single query. -->
<max_threads>8</max_threads>
</default>
<!-- Settings for queries from the user interface -->
<web>
<max_rows_to_read>1000000000</max_rows_to_read>
<max_bytes_to_read>100000000000</max_bytes_to_read>
<max_rows_to_group_by>1000000</max_rows_to_group_by>
<group_by_overflow_mode>any</group_by_overflow_mode>
<max_rows_to_sort>1000000</max_rows_to_sort>
<max_bytes_to_sort>1000000000</max_bytes_to_sort>
<max_result_rows>100000</max_result_rows>
<max_result_bytes>100000000</max_result_bytes>
<result_overflow_mode>break</result_overflow_mode>
<max_execution_time>600</max_execution_time>
<min_execution_speed>1000000</min_execution_speed>
<timeout_before_checking_execution_speed>15</timeout_before_checking_execution_speed>
<max_columns_to_read>25</max_columns_to_read>
<max_temporary_columns>100</max_temporary_columns>
<max_temporary_non_const_columns>50</max_temporary_non_const_columns>
<max_subquery_depth>2</max_subquery_depth>
<max_pipeline_depth>25</max_pipeline_depth>
<max_ast_depth>50</max_ast_depth>
<max_ast_elements>100</max_ast_elements>
<max_sessions_for_user>4</max_sessions_for_user>
<readonly>1</readonly>
</web>
</profiles>
优化参数及其说明(参考)
1. 系统级参数
这些参数通常设置在config.xml文件中:
max_connections: 设置最大并发连接数。
listen_host: 设置服务器监听的主机地址,可以设置为特定IP地址或0.0.0.0来监听所有地址。
listen_try: 设置尝试绑定的次数,以避免在启动时由于端口占用而失败。
max_server_memory_usage: 限制服务器内存使用量。
path: 数据存储的主路径。
tmp_path: 临时文件路径。
user_files_path: 用户文件的存储路径。
format_schema_path: 格式模式文件的路径。
log_level: 日志记录级别。
2. 用户和权限参数
这些参数设置在users.xml文件中:
readonly: 设置是否为只读模式。
max_memory_usage: 每个用户的最大内存使用量。
max_concurrent_queries: 每个用户的最大并发查询数。
profile: 指定用户使用的资源配置文件。
quota: 指定用户的配额设置。
3. 表和数据引擎参数
这些参数可以在表创建时设置:
primary_key: 设置表的主键。
index_granularity: 设置索引粒度,影响数据块的大小。
merge_tree: MergeTree引擎的参数,如parts_to_throw_insert和max_partitions_to_read。
4. 查询优化参数
这些参数可以在查询时使用,也可以在服务器级别进行配置:
max_threads: 查询使用的最大线程数。
max_execution_time: 查询的最大执行时间。
use_uncompressed_cache: 是否使用未压缩的缓存。
max_block_size: 查询时返回的最大数据块大小。
min_insert_block_size_rows: 插入时的最小行数。
min_insert_block_size_bytes: 插入时的最小字节数。
5. 网络和缓存参数
这些参数可以在config.xml中设置:
max_network_bandwidth: 限制服务器的最大网络带宽。
max_broken_connections: 设置允许的最大断开连接数。
tcp_keep_alive_timeout: 设置TCP连接的保持时间。
6. 存储和文件系统参数
这些参数在config.xml中设置:
merge_max_block_size: 合并时的最大数据块大小。
merge_tree_min_rows_for_wide_part: 创建宽部件的最小行数。
merge_tree_max_rows_to_use_cache: 使用缓存的最大行数。
7. 日志和监控参数
这些参数也在config.xml中设置:
log_path: 日志文件的存储路径。
query_log: 是否启用查询日志。
metric_log: 是否启用度量日志。
trace_log: 是否启用跟踪日志。
启动服务
systemctl enable clickhouse-server
systemctl start clickhouse-server
systemctl status clickhouse-server
clickhouse-client
创建账户
登录超管:clickhouse-client --user=default
创建root账户
CREATE USER root IDENTIFIED WITH sha256_password BY 'dbapassword1vc3rcsSDFs23e';
GRANT SELECT, INSERT, UPDATE, DELETE,ALTER,DROP,TRUNCATE ON *.* TO root;
登录root账户
clickhouse-client --user=root --password
show databases;
总结
ClickHouse是一款高性能的开源列式数据库管理系统,特别适用于实时数据分析和大规模数据查询场景。其列式存储、向量化执行、并行处理等技术特点,使得它在处理海量数据时具有显著优势。然而,ClickHouse在写入性能、事务支持、生态系统等方面仍存在一定的局限性。总体而言,对于需要快速、实时数据分析的应用场景,ClickHouse是一个值得推荐的选择。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有