简单的Clickhouse群集通过Docker中的Clickhouse-keeper

发布于 2025-02-02 00:54:22 字数 5964 浏览 1 评论 0 原文

我正在尝试通过 clickhouse-keeper 进行设置和测试复制。

这是我的docker.compose.yaml

version: "3.7"

services:
  clickhouse01:
    image: yandex/clickhouse-server
    container_name: clickhouse01
    hostname: clickhouse01
    ports:
      - 8811:8123
      - 9011:9000
    volumes:
      - "D:/clichhouse-data/volume1:/var/lib/clickhouse"

  clickhouse02:
    image: yandex/clickhouse-server
    hostname: clickhouse02
    container_name: clickhouse02
    ports:
      - 8812:8123
      - 9012:9000
    volumes:
      - "D:/clichhouse-data/volume2:/var/lib/clickhouse"

是我在 /etc/clickhouse-server/config.xml 的 remote_servers 部分

<remote_servers>
        <test_cluster_two_shards_localhost>
             <shard>
                 <replica>
                     <host>clickhouse01</host>
                     <port>9000</port>
                 </replica>
                 <replica>
                    <host>clickhouse02</host>
                    <port>9000</port>
                </replica>
             </shard>
        </test_cluster_two_shards_localhost>
    </remote_servers>

这 我在 1st Node ,路径 - /etc/clickhouse-server/config.d/上使用的Keeper.xml 文件:

<clickhouse_keeper>
    <keeper_server>
        <tcp_port>9181</tcp_port>
        <server_id>1</server_id>
        <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <raft_logs_level>trace</raft_logs_level>
        </coordination_settings>

        <raft_configuration>
            <server>
                <id>1</id>
                <hostname>clickhouse01</hostname>
                <port>9234</port>
            </server>
            <server>
                <id>2</id>
                <hostname>clickhouse02</hostname>
                <port>9234</port>
            </server>
        </raft_configuration>
    </keeper_server>
</clickhouse_keeper>

这是 keeper.xml 我在第二个节点,路径 - /etc/clickhouse-server/config.d/

<clickhouse_keeper>
    <keeper_server>
        <tcp_port>9181</tcp_port>
        <server_id>2</server_id>
        <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <raft_logs_level>trace</raft_logs_level>
        </coordination_settings>

        <raft_configuration>
            <server>
                <id>1</id>
                <hostname>clickhouse01</hostname>
                <port>9234</port>
            </server>
            <server>
                <id>2</id>
                <hostname>clickhouse02</hostname>
                <port>9234</port>
            </server>
        </raft_configuration>
    </keeper_server>
</clickhouse_keeper>

这是< strong> macros.xml 我在 1st节点,路径 - /etc/clickhouse-server/config.d/

<clickhouse>
    <distributed_ddl>
        <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>
    <macros>
        <cluster>test_cluster_two_shards_localhost</cluster>
        <replica>replica1</replica>
        <shard>1</shard>
    </macros>
</clickhouse>

这是 macros.xml 我在第二个节点,路径 - /etc/clickhouse-server/config.d/

<clickhouse>
    <distributed_ddl>
        <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>
    <macros>
        <cluster>test_cluster_two_shards_localhost</cluster>
        <replica>replica2</replica>
        <shard>1</shard>
    </macros>
</clickhouse>

此IS use-keeper.xml 我在每个节点上使用的文件,路径 - /etc/clickhouse-server/config.d/

<clickhouse>
    <zookeeper>
        <node index="1">
            <host>clickhouse01</host>
            <port>9181</port>
        </node>
        <node index="2">
            <host>clickhouse02</host>
            <port>9181</port>
        </node>
    </zookeeper>
</clickhouse>

我可以看到预期的群集 system.clusters system.clusers.clusters询问

但我没有具有 system.zookeeper system.zookeeper Query

我也试图尝试检查守护者是否正在运行 Echo Ruok | NC 127.0.0.1 9181 - 没有答案。

参考:

  1. ​=“ nofollow noreferrer”> https://mrkaran.dev/posts/clickhouse-replication/

I'm trying to set up and test replication via clickhouse-keeper.

This is my docker.compose.yaml

version: "3.7"

services:
  clickhouse01:
    image: yandex/clickhouse-server
    container_name: clickhouse01
    hostname: clickhouse01
    ports:
      - 8811:8123
      - 9011:9000
    volumes:
      - "D:/clichhouse-data/volume1:/var/lib/clickhouse"

  clickhouse02:
    image: yandex/clickhouse-server
    hostname: clickhouse02
    container_name: clickhouse02
    ports:
      - 8812:8123
      - 9012:9000
    volumes:
      - "D:/clichhouse-data/volume2:/var/lib/clickhouse"

This is remote_servers section that I'm using on each node in /etc/clickhouse-server/config.xml

<remote_servers>
        <test_cluster_two_shards_localhost>
             <shard>
                 <replica>
                     <host>clickhouse01</host>
                     <port>9000</port>
                 </replica>
                 <replica>
                    <host>clickhouse02</host>
                    <port>9000</port>
                </replica>
             </shard>
        </test_cluster_two_shards_localhost>
    </remote_servers>

This is keeper.xml file that I'm using on the 1st node, path - /etc/clickhouse-server/config.d/:

<clickhouse_keeper>
    <keeper_server>
        <tcp_port>9181</tcp_port>
        <server_id>1</server_id>
        <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <raft_logs_level>trace</raft_logs_level>
        </coordination_settings>

        <raft_configuration>
            <server>
                <id>1</id>
                <hostname>clickhouse01</hostname>
                <port>9234</port>
            </server>
            <server>
                <id>2</id>
                <hostname>clickhouse02</hostname>
                <port>9234</port>
            </server>
        </raft_configuration>
    </keeper_server>
