clickhouse配置文件

/etc/clickhouse-server/

在你当前的 /etc/clickhouse-server/ 目录结构中,各子目录和文件分别承担以下职责:

1. conf.d/:全局宏与端口配置

  • chop-generated-macros.xml

    • 定义全局可复用的 ${macros}(如集群名、命名空间、存储路径、日志路径等),在其他配置片段中通过 ${macro_name} 引用。
  • chop-generated-ports.xml

    • 声明所有端口号(<http_port><tcp_port><interserver_http_port><interserver_tcp_port> 等),供 config.d/ 下的配置文件使用。

这两个文件一同作用于 ClickHouse 的主配置(config.xml),确保网络接口、HTTP 接口等端口与路径能动态注入。

2. config.d/:主配置片段

这里集中放置了服务层级的配置,包括监听地址、日志、性能调优、远程服务器等:

  • 01-clickhouse-01-listen.xml:配置服务监听的 IP/端口,通常借助 ${tcp_port}${http_port} 宏;
  • 01-clickhouse-02-logger.xml:日志级别与日志文件路径;
  • 01-clickhouse-03-query_log.xml01-clickhouse-04-part_log.xml:查询日志与分区日志的开关、路径及保留策略;
  • 02-clickhouse-01-qfusion.xml:自定义的 QFusion 相关参数或扩展插件配置;
  • memory.xml:包括全局或默认内存限制、缓存大小等设置;
  • chop-generated-remote_servers.xml:定义集群内互联的远程服务器(用于分布式表或复制)。

这些文件会合并到 config.xml<yandex> 根元素下的相应节点中。

3. users.xmlusers.d/:用户与 Profile/Quota 配置

  • users.xml:默认安装包提供、包含基本用户(如 default)和 Profile/Quota 定义。

  • users.d/:拆分用户、Profile 和配额的片段目录:

    • 01-clickhouse-rdsadmin-profile.xml, 02-clickhouse-default-profile.xml, chop-generated-profiles.xml:定义 <profiles>,包括资源限制(max_memory_usagemax_bytes_before_external_sort 等)。
    • chop-generated-users.xml:定义 <users>,将用户名与 Profile、Quota 关联起来。

这些片段通过软链接指向 ConfigMap 中的实际内容,按文件名排序合并后形成最终的用户与权限配置。


加载与覆盖机制

  1. 文件顺序

    • 目录中的文件按文件名(数字前缀)排序依次加载,后加载的片段可以覆盖前面的相同节点。
  2. 合并逻辑

    • 所有 <profiles> 节点合并成一个大列表;所有 <users> 节点合并成一个大列表;同样 <macros><ports> 也会合并到全局配置中。
  3. 热重载

    • 修改任一片段后,可执行:

      SYSTEM RELOAD CONFIG;
      

      ClickHouse 会自动重新载入这些片段,无需重启服务。

通过这种目录+软链接+片段化的方式,ClickHouse 在 Kubernetes/Helm 环境中实现了配置的灵活拆分、动态重载和环境感知管理。

users.xml和profiles.xml

在 ClickHouse 的配置目录(通常是 /etc/clickhouse-server/)下,你会看到这么几个文件:

config.xml
users.xml
profiles.xml     ← 可选
quotas.xml

它们的职责如下:

文件名作用
users.xml定义用户(<users>)及其关联的 profile(<profile>)和配额(<quota>)等。
profiles.xml只定义 profile(<profiles>)的具体参数集合,不包含用户;在 users.xml 里引用。

为什么要分离成 profiles.xml?

  1. 职责分离

    • users.xml 只管“谁能登录”、密码、默认数据库、以及“给这个用户指定哪个 profile / quota”;
    • profiles.xml 专门管“每个 profile 下有哪些资源/查询限制”。
  2. 复用性

    • 如果你有多组用户需要共享一套资源限制(比如 analyticsetlad-hoc 三种 profile),把 profile 放到独立文件里更清晰,任何用户只需在 users.xml 中引用 <profile>analytics</profile>
    • 否则每次要写全一套 <max_memory_usage><max_bytes_before_external_sort> 等,就会在 users.xml 里重复三遍。
  3. 可维护性

    • profile 参数更新时,只需编辑 profiles.xml,重启或发送 SYSTEM RELOAD CONFIG 即可全局生效。
    • 用户与 profile 分离后,用户文件更干净,也更不容易误改 profile 的细节。

配置示例对比

1)内嵌在 users.xml

<yandex>
  <users>
    <qfusion>
      <password>...</password>
      <profile>qfusion</profile>
    </qfusion>
  </users>
  <profiles>
    <qfusion>
      <max_memory_usage>32212254720</max_memory_usage>
      <max_bytes_before_external_sort>32212254720</max_bytes_before_external_sort>
      <max_bytes_before_external_group_by>32212254720</max_bytes_before_external_group_by>
    </qfusion>
  </profiles>
</yandex>

2)分离到 profiles.xml

users.xml:

<yandex>
  <users>
    <qfusion>
      <password>...</password>
      <profile>qfusion</profile>
    </qfusion>
  </users>
  <!-- profiles、quotas 都不写这里 -->
</yandex>

profiles.xml:

<yandex>
  <profiles>
    <qfusion>
      <max_memory_usage>32212254720</max_memory_usage>
      <max_bytes_before_external_sort>32212254720</max_bytes_before_external_sort>
      <max_bytes_before_external_group_by>32212254720</max_bytes_before_external_group_by>
    </qfusion>
  </profiles>
</yandex>

小结

  • 嵌入式(全部写在 users.xml)适合配置极少用户、profile 参数也很少更新的场景;
  • 分离式(用 profiles.xml 专门管理)更适合中大型集群、profile 复用强、运维更改频繁的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值