ClickHouse用户资源隔离在 GrowingIO 的实践

本文介绍了GrowingIO如何在ClickHouse中实现用户资源隔离和多租户管理。通过Quotas和Profile机制限制用户对资源的使用,确保服务稳定性。文章详细讲解了如何使用SQL进行动态资源管理,包括创建用户、Profile、Quota和Role,以及如何通过SQL驱动的方式实现权限持久化。此外,还探讨了ClickHouse推荐的SQL驱动的访问控制流程。
摘要由CSDN通过智能技术生成

业务场景

对 ClickHouse 做多租户,是一个非常必要的场景。如果不加限制,用户可能会过度消耗数据库服务的资源,影响其他用户使用。本文尝试在硬件级别的隔离之外,给大家展示另外一种相对便宜的方法。

本文先描述 ClickHouse 提供哪些资源限制的机制,再描述 GrowingIO 的实践。由于用户资源使用限制是用户管理的一种,本文也会加入用户管理的内容。

Hello World

一般通过 systemd 托管 ClickHouse,使用工具渲染模板得出配置文件,由于我们的目的只是演示,所以简化了相关步骤和配置。

在 /etc/clickhouse目录创建 2 个文件:

── conf
   ├── config.xml
   └── users.xml

然后在任意目录运行:

clickhouse server --config=/etc/clickhouse/conf/config.xml

就让 ClickHouse 按照配置文件运行,同时 ClickHouse 监听配置文件,如有变化,不需要重启就能按新的配置运行。

The server tracks changes in config files... and reloads the settings for users and clusters on the fly (Configuration Files | ClickHouse Documentation)

这是简约版的 config.xml 的配置 demo:

<?xml version="1.0"?>
<yandex>
    <logger>
        <level>trace</level>
        <log>/tmp/log/clickhouse-server.log</log>
        <errorlog>/tmp/log/clickhouse-server.err.log</errorlog>
        <size>1000M</size>
        <count>10</count>
    </logger>
    <query_log>
        <database>system</database>
        <table>query_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>1000</flush_interval_milliseconds>
    </query_log>
    <tcp_port>9000</tcp_port>
    <listen_host>127.0.0.1</listen_host>
    <access_control_path>/tmp/ledzeppelin/</access_control_path>
    <max_concurrent_queries>500</max_concurrent_queries>
    <mark_cache_size>5368709120</mark_cache_size>
    <path>./clickhouse/</path>
    <users_config>users.xml</users_config>
</yandex>

注意到 <users_config>users.xml</users_config> 绑定了 config.xml 当前目录的 users.xml

<?xml version="1.0"?>
<yandex>
    <profiles>
        <default>
            <readonly>1</readonly>
        </default>
        <pA>
            <max_memory_usage>10G</max_memory_usage>
            <max_memory_usage_for_user>10G</max_memory_usage_for_user>
            <max_memory_usage_for_all_queries>10G</max_memory_usage_for_all_queries>
            <max_query_size>1073741824</max_query_size>
            <readonly>1</readonly>
        </pA>
    </profiles>
    <users>
        <zeppelin>
            <!-- <password_sha256_hex></password_sha256_hex> -->
            <password>password</password>
            <networks>
                <ip>::/0</ip>
            </networks>
            <profile>pA</profile>
            <quota>qA</quota>
        </zeppelin>
    </users>
    <quotas>
        <qA>
            <interval>
                <!-- 以秒为单位 -->
                <duration>10
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值