Clickhouse集群搭建

clickhouse官網(wǎng),也會(huì)有集群搭建的內(nèi)容

搭建前的準(zhǔn)備

配置好防火墻以及搭建好zookeeper,這里就不做搭建,可自行查找攻略
首先取消打開(kāi)文件數(shù)限制,然后重啟不然不生效

[root@node02 ~]#  vim /etc/security/limits.conf
* soft nofile 65536 
* hard nofile 65536 
* soft nproc 131072 
* hard nproc 131072

安裝依賴,rpm離線安裝需要此依賴

[root@node02 ~]#  yum install -y libtool
[root@node02 ~]#  yum install -y *unixODBC*

備注 : 我這里用的root用戶,生產(chǎn)環(huán)境可不是root用戶哦


yum安裝

# yum 安裝 server 以及 client
 yum install -y clickhouse-server clickhouse-client
# 查看是否安裝完成
 yum list installed 'clickhouse*'
[root@node02 ~]#  yum list installed 'clickhouse*'
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: mirrors.cn99.com
 * updates: mirrors.163.com
已安裝的軟件包
clickhouse-client.x86_64                       20.8.3.18-1.el7                @Altinity_clickhouse
clickhouse-common-static.x86_64                20.8.3.18-1.el7                @Altinity_clickhouse
clickhouse-server.x86_64                       20.8.3.18-1.el7                @Altinity_clickhouse
clickhouse-server-common.x86_64                20.8.3.18-1.el7                @Altinity_clickhous
# 通過(guò) clickhouse service 來(lái)啟動(dòng),停止,clickhouse
service clickhouse-server start | stop | status | restart | ...
[root@node02 ~]# service clickhouse-server start
Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
DONE
# 進(jìn)入client
clickhouse-client
[root@node02 ~]# clickhouse-client 
ClickHouse client version 20.8.3.18.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.8.3 revision 54438.

到這里yum模式的就安裝完成了,當(dāng)然只是一個(gè)單節(jié)點(diǎn),后面會(huì)說(shuō)集群的搭建

集群搭建

集群搭建和單節(jié)點(diǎn)是差不多的,就是編寫(xiě)配置文件就可,首先在其他節(jié)點(diǎn)上安裝好clickhouse,然后執(zhí)行下面的步驟

# 1. 修改config.xml配置文件
vim /etc/clickhouse-server/config.xml
[root@node02 ~]# vim /etc/clickhouse-server/config.xml
# 進(jìn)入編輯后  /<listen_host> 回車(chē),找到這個(gè)位置,這個(gè)配置是用于,允許IP4和IP6源主機(jī)遠(yuǎn)程訪問(wèn)
     <listen_host>::</listen_host>
    <!-- Same for hosts with disabled ipv6: -->
    <!-- <listen_host>0.0.0.0</listen_host> -->
# 將注釋的內(nèi)容給打開(kāi)即可, 注意每臺(tái)節(jié)點(diǎn)都要更改
# 然后進(jìn)入到/etc目錄下創(chuàng)建metrika.xml文件即可
[root@node02 etc]# vim metrika.xml

vim metrika.xml內(nèi)容,我這里是四臺(tái)節(jié)點(diǎn),配置文件是這樣的,以后的文章中會(huì)記錄clickhouse的一些調(diào)優(yōu)內(nèi)容

<yandex>
# 集群配置
<clickhouse_remote_servers>
    <perftest_4shards_1replicas>
        <shard>
             <internal_replication>true</internal_replication>
            <replica>
                <host>node01</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <internal_replication>true</internal_replication>
                <host>node02</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>node03</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
             <internal_replication>true</internal_replication>
            <replica>
                <host>node04</host>
                <port>9000</port>
            </replica>
        </shard>
    </perftest_4shards_1replicas>   
</clickhouse_remote_servers>
# zk配置
<zookeeper-servers>
  <node index="1">
    <host>node01</host>
    <port>2181</port>
  </node>
  <node index="2">
    <host>node02</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>node03</host>
    <port>2181</port>
  </node> 
  <node index="4">
    <host>node04</host>
    <port>2181</port>
  </node>
</zookeeper-servers>
# 這個(gè)位置需要根據(jù)不同的節(jié)點(diǎn)來(lái)更改
<macros>
    <replica>node02</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>

然后將metrika.xml文件分發(fā)到其他的節(jié)點(diǎn),然后停止之前啟動(dòng)clickhouse,然后每臺(tái)節(jié)點(diǎn)啟動(dòng)服務(wù),對(duì)沒(méi)看錯(cuò),不需要在做什么事情了,他會(huì)自動(dòng)讀取這個(gè)文件,啟動(dòng)就行了

