背景
最近花了些时间看了下ClickHouse文档,发现它在OLAP方面表现很优异,而且相对也比较轻量和简单,所以准备入门了解下该数据库系统。在安装完之后首先做的应该如何设置用户密码以及权限控制。因为和MySQL、MongoDB等数据库的用户管理完全不一样,为方便自己以后直接查阅,本文对其用户权限管理方面进行梳理说明。
说明
ClickHouse作为一个分析类型(OLAP)的数据库系统,相对于MySQL数据库在用户管理方面有很大不同,它是通过修改配置文件来实现用户权限管理的。在安装好ClickHouse之后,其默认的配置文件在/etc/clickhouse-server目录下,对应的配置文件为users.xml,ClickHouse使用它来定义用户相关的配置项。现在开始对其进行说明,对应手册里的说明包含以下几个方面:
- Settings profiles
- User settings
- Constraints on Settings
- Quotas
- Permissions for queries
- Access Rights
注意一点,修改了user.xml的参数之后是即时生效的,如有问题可以查看其错误日志。好了,现在开始对这些进行说明,先熟悉用户权限管理这一方面的相关操作。
※ Settings profiles :设置用户配置文件
profile的作用类似于用户角色,可以在user.xml中定义多组profile,并可以为每组profile定义不同的配置项,类限制资源的使用。多个profile的配置可以复用。咋眼一看有点和MySQL的Proxy权限类似。
模板:
<profiles> --配置profile <default> -- 自定义profile <max_memory_usage>10000000000</max_memory_usage> <use_uncompressed_cache>0</use_uncompressed_cache> <load_balancing>random</load_balancing> </default> <readonly> -- 自定义profile <readonly>1</readonly> <max_memory_usage>100000000</max_memory_usage> </readonly> </profiles>
说明:
- <default>:自定义profile,可以在它下面设置相关参数,如:最大内存使用、只读等等。更多的配置参数后续会介绍,也而已看官网文档,可以设置多个profile。
该示例指定了两个profile:default和readonly。 默认<default>有一个特殊用途:必须始终存在并且在启动服务器时应用。profile文件可以相互继承,只需要在配置文件中列出即可,如定义一个test的profile:
<test> <profile>readonly</profile> <max_memory_usage>10000</max_memory_usage> </test>
test的profile继承了readonly的profile,包含了其所有的配置,并且使用新参数来覆盖其原有的配置。设置了之后如何使用呢?有二种方法,第1是直接在终端命令行里进行设置,第2个是在users.xml中的users选项组里进行指定(后面会说明)。
[root@dba clickhouse-server]# clickhouse-client ClickHouse client version 20.3.5.21 (official build). Connecting to localhost:9000 as user default. Connected to ClickHouse server version 20.3.5 revision 54433. dba :) set profile = 'test' SET profile = 'test' Ok. rows in set. Elapsed: 0.002 sec. dba :) set max_memory_usage = 123123 SET max_memory_usage = 123123 Received exception from server (version 20.3.5): Code: 164. DB::Exception: Received from localhost:9000. DB::Exception: Cannot modify 'max_memory_usage' setting in readonly mode. rows in set. Elapsed: 0.005 sec. dba :) Bye.