CentOS7 部署安装ClickHouse

发布于:2024-06-24 ⋅ 阅读:(138) ⋅ 点赞:(0)

一、什么是ClickHouse

ClickHouse 是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),使用C++语言编写,主要用于在线分析处理查询(OLAP),能够使用SQL查询实时生成分析数据报告。

OLAP场景需要在大型数据集上对具有以下特征的复杂分析查询进行实时响应:

  • 数据集可以是巨大的——数十亿或数万亿行
  • 数据组织在包含多列的表中
  • 只选择少数几列来回答任何特定的查询
  • 必须以毫秒或秒为单位返回结果

 ClickHouse官网:Fast Open-Source OLAP DBMS - ClickHouse

二、单机部署安装

建议使用官方预编译的rpm软件包,适用于CentOS、RedHat和所有其他基于rpm的Linux发行版。

设置RPM存储库

yum install -y yum-utils
yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo

安装ClickHouse服务器和客户端

yum install -y clickhouse-server clickhouse-client

启动ClickHouse服务器

systemctl enable clickhouse-server
systemctl start clickhouse-server
systemctl status clickhouse-server
clickhouse-client # or "clickhouse-client --password" if you set up a password.

修改配置文件

vim /etc/clickhouse-server/config.xml

把 <listen_host>::</listen_host> 的注释打开,这样的话才能让ClickHouse被除本机以外的服务器访问

在这个文件中,有ClickHouse的一些默认路径配置,比较重要的
数据文件路径:<path>/var/lib/clickhouse/</path>
日志文件路径:<log>/var/log/clickhouse-server/clickhouse-server.log</log>

启动Server

systemctl start clickhouse-server

使用client连接server

clickhouse-client -m

-m :可以在命令窗口输入多行命令

 安装完配置文件路径 /etc/clickhouse-*

 三、RPM包安装

rpm安装包地址:https://packages.clickhouse.com/rpm/

Packages
  • clickhouse-common-static:安装clickhouse编译的二进制文件
  • clickhouse-server:为clickhouse服务器创建一个软链接,并安装默认的服务器配置
  • clickhouse-client:为clickhouse客户端和其他与客户端相关的工具创建软链接。并安装客户端配置文件
  • clickhouse-common-static-dbg:安装ClickHouse编译的带有调试信息的二进制文件
  • clickhouse-keeper:用于在专用的ClickHouse Keeper节点上安装ClickHouse Keeper。如果您在与ClickHouse服务器相同的服务器上运行ClickHouse Keeper,则无需安装此软件包。安装ClickHouse Keeper和默认的ClickHouse Keeler配置文件

 安装包下载到自己制定路径

clickhouse-client-24.5.3.5.x86_64.rpm
clickhouse-common-static-24.5.3.5.x86_64.rpm
clickhouse-server-24.5.3.5.x86_64.rpm

 安装rpm

rpm -ivh clickhouse-*

 四、ClickHouse Keeper

ClickHouse 集群是需要使用Zookeeper去实现集群副本之间的同步,而ClickHouse Keeper基于Raft一致性算法开发的一款专门为ClickHouse设计的分布式一致性解决方案,旨在替代ZooKeeper作为ClickHouse集群的元数据存储与管理工具。

官方翻译:在生产环境中,我们强烈建议在专用节点上运行ClickHouse Keeper。在测试环境中,如果您决定在同一台服务器上运行ClickHouse Server和ClickHouse Keeper,则无需安装ClickHouse Keepper,因为它包含在ClickHouse服务器中。此命令仅在独立的ClickHouse Keeper服务器上需要。

单独安装ClickHouse Keeper

yum install -y clickhouse-keeper

启用并启动ClickHouse Keeper

systemctl enable clickhouse-keeper
systemctl start clickhouse-keeper
systemctl status clickhouse-keeper

ClickHouse-Keeper方式搭建CK集群

ClickHouse-Keeper嵌入式

嵌入式模式代表不需要额外部署和启动服务,在ClickHouse中配置启用,启动ClickHouse就可以启动嵌入式Keeper

修改 /etc/clickhouse-server/config.xml

将 /etc/clickhouse-keeper/keeper_config.xml 配置文件里的 <keeper_server>******</keeper_server> 加入clickhouse-serverconfig.xml里即可

<clickhouse>

# 省略其他...

...
    <keeper_server>
            <tcp_port>9181</tcp_port>

            <!-- Must be unique among all keeper serves -->
            <server_id>1</server_id>

            <log_storage_path>/var/lib/clickhouse/coordination/logs</log_storage_path>
            <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>

            <coordination_settings>
                <operation_timeout_ms>10000</operation_timeout_ms>
                <min_session_timeout_ms>10000</min_session_timeout_ms>
                <session_timeout_ms>100000</session_timeout_ms>
                <raft_logs_level>information</raft_logs_level>
                <compress_logs>false</compress_logs>
                <!-- All settings listed in https://github.com/ClickHouse/ClickHouse/blob/master/src/Coordination/CoordinationSettings.h -->
            </coordination_settings>

            <!-- enable sanity hostname checks for cluster configuration (e.g. if localhost is used with remote endpoints) -->
            <hostname_checks_enabled>true</hostname_checks_enabled>
            <raft_configuration>
                <server>
                    <id>1</id>
                    <!-- Internal port and hostname -->
                    <hostname>example1</hostname>
                    <port>9234</port>
                </server>
                <server>
                    <id>2</id>
                    <!-- Internal port and hostname -->
                    <hostname>example2</hostname>
                    <port>9234</port>
                </server>
                <server>
                    <id>3</id>
                    <!-- Internal port and hostname -->
                    <hostname>example3</hostname>
                    <port>9234</port>
                </server>

                <!-- Add more servers here -->

            </raft_configuration>
    </keeper_server>
...
   <zookeeper>
        <node>
            <host>example1</host>
            <port>2181</port>
        </node>
        <node>
            <host>example2</host>
            <port>2181</port>
        </node>
        <node>
            <host>example3</host>
            <port>2181</port>
        </node>
     </zookeeper>
</clickhouse>

启动直接是采用 clickhouse 的启动方式,systemctl start clickhouse-server(启动 clickhouse-server 新旧版有几种方式均可)

此外同样的部署多个服务节点,需调整 <zookeeper> 和 <server> 下的地址配置,设置合理的分片和副本