Docker Compose V2 安装 ClickHouse v20.6.8.5 经验分享

前言

ClickHouse 是一款开源的分布式列式数据库管理系统,专门设计用于高性能的大数据分析和查询。
目前项目中用到的一个场景是将mongo的数据同步到clickhouse,使用clickhouse做报表,后续也将分享同步和使用方案

  • 使用 Docker Compose 部署单机版,小项目和自己测试够用了,生产使用集群,基于此方案后续有需要我再尝试整理

安装

  • 安装目录:/app/clickhouse
  • 镜像:yandex/clickhouse-server:20.6.8.5
  • 版本: v20.6.8.5
  • 配置文件文档:配置文件
  • 端口说明:Network ports ,单机部署可以就暴露 8123(连接),9363(prometheus );ps:如果使用 Archery v1.10 连接需要使用 9000 端口

获取默认配置文件

默认配置文件: config.xml, users.xml

  1. 从容器内拷贝配置文件到容器外部主机
    (创建 work 目录,进入运行的 clickhouse 容器后会将默认的配置文件(config.xml, users.xml)复制到 work 目录)
    • 创建容器获取容器内的默认配置文件
      mkdir ./work
      docker run -it --rm --entrypoint=/bin/bash -v ./work:/work --privileged=true --user=root yandex/clickhouse-server:20.6.8.5
      进入容器后复制配置到work文件夹
      cp -r /etc/clickhouse-server/* /work
      exit
      
  2. ./work/config.xml
    • <?xml version="1.0"?>
      <!--
        NOTE: User and query level settings are set up in "users.xml" file.
        If you have accidentially specified user-level settings here, server won't start.
        You can either move the settings to the right place inside "users.xml" file
         or add <skip_check_for_incorrect_settings>1</skip_check_for_incorrect_settings> here.
      -->
      <yandex>
          <logger>
              <!-- Possible levels: https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/Logger.h#L105 -->
              <level>trace</level>
              <log>/var/log/clickhouse-server/clickhouse-server.log</log>
              <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
              <size>1000M</size>
              <count>10</count>
              <!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
      
              <!-- Per level overrides (legacy):
      
              For example to suppress logging of the ConfigReloader you can use:
              NOTE: levels.logger is reserved, see below.
              -->
              <!--
              <levels>
                <ConfigReloader>none</ConfigReloader>
              </levels>
              -->
      
              <!-- Per level overrides:
      
              For example to suppress logging of the RBAC for default user you can use:
              (But please note that the logger name maybe changed from version to version, even after minor upgrade)
              -->
              <!--
              <levels>
                <logger>
                  <name>ContextAccess (default)</name>
                  <level>none</level>
                </logger>
                <logger>
                  <name>DatabaseOrdinary (test)</name>
                  <level>none</level>
                </logger>
              </levels>
              -->
          </logger>
      
          <send_crash_reports>
              <!-- Changing <enabled> to true allows sending crash reports to -->
              <!-- the ClickHouse core developers team via Sentry https://sentry.io -->
              <!-- Doing so at least in pre-production environments is highly appreciated -->
              <enabled>false</enabled>
              <!-- Change <anonymize> to true if you don't feel comfortable attaching the server hostname to the crash report -->
              <anonymize>false</anonymize>
              <!-- Default endpoint should be changed to different Sentry DSN only if you have -->
              <!-- some in-house engineers or hired consultants who're going to debug ClickHouse issues for you -->
              <endpoint>https://[email protected]/5226277</endpoint>
          </send_crash_reports>
      
          <!--display_name>production</display_name--> <!-- It is the name that will be shown in the client -->
          <http_port>8123</http_port>
          <tcp_port>9000</tcp_port>
          <mysql_port>9004</mysql_port>
          <!-- For HTTPS and SSL over native protocol. -->
          <!--
          <https_port>8443</https_port>
          <tcp_port_secure>9440</tcp_port_secure>
          -->
          <!-- Used with https_port and tcp_port_secure. Full ssl options list: https://github.com/ClickHouse-Extras/poco/blob/master/NetSSL_OpenSSL/include/Poco/Net/SSLManager.h#L71 -->
          <openSSL>
              <server> <!-- Used for https server AND secure tcp port -->
                  <!-- openssl req -subj "/CN=localhost" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout /etc/clickhouse-server/server.key -out /etc/clickhouse-server/server.crt -->
                  <certificateFile>/etc/clickhouse-server/server.crt</certificateFile>
                  <privateKeyFile>/etc/clickhouse-server/server.key</privateKeyFile>
                  <!-- openssl dhparam -out /etc/clickhouse-server/dhparam.pem 4096 -->
                  <dhParamsFile>/etc/clickhouse-server/dhparam.pem</dhParamsFile>
                  <verificationMode>none</verificationMode>
                  <loadDefaultCAFile>true</loadDefaultCAFile>
                  <cacheSessions>true</cacheSessions>
                  <disableProtocols>sslv2,sslv3</disableProtocols>
                  <preferServerCiphers>true</preferServerCiphers>
              </server>
      
              <client> <!-- Used for connecting to https dictionary source and secured Zookeeper communication -->
                  <loadDefaultCAFile>true</loadDefaultCAFile>
                  <cacheSessions>true</cacheSessions>
                  <disableProtocols>sslv2,sslv3</disableProtocols>
                  <preferServerCiphers>true</preferServerCiphers>
                  <!-- Use for self-signed: <verificationMode>none</verificationMode> -->
                  <invalidCertificateHandler>
                      <!-- Use for self-signed: <name>AcceptCertificateHandler</name> -->
                      <name>RejectCertificateHandler</name>
                  </invalidCertificateHandler>
              </client>
          </openSSL>
      
          <!-- Default root page on http[s] server. For example load UI from https://tabix.io/ when opening http://localhost:8123 -->
          <!--
          <http_server_default_response><![CDATA[<html ng-app="SMI2"><head><base href="http://ui.tabix.io/"></head><body><div ui-view="" class="content-ui"></div><script src="http://loader.tabix.io/master.js"></script></body></html>]]></http_server_default_response>
          -->
      
          <!-- Port for communication between replicas. Used for data exchange. -->
          <interserver_http_port>9009</interserver_http_port>
      
          <!-- Hostname that is used by other replicas to request this server.
               If not specified, than it is determined analoguous to 'hostname -f' command.
               This setting could be used to switch replication to another network interface.
            -->
          <!--
          <interserver_http_host>example.yandex.ru</interserver_http_host>
          -->
      
          <!-- Listen specified host. use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere. -->
          <!-- <listen_host>::</listen_host> -->
          <!-- Same for hosts with disabled ipv6: -->
          <!-- <listen_host>0.0.0.0</listen_host> -->
      
          <!-- Default values - try listen localhost on ipv4 and ipv6: -->
          <!--
          <listen_host>::1</listen_host>
          <listen_host>127.0.0.1</listen_host>
          -->
          <!-- Don't exit if ipv6 or ipv4 unavailable, but listen_host with this protocol specified -->
          <!-- <listen_try>0</listen_try> -->
      
          <!-- Allow listen on same address:port -->
          <!-- <listen_reuse_port>0</listen_reuse_port> -->
      
          <!-- <listen_backlog>64</listen_backlog> -->
      
          <max_connections>4096</max_connections>
          <keep_alive_timeout>3</keep_alive_timeout>
      
          <!-- Maximum number of concurrent queries. -->
          <max_concurrent_queries>100</max_concurrent_queries>
      
          <!-- Maximum memory usage (resident set size) for server process.
               Zero value or unset means default. Default is "max_server_memory_usage_to_ram_ratio" of available physical RAM.
               If the value is larger than "max_server_memory_usage_to_ram_ratio" of available physical RAM, it will be cut down.
      
               The constraint is checked on query execution time.
               If a query tries to allocate memory and the current memory usage plus allocation is greater
                than specified threshold, exception will be thrown.
      
               It is not practical to set this constraint to small values like just a few gigabytes,
                because memory allocator will keep this amount of memory in caches and the server will deny service of queries
### Docker V24 和 Docker Compose V2 安装指南 #### 一、Docker V24 的安装安装 Docker V24,需确保操作系统支持该版本并满足其依赖条件。以下是通用的安装方法: 对于基于 Debian/Ubuntu 的系统: ```bash # 更新 apt 软件包索引 sudo apt-get update # 安装必要的软件包以便 apt 可以通过 HTTPS 使用存储库 sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release # 添加 Docker 的官方 GPG 密钥 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # 设置稳定的存储库 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # 再次更新 apt 包索引 sudo apt-get update # 安装特定版本的 Docker Engine (假设目标版本为 v24.x) sudo apt-get install docker-ce=5:24.* docker-ce-cli=5:24.* containerd.io ``` 对于基于 RHEL/CentOS 的系统: ```bash # 安装所需的包来启用 yum 模块 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 # 添加 Docker 的官方仓库 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 列出可用版本并选择具体版本号(如 24.x) sudo yum list docker-ce --showduplicates | sort -r # 安装指定版本的 Docker CE sudo yum install -y docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io ``` 完成以上操作后,启动 Docker 并验证安装是否成功: ```bash sudo systemctl start docker sudo docker version ``` 如果需要升级到最新版,则可以运行 `apt` 或 `yum` 升级命令。 --- #### 二、Docker Compose V2安装 Docker Compose V2 是作为独立插件集成到 Docker CLI 中的一部分。以下是推荐的安装方式: ##### 方法 1:通过 Daocloud 加速下载 此方法适用于国内网络环境较差的情况。 ```bash # 创建必要目录结构 DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} mkdir -p $DOCKER_CONFIG/cli-plugins # 下载对应平台的二进制文件至 cli-plugins 目录下 curl -SL https://get.daocloud.io/docker/compose/releases/download/v2.3.4/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose # 修改可执行权限 chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose # 验证安装是否成功 docker compose version ``` ##### 方法 2:直接从 GitHub 获取 国际用户可以直接访问 GitHub Release 页面获取最新稳定版链接。 ```bash # 替换 URL 地址中的版本号为实际需求的目标版本 curl -SL https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose # 同样赋予执行权限并测试功能 chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose docker compose version ``` 注意:上述路径 `$HOME/.docker/cli-plugins` 是默认配置位置;若自定义了其他路径,请调整相应变量设置[^3]。 --- #### 总结 无论是 Docker 还是 Docker Compose,在安装过程中都应关注系统的兼容性和依赖关系。此外,建议定期查阅官方文档以获得最权威的信息补充[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值