Title

clickhouse 20.5.4.40-2集群搭建

0 前置设置

host zk clickhouse
gcw1 3.4.14 20.5.4.40-2
gcw2 3.4.14 20.5.4.40-2
gcw3 3.4.14 20.5.4.40-2

1 下载

清华大学开源软件镜像站

clickhouse

若是下载慢,可以从清华镜像站下载,手动导入

[root@gcw3 clickhouseRpm]# pwd
/opt/src/clickhouseRpm
[root@gcw3 clickhouseRpm]# ll
total 121556
-rw-r--r-- 1 root root     76151 Nov  6 20:23 clickhouse-client-20.5.4.40-2.noarch.rpm
-rw-r--r-- 1 root root 121976643 Nov  6 20:23 clickhouse-common-static-20.5.4.40-2.x86_64.rpm
-rw-r--r-- 1 root root     98616 Nov  6 20:23 clickhouse-server-20.5.4.40-2.noarch.rpm
-rw-r--r-- 1 root root   2310911 Nov  6 20:23 clickhouse-test-20.5.4.40-2.noarch.rpm

2 安装

[root@gcw3 clickhouseRpm]# rpm -ivh clickhouse-* --force --nodeps
warning: clickhouse-client-20.5.4.40-2.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID e0c56bd4: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:clickhouse-common-static-20.5.4.4################################# [ 25%]
   2:clickhouse-client-20.5.4.40-2    ################################# [ 50%]
   3:clickhouse-server-20.5.4.40-2    ################################# [ 75%]
Created symlink from /etc/systemd/system/multi-user.target.wants/clickhouse-server.service to /etc/systemd/system/clickhouse-server.service.
Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
   4:clickhouse-test-20.5.4.40-2      ################################# [100%]

3 配置

默认安装路径 /etc/clickhouse-server

[root@gcw3 clickhouseRpm]# cd /etc/clickhouse-server/
[root@gcw3 clickhouse-server]# ll
total 48
drwxr-xr-x 2 root root     6 Nov  6 20:28 config.d
-rw-r--r-- 1 root root 28815 Aug  1  2020 config.xml
lrwxrwxrwx 1 root root    41 Nov  6 20:28 preprocessed -> /var/lib/clickhouse//preprocessed_configs
-rw-r--r-- 1 root root  5444 Aug  1  2020 server-test.xml
drwxr-xr-x 2 root root     6 Nov  6 20:28 users.d
-rw-r--r-- 1 root root  5328 Aug  1  2020 users.xml

3.1 数据存放目录

vi config.xml 176行左右

<path>/var/lib/clickhouse/</path>

3.2 zookeeper标签上面增加:集群配置信息

vi config.xml 333行左右

<include_from>/etc/clickhouse-server/config.d/metrika.xml</include_from>
<zookeeper incl="zookeeper-servers" optional="true" />

3.3 conf.d目录下metrika.xml配置

vi config.d/metrika.xml

添加下列配置

我这里主机名称是gcw1,gcw2,gcw3

注意port 9000端口是否会冲突

<yandex>
    <clickhouse_remote_servers>
        <perftest_3shards_1replicas>
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>gcw1</host>
                    <port>9000</port>
                </replica>
            </shard>
            <shard>
                <replica>
                    <internal_replication>true</internal_replication>
                    <host>gcw2</host>
                    <port>9000</port>
                </replica>
            </shard>
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>gcw3</host>
                    <port>9000</port>
                </replica>
            </shard>
        </perftest_3shards_1replicas>
    </clickhouse_remote_servers>
    <zookeeper-servers>
        <node index="1">
            <host>gcw1</host>
            <port>2181</port>
        </node>
        <node index="2">
            <host>gcw2</host>
            <port>2181</port>
        </node>
        <node index="3">
            <host>gcw3</host>
            <port>2181</port>
        </node>
    </zookeeper-servers>
    <macros>
        <shard>01</shard>
        <replica>gcw1</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>

3.4 conf.xml其他配置(暂时可以不修改)

名称 含义
logger 日志的存放路径
http_port 浏览器访问的端口,默认为8123
tcp_port tcp协议的传输端口
openSSL 一些ssl的认证配置文件
listen_host 如果我们要对外使用服务的话,此处需要修改成0.0.0.0

4 集群配置

主机gcw1和gcw2上配置和以上相同

5 启动

5.1 zookeeper启动

zk集群搭建

#启动命令  
zkServer.sh start
#状态查看  
zkServer.sh status

5.2 clickhuose启动

[root@gcw3 app]# systemctl start clickhouse-server
[root@gcw3 app]# systemctl status clickhouse-server
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
   Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-11-06 21:41:58 CST; 9s ago
------

5.3 设置为开机自动启动

systemctl enable clickhouse-server

5.4 设置关闭开机自动启动

systemctl disable clickhouse-server

6 测试

查看有哪些数据库

--p 指定端口

[root@gcw1 conf]# clickhouse-client -m
ClickHouse client version 20.5.4.40 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.5.4 revision 54435.

gcw1 :) show databases;
SHOW DATABASES
┌─name───────────────────────────┐
│ _temporary_and_external_tables │
│ default                        │
│ system                         │
└────────────────────────────────┘
3 rows in set. Elapsed: 0.002 sec. 

gcw1 :) quit
Bye.

6.2 查看有哪些主机

root@gcw1 clickhouse-server]# clickhouse-client  -m 
ClickHouse client version 20.5.4.40 (official build).
Connecting to localhost:19000 as user default.
Connected to ClickHouse server version 20.5.4 revision 54435.

gcw1 :) select distinct(host_name) from system.clusters;

SELECT DISTINCT host_name
FROM system.clusters

┌─host_name─┐
│ gcw1      │
│ gcw2      │
│ gcw3      │
│ 127.0.0.1 │
│ 127.0.0.2 │
│ localhost │
└───────────┘

6 rows in set. Elapsed: 0.002 sec. 

7 日志查看

[root@gcw1 clickhouse-server]# pwd
/var/log/clickhouse-server
[root@gcw1 clickhouse-server]# ll
total 452
-rw-r----- 1 clickhouse clickhouse    241 Nov  6 21:59 clickhouse-server.err.log
-rw-r----- 1 clickhouse clickhouse 340655 Nov  6 22:05 clickhouse-server.log
posted @ 2021-11-06 22:10  apeGcWell  阅读(134)  评论(0编辑  收藏  举报