目录
profile中的设定项——设置约束(Constraints on Settings)
说明
ClickHouse支持基于RBAC方法的访问控制管理。(关于RBAC的介绍)
作为一个分析类型(OLAP)的数据库系统,相对于MySQL数据库在用户管理方面有很大不同,clickhouse支持使用两种方式配置访问实体:
- 一是通过sql直接设置,这也是官方推荐的,但是需要至少一个用户帐户启用SQL驱动的访问控制和帐户管理,这需要使用第二种方式设置access_management
- 二是通过配置文件users.xml,默认位置在/etc/clickhouse-server目录下,ClickHouse使用它来定义用户相关的配置项。
【注意,您不能同时通过两种配置方法来管理同一访问实体。(You can’t manage the same access entity by both configuration methods simultaneously.)】
本文主要对第二种方式进行说明。注意一点,修改了user.xml的参数之后是即时生效的,如有问题可以查看其错误日志。
users.xml有三大块进行说明,分别为:profiles,quotas,users
profiles
profile的作用类似于用户角色(role),可以在user.xml中定义多组profile,并可以为每组profile定义不同的配置项。
初始时users.xml:
<!-- Profiles of settings. -->
<profiles>
<!-- Default settings. -->
<default>
<!-- Maximum memory usage for processing single query, in bytes. -->
<max_memory_usage>10000000000</max_memory_usage>
<!-- Use cache of uncompressed blocks of data. Meaningful only for processing many of very short queries. -->
<use_uncompressed_cache>0</use_uncompressed_cache>
<!-- How to choose between replicas during distributed query processing.
random - choose random replica from set of replicas with minimum number of errors
nearest_hostname - from set of replicas with minimum number of errors, choose replica
with minimum number of different symbols between replica's hostname and local hostname
(Hamming distance).
in_order - first live replica is chosen in specified order.
first_or_random - if first replica one has higher number of errors, pick a random one from replicas with minimum number of errors.
-->
<load_balancing>random</load_balancing>
</default>
<!-- Profile that allows only read queries. -->
<readonly>
<readonly>1</readonly>
</readonly>
</profiles>
初始有两个profile,一个default,一个readonly,每个profile中都可以有很多其他设定项,比如使用的最大内存、是否只读等等。
默认<default>有一个特殊用途:必须始终存在并且在启动服务器时应用。
profile之间可以相互继承,比如新建两个profile,test1继承default,新加设定为不允许ddl;test2继承readonly,新加设定为允许ddl
<profiles>
...<!-- default和readonly -->
<test1>
<profile>default</profile>
<allow_ddl>0</allow_ddl>
</test1>
<test2>
<profile>readonly</profile>
<allow_ddl>1</allow_ddl>
</test2>
</profiles>
profile中的设定项——查询权限设置
https://clickhouse.tech/docs/en/operations/settings/permissions-for-queries/
ClickHouse中的查询可以分为几种类型:
- 读取数据查询:
SELECT
,SHOW
,DESCRIBE
,EXISTS
。 - 写入数据查询:
INSERT
,OPTIMIZE
。 - 更改设置查询:
SET
,USE
。 - DDL查询:
CREATE
,ALTER
,RENAME
,ATTACH
,DETACH
,DROP
TRUNCATE
。 KILL QUERY
。
其中KILL QUERY查询可以在任何设置下生效。
<readonly>
只读限制,设置读取数据,写入数据和更改设置查询的权限(并不设置ddl查询权限)。
可能的值:
- 0-允许所有查询。
- 1-仅允许读取数据查询。
- 2-允许读取数据和更改设置查询。
读取数据 | 写入数据 | 更改设置 | |
0 | YES | YES | YES |
1 | YES | NO | NO |
2 | YES | NO | YES |
默认值:0
<allow_ddl>
DDL限制,设置是否可以进行DDL操作
可能的值:
- 0-不允许DDL查询。
- 1-允许DDL查询。
默认值:1
profile中的设定项——对查询复杂度的设置
https://clickhouse.tech/docs/en/operations/settings/query-complexity/
对查询复杂度的限制是设置的一部分。它们用于从用户界面提供更安全的执行。
几乎所有限制仅适用于SELECT
。对于分布式查询处理,限制分别应用于每个服务器(就是说对于最大内存这种设置来说是对每台服务器单独算的,不是对集群整体设置最大内存)。
ClickHouse会检查对于整体数据部分的限制条件,而不是对每一行进行限制。这意味着您可以超出数据部分大小的限制值。(It means that you can exceed the value of restriction with the size of the data part.)
对“什么东西的最大数量”的限制可以取值为0,表示“不受限制”。
大多数限制还具有“ overflow_mode”设置,表示超出限制时该怎么做,通常有以下两个值:
throw
–抛出异常(默认)。break
–停止执行查询并返回部分结果。
对于聚合限制(group_by_