# 每臺(tái)節(jié)點(diǎn)啟動(dòng)完成了查看是否啟動(dòng)
[root@node02 etc]# ps -aux | grep clickhouse-server
clickho+ 244604  0.4  1.1 1971184 368656 ?      Ssl  18:57   0:09 clickhouse-server --daemon --pid-file=/var/run/clickhouse-server/clickhouse-server.pid --config-file=/etc/clickhouse-server/config.xml
root     248725  0.0  0.0 112824   980 pts/0    S+   19:36   0:00 grep --color=auto clickhouse-server
# 如過(guò)啟動(dòng)失敗可以去查看log ,log位置
[root@node02 clickhouse-server]# pwd
/var/log/clickhouse-server
[root@node02 clickhouse-server]# ll
總用量 864
-rw-r-----. 1 clickhouse clickhouse 154597 11月 25 18:17 clickhouse-server.err.log
-rw-r-----. 1 clickhouse clickhouse 720270 11月 25 19:37 clickhouse-server.log
-rw-r-----. 1 clickhouse clickhouse   5395 11月 25 18:57 stderr.log
-rw-r-----. 1 clickhouse clickhouse      0 11月 25 18:14 stdout.log
# 啟動(dòng)完成后我們進(jìn)入client ,說(shuō)明成功了
[root@node02 clickhouse-server]# clickhouse-client 
ClickHouse client version 20.8.3.18.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.8.3 revision 54438.
node02 :) 
# 查看集群信息,可以看到以下信息 
# perftest_4shards_1replicas這個(gè)是我們?cè)趍etrika.xml配置文件中配置的
node02 :) select * from 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_4shards_1replicas        │         1 │            1 │           1 │ node01    │ 192.168.2.217 │ 9000 │        0 │ default │                  │            0 │                       0 │
│ perftest_4shards_1replicas        │         2 │            1 │           1 │ node02    │ 192.168.2.202 │ 9000 │        1 │ default │                  │            0 │                       0 │
│ perftest_4shards_1replicas        │         3 │            1 │           1 │ node03    │ 192.168.2.203 │ 9000 │        0 │ default │                  │            0 │                       0 │
│ perftest_4shards_1replicas        │         4 │            1 │           1 │ node04    │ 192.168.2.218 │ 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 │ 127.0.0.1     │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_cluster_two_shards_localhost │         2 │            1 │           1 │ localhost │ 127.0.0.1     │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_shard_localhost              │         1 │            1 │           1 │ localhost │ 127.0.0.1     │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_shard_localhost_secure       │         1 │            1 │           1 │ localhost │ 127.0.0.1     │ 9440 │        0 │ default │                  │            0 │                       0 │
│ test_unavailable_shard            │         1 │            1 │           1 │ localhost │ 127.0.0.1     │ 9000 │        1 │ default │                  │            0 │                       0 │
│ test_unavailable_shard            │         2 │            1 │           1 │ localhost │ 127.0.0.1     │    1 │        0 │ default │                  │            0 │                       0 │
└───────────────────────────────────┴───────────┴──────────────┴─────────────┴───────────┴───────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘

到這里我們的clickhouse集群就搭建成功了,后面還會(huì)做一些優(yōu)化,現(xiàn)在的這個(gè)只適用于測(cè)試

rpm方式安裝可以參考這篇文章https://blog.csdn.net/gulugulu_gulu/article/details/105769647

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 滿目山河空念遠(yuǎn),落花風(fēng)雨更傷春。 ClickHouse概述 什么是ClickHouse? ClickHouse 是...
    淡淡的傷你閱讀 4,563評(píng)論 0 1
  • 閱讀此文,你將得到什么:ClickHouse安裝的2種方法,以及背后的坑一步步幫你實(shí)現(xiàn)ClickHouse從單機(jī)到...
    JackpGao閱讀 23,553評(píng)論 16 17
  • ClickHouse是一個(gè)用于聯(lián)機(jī)分析(OLAP)的列式數(shù)據(jù)庫(kù)管理系統(tǒng)(DBMS)??梢杂糜赑B級(jí)大數(shù)據(jù)實(shí)時(shí)分析,...
    codeMaster_閱讀 1,175評(píng)論 0 1
  • 環(huán)境準(zhǔn)備 準(zhǔn)備了4臺(tái)機(jī)器,Centos7.6,可以通過(guò)如下命令查看系統(tǒng)版本 配置hosts 編輯hosts文件,新...
    風(fēng)箏flying閱讀 2,870評(píng)論 0 0
  • 集群規(guī)劃 集群架構(gòu) 其中 Distribute 是指創(chuàng)建分布式表的機(jī)器,在此文章中是將 Distribute 單獨(dú)...
    李傳亮閱讀 22,310評(píng)論 11 13

友情鏈接更多精彩內(nèi)容