CentOS 7 安装分布式ClickHouse(3台节点)

CentOS7-之安装分布式Click-House(3台节点)

0 前言

本文主要介绍如何在CentOS7操作系统上通过.tgz包的方式安装分布式的ClickHouse集群。

安装方式有很多种。

  • rpm包安装
  • tgz包安装
  • 源码编译安装
  • and so on …

1 前提准备

在安装之前首先需要在操作系统上进行相关的环境准备及配置,这些环境准备需要在每个节点上执行

1.1 修改系统文件的限制

首先分别修改以下2个文件,必须是root权限执行,如果是其它用户必须在sudoer中配置管理员权限。

  • sudo vim /etc/security/limits.conf
  • sudo vim /etc/security/limits.d/20-nproc.conf
# 放开系统同时产生的文件数量的限制,分别在以上2个文件末尾添加该内容
* soft nofile 65536 #--限制的文件个数
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072

# 添加完之后等待重启,之后使用以下命令进行验证
ulimit -n 或者ulimit -a 
>> 65536 # 显示这个结果即为成功

1.2 关闭selinux的强制守护

vim /etc/selinux/config

#将文件中的forcexx修改成disable,等待重启
xxxxxx=disable

1.3 关闭防火墙

# 查看防火墙的运行状态
firewall-cmd --state
> running
# 临时关闭防火墙
systemctl status firewalld.service
> running
systemctl list-unit-files|grep firewalld.service
> firewalld.service   disabled
# 永久关闭防火墙,防止开机自启动
systemctl stop firewalld.service #停止防火墙
systemctl disable firewalld.service #防止开机启动防火墙

1.4 统一重启节点

开机之后就okay了,老babe们。

2 分布式安装

2.1 下载安装包并解压安装

下载路径:https://repo.clickhouse.tech/tgz

clickhouse-common-static-20.2.1.2177.tgz    
clickhouse-common-static-dbg-20.2.1.2177.tgz    
clickhouse-server-20.2.1.2177.tgz               
clickhouse-client-20.2.1.2177.tgz   

然后分别解压到指定目录,3台节点都需要操作。

tar -zxvf *.tgz -C /opt/module/clickhouse/

然后分别进行初始化安装,按照顺序执行以下操作。

cd /opt/module/clickhouse/
#进入解压文件夹之后顺序执行以下操作
sudo clickhouse-common-static-20.2.1.2177/install/doinst.sh
sudo clickhouse-common-static-dbg-20.2.1.2177/install/doinst.sh
sudo clickhouse-server-20.2.1.2177/install/doinst.sh
sudo clickhouse-client-20.2.1.2177/install/doinst.sh

2.2 核心配置

需要进行一些核心的配置才能启动分布式的ClickHouse集群

  • sudo vim /etc/clickhouse-server/config.xml
  • sudo vim /etc/metrika.xml

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

<!--0 创建数据存储目录 -->
mkdir /opt/module/clickhouse/data

<!--1 修改数据存放路径,以及监控权限放开-->
<path>/opt/module/clickhouse/data/</path>

<!--2 放开外部访问权限-->
<listen_host>::</listen_host>
<!--<listen_host>::1</listen_host>-->
<!--<listen_host>127.0.0.1</listen_host>-->

2.2.2 创建外置的配置文件/etc/metrika.xml

<!--vim /etc/metrika.xml-->

<yandex>
    <clickhouse_remote_servers>
        <perftest_3shards_1replicas>
            <shard>
            	<internal_replication>true</internal_replication>
                <replica>
                <host>shufang101</host>
                <port>9000</port>
                </replica>
            </shard>
            <shard>
                <replica>
                    <internal_replication>true</internal_replication>
                    <host>shufang102</host>
                    <port>9000</port>
                </replica>
            </shard>
                <shard>
                <internal_replication>true</internal_replication>
                <replica>
                <host>shufang103</host>
                <port>9000</port>
                </replica>
            </shard>
        </perftest_3shards_1replicas>
    </clickhouse_remote_servers>

    <!--zookeeper相关配置-->
    <zookeeper-servers>
        <node index="1">
            <host>shufang101</host>
            <port>2182</port>
        </node>
        <node index="2">
            <host>shufang102</host>
            <port>2182</port>
        </node>
        <node index="3">
            <host>shufang103</host>
            <port>2182</port>
        </node>
    </zookeeper-servers>
	<!-- 三台节点唯一不同的配置,与节点ip一致-->
    <macros>
    <replica>shufang102</replica>
    </macros>

    <networks>
    <ip>::/0</ip>
    </networks>

    <clickhouse_compression>
        <case>
            <min_part_size>10000000000</min_part_size>
            <min_part_size_ratio>0.01</min_part_size_ratio>
            <method>lz4</method>
        </case>
    </clickhouse_compression>
</yandex>
<!--参考博客:https://www.cnblogs.com/jiashengmei/p/11991243.html-->

2.2.3 验证集群的可行性

  • 首先启动ZK集群
  • 然后分别启动clickhouse-server
sudo service clickhouse-server start
sudo clickhouse-client [-m] [--query] ....

# 查询ClickHouse的系统元数据表`system.clusters`,验证集群节点是否一致
SELECT *
FROM system.clusters

┌─cluster───────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name──┬─host_address───┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─estimated_recovery_time─┐
│ perftest_3shards_1replicas        │         1 │            1 │           1 │ shufang101 │ 192.168.93.101 │ 9000 │        0 │ default │                  │            0 │                       0 │
│ perftest_3shards_1replicas        │         2 │            1 │           1 │ shufang102 │ 192.168.93.102 │ 9000 │        1 │ default │                  │            0 │                       0 │
│ perftest_3shards_1replicas        │         3 │            1 │           1 │ shufang103 │ 192.168.93.103 │ 9000 │        0 │ default │                  │            0 │                       0 │
│ test_cluster_two_shards           │         1 │            1 │           1 │ 127.0.0.1  │ 127.0.0.1      │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_cluster_two_shards           │         2 │            1 │           1 │ 127.0.0.2  │ 127.0.0.2      │ 9000 │        0 │ default │                  │            0 │                       0 │
│ test_cluster_two_shards_localhost │         1 │            1 │           1 │ localhost  │ ::1            │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_cluster_two_shards_localhost │         2 │            1 │           1 │ localhost  │ ::1            │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_shard_localhost              │         1 │            1 │           1 │ localhost  │ ::1            │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_shard_localhost_secure       │         1 │            1 │           1 │ localhost  │ ::1            │ 9440 │        0 │ default │                  │            0 │                       0 │
│ test_unavailable_shard            │         1 │            1 │           1 │ localhost  │ ::1            │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_unavailable_shard            │         2 │            1 │           1 │ localhost  │ ::1            │    1 │        0 │ default │                  │            0 │                       0 │
└───────────────────────────────────┴───────────┴──────────────┴─────────────┴────────────┴────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘



版权声明:本文为shufangreal原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。