</clickhouse_keeper>

This is keeper.xml file that I'm using on the 2nd node, path - /etc/clickhouse-server/config.d/:

<clickhouse_keeper>
    <keeper_server>
        <tcp_port>9181</tcp_port>
        <server_id>2</server_id>
        <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <raft_logs_level>trace</raft_logs_level>
        </coordination_settings>

        <raft_configuration>
            <server>
                <id>1</id>
                <hostname>clickhouse01</hostname>
                <port>9234</port>
            </server>
            <server>
                <id>2</id>
                <hostname>clickhouse02</hostname>
                <port>9234</port>
            </server>
        </raft_configuration>
    </keeper_server>
</clickhouse_keeper>

This is macros.xml file that I'm using on the 1st node, path - /etc/clickhouse-server/config.d/:

<clickhouse>
    <distributed_ddl>
        <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>
    <macros>
        <cluster>test_cluster_two_shards_localhost</cluster>
        <replica>replica1</replica>
        <shard>1</shard>
    </macros>
</clickhouse>

This is macros.xml file that I'm using on the 2nd node, path - /etc/clickhouse-server/config.d/:

<clickhouse>
    <distributed_ddl>
        <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>
    <macros>
        <cluster>test_cluster_two_shards_localhost</cluster>
        <replica>replica2</replica>
        <shard>1</shard>
    </macros>
</clickhouse>

This is use-keeper.xml file that I'm using on each node, path - /etc/clickhouse-server/config.d/:

<clickhouse>
    <zookeeper>
        <node index="1">
            <host>clickhouse01</host>
            <port>9181</port>
        </node>
        <node index="2">
            <host>clickhouse02</host>
            <port>9181</port>
        </node>
    </zookeeper>
</clickhouse>

I can see expected cluster in system.clusters table system.clusters query

But I don't have system.zookeeper table system.zookeeper query

I also tried to check if keeper is running by echo ruok | nc 127.0.0.1 9181 - no answer.

References:

  1. https://kb.altinity.com/altinity-kb-setup-and-maintenance/altinity-kb-zookeeper/clickhouse-keeper/
  2. https://mrkaran.dev/posts/clickhouse-replication/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2025-02-09 00:54:22

解决。

我的错误是,我在运行容器后通过以下方式使用 cp 命令复制了整个配置:
docker cp'C:\ users \ {user} \ desktop \ ch cluster \ ch cluster \ node-1 \ config.xml'clickhouse01:/etc/clickhouse-server

我认为我需要运行使用默认配置,请单击“ server” ,然后在应用新配置后重新启动 clickhouse-server 内部容器。

因此,这是我理解如何应用和更改配置的问题。

更改:

  1. 我将本地放置( d:/clichhouse-data/node-1 )都需要配置( keeper.xml macros.xml 和等等。)
  2. 更新 docker-compose.yaml 文件以下方式:
version: "3.7"

services:
  clickhouse01:
    image: yandex/clickhouse-server
    container_name: clickhouse01
    hostname: clickhouse01
    ports:
      - 8811:8123
      - 9011:9000
      - 9181:9181
    volumes:
      - type: volume
        source: clickhouse01
        target: /var/lib/clickhouse
      - "D:/clichhouse-data/node-1/config.xml:/etc/clickhouse-server/config.xml"
      - "D:/clichhouse-data/node-1:/etc/clickhouse-server/config.d/"

  clickhouse02:
    image: yandex/clickhouse-server
    hostname: clickhouse02
    container_name: clickhouse02
    ports:
      - 8812:8123
      - 9012:9000
      - 9182:9181
    volumes:
      - type: volume
        source: clickhouse02
        target: /var/lib/clickhouse
      - "D:/clichhouse-data/node-2/config.xml:/etc/clickhouse-server/config.xml"
      - "D:/clichhouse-data/node-2:/etc/clickhouse-server/config.d/"
      
volumes:
  clickhouse01:
  clickhouse02:

因此,在启动上更新了配置。

Resolved.

My mistake was that I copied the entire configuration after running the containers by using cp command in the following way:
docker cp 'C:\Users\{user}\Desktop\CH cluster\node-1\config.xml' clickhouse01:/etc/clickhouse-server

I thought that I need to run clickhouse-server with default configuration and then restart the clickhouse-server inside container after applying new configuration.

So that, it was the issue with my understanding how I should apply and change configuration.

Changes:

  1. I placed locally (D:/clichhouse-data/node-1) all need configs (keeper.xml, macros.xml and etc.)
  2. Updated docker-compose.yaml file in the following way:
version: "3.7"

services:
  clickhouse01:
    image: yandex/clickhouse-server
    container_name: clickhouse01
    hostname: clickhouse01
    ports:
      - 8811:8123
      - 9011:9000
      - 9181:9181
    volumes:
      - type: volume
        source: clickhouse01
        target: /var/lib/clickhouse
      - "D:/clichhouse-data/node-1/config.xml:/etc/clickhouse-server/config.xml"
      - "D:/clichhouse-data/node-1:/etc/clickhouse-server/config.d/"

  clickhouse02:
    image: yandex/clickhouse-server
    hostname: clickhouse02
    container_name: clickhouse02
    ports:
      - 8812:8123
      - 9012:9000
      - 9182:9181
    volumes:
      - type: volume
        source: clickhouse02
        target: /var/lib/clickhouse
      - "D:/clichhouse-data/node-2/config.xml:/etc/clickhouse-server/config.xml"
      - "D:/clichhouse-data/node-2:/etc/clickhouse-server/config.d/"
      
volumes:
  clickhouse01:
  clickhouse02:

And as a result configuration updated on the startup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文