• docker for windonws--Windows 10 家庭中文版安装clickhouse 22.3版本及配置


    1. 拉取镜像

    docker pull clickhouse/clickhouse-server:22.3.11.12-alpine
    
    • 1

    2. clickhouse单机版

    2.1. 配置容器

    因为如下原因,需要将clickhouse的配置文件及数据目录复制到宿主机

    • 修改配置文件
    • 避免容器重启时,丢失数据文件
    #启动容器
    docker run -d --name ch-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server:22.3.11.12-alpine
    
    # 复制文件到宿主机
    docker cp ch-server:/etc/clickhouse-server D:/docker/ch/etc/clickhouse-server
    docker cp ch-server:/var/lib/clickhouse D:/docker/ch/data
    
    #停止容器
    docker stop ch-server
    
    # 再次启动容器
    docker run -d --name=single-ch-server -p 8123:8123 -p 9000:9000 -p 9009:9009 --ulimit nofile=262144:262144 -v D:/docker/ch/data:/var/lib/clickhouse:rw -v D:/docker/ch/etc/clickhouse-server:/etc/clickhouse-server:rw clickhouse/clickhouse-server:22.3.11.12-alpine
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    2.2. 测试jdbc连接

    启动成功后,使用DBeaver测试,用户名default,密码为空,则可以正常连接。
    在这里插入图片描述

    3.1 clickhouse集群版

    3.1. 修改集群配置

    • 将配置、日志放在ch01目录下
    • 修改 D:\docker\ch\ch01\etc\clickhouse-server下的config.xml中,删除 节点并添加如下信息
    	<include_from>/etc/clickhouse-server/metrika01.xmlinclude_from>
    	<remote_servers incl="clickhouse_remote_servers" optional="true"/>
    	<zookeeper incl="zookeeper_servers" optional="true"/>
    	<macros incl="macros" optional="true"/>
        
        <compression incl="clickhouse_compression">compression>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 新增metrika01.xml文件,内容如下:
      • 考虑到一台笔记本的资源比较有限,所以就安装单个节点的zk, clickhouse的集群也是2分片1副本的。
    
    <yandex>
        <clickhouse_remote_servers>
          <cluster01>
                <shard>
                    <internal_replication>trueinternal_replication>
    				<weight>1weight>
                    <replica>
                        <host>ch01host>
                        <port>9000port>
                        <user>defaultuser>
                        <password>password>
                    replica>
                shard>
    			<shard>
                    <internal_replication>trueinternal_replication>
    				<weight>1weight>
                    <replica>
                        <host>ch02host>
                        <port>9000port>
                        <user>defaultuser>
                        <password>password>
                    replica>
                shard>
    		cluster01>
        clickhouse_remote_servers>
    
        <macros>
            <layer>01layer>
            <shard>01shard>
            <replica>ch01replica>
        macros>
    
        <zookeeper_servers>
            <node index="1">
                <host>zk01host>
                <port>2181port>
            node>
        zookeeper_servers>
    
       <networks>
         <ip>::/0ip>
       networks>
    
      <clickhouse_compression>
        <case>
          <min_part_size>1073741824min_part_size>
          <min_part_size_ratio>0.01min_part_size_ratio>
          <method>lz4method>
        case>
      clickhouse_compression>
    yandex>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 节点ch02的配置:复制ch01目录,产生ch02目录
    • 修改metrika01.xml,将macros内容调整,其它配置与上面一致。
       <macros>
            <layer>01layer>
            <shard>02shard>
            <replica>ch02replica>
        macros>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    3.2. 编辑docker-compose.yml

    采用卷标的方式挂载数据

    version: '3.1'
    services:
      zookeeper:
        image: zookeeper:3.4.14
        ports:
          - "8181:2181"
          - "8182:2182"
        hostname: zk01
      ch01:
        image: clickhouse/clickhouse-server:22.3.11.12-alpine
        restart: on-failure
        container_name: ch01
        ports:
          - 9000:9000
          - 8123:8123
          - 9009:9009
        volumes:
          - ch1-data:/var/lib/clickhouse
          - D:/docker/ch/ch01/etc/clickhouse-server:/etc/clickhouse-server:rw
          - D:/docker/ch/ch01/log:/var/log/clickhouse-server:rw
        hostname: ch01
        ulimits:
          nofile:
            soft: 262144
            hard: 262144
        depends_on:
          - "zookeeper"
      ch02:
        image: clickhouse/clickhouse-server:22.3.11.12-alpine
        restart: on-failure
        container_name: ch02
        ports:
          - 9800:9000
          - 8823:8123
          - 9809:9009
        volumes:
          - ch2-data:/var/lib/clickhouse
          - D:/docker/ch/ch02/etc/clickhouse-server:/etc/clickhouse-server:rw
          - D:/docker/ch/ch02/log:/var/log/clickhouse-server:rw
        hostname: ch02
        ulimits:
          nofile:
            soft: 262144
            hard: 262144
        depends_on:
          - "zookeeper"
    volumes:
      ch1-data:
      ch2-data:
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    3.3. 启动CH集群

    docker-compose up -d
    
    • 1

    3.4. 测试

    create database test on cluster cluster01;
    
    use test;
    
    create table events_local on cluster cluster01 (
    	ID String,
    	EventType UInt8,
    	URL String,
    	EventTime DateTime
    ) ENGINE = MergeTree()
    PARTITION BY toStartOfDay(EventTime)
    ORDER BY (EventTime,EventType)
    SETTINGS index_granularity = 8192;
    
    create table events on cluster cluster01 as test.events_local ENGINE = Distributed('cluster01', 'test', 'events_local', rand());
    
    insert into events(ID,EventType,URL,EventTime) values ('11',1,'http://www.baidu.com','2021-12-20 12:00:00');
    insert into events(ID,EventType,URL,EventTime) values ('12',1,'http://www.baidu.com','2021-12-20 12:00:00');
    insert into events(ID,EventType,URL,EventTime) values ('13',1,'http://www.baidu.com','2021-12-20 12:00:00');
    insert into events(ID,EventType,URL,EventTime) values ('14',1,'http://www.baidu.com','2021-12-20 12:00:00');
    insert into events(ID,EventType,URL,EventTime) values ('15',1,'http://www.baidu.com','2021-12-20 12:00:00');
    insert into events(ID,EventType,URL,EventTime) values ('16',1,'http://www.baidu.com','2021-12-20 12:00:00');
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    4. 存在的解决问题

    4.1. Permission denied

    将Clickhouse的数据目录放在宿主机时,在插入数据时报如下错误,但如果不放在宿主机,则数据会丢失。

    Received exception from server (version 22.3.11):
    Code: 1001. DB::Exception: Received from localhost:9000. DB::Exception: std::__1::__fs::filesystem::filesystem_error: filesystem error: in rename: Permission denied [/var/lib/clickhouse/store/0d4/0d4a6f52-b3a6-4496-8174-e03ae9503321/tmp_insert_1639958400_1_1_0/] [/var/lib/clickhouse/store/0d4/0d4a6f52-b3a6-4496-8174-e03ae9503321/1639958400_1_1_0/]. (STD_EXCEPTION)
    
    • 1
    • 2
    • 采用将宿主机 路径直接挂载到本地,比较直观,但需要管理本地的路径,但这种方式在clickhouse写数据时,会报:Permission denied
    • 使用卷标的方式,比较简洁,但你不知道数据存在本地什么位置,但这种方式在clickhouse写数据时是正常的
      目前不清楚具体的原因,如果你知道,烦请告知。

    4.2. Ports are not available

    报错信息:Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:8848 -> 0.0.0.0:0: listen tcp 0.0.0.0:8848: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

    通过cmd命令查看哪些端口被禁用TCP协议
    netsh interface ipv4 show excludedportrange protocol=tcp

    将docker启动命令中的宿主机端口改成禁用之外的就可以了
    在这里插入图片描述

  • 相关阅读:
    基于Python医学院校二手书管理毕业设计-附源码201704
    Serializable序列化
    解决LabVIEW通过OPC Server读取PLC地址时的错误180121602
    代码发布方式
    C/S架构学习之多进程实现TCP并发服务器
    如何使用 Bing Image Creator 创建图像(DALL-E3)
    助力燃气安全运行:智慧燃气管网背景延展
    ARM汇编器所支持的伪操作 - 信息报告伪操作
    12.1 使用键盘鼠标监控钩子
    【ArcGIS Pro二次开发】(65):进出平衡SHP转TXT、TXT转SHP
  • 原文地址:https://blog.csdn.net/penriver/article/details/126458447