17_clickhouse分布式集群部署
23.ClickHouse分布式集群部署
23.1.集群部署
23.1.1.準(zhǔn)備工作
節(jié)點(diǎn)規(guī)劃:
| clickhouse1 | 192.168.106.103 | shard1 | 副本1 |
| clickhouse2 | 192.168.106.104 | shard1 | 副本2 |
| clickhouse3 | 192.168.106.105 | shard2 | 副本1 |
| clickhouse4 | 192.168.106.106 | shard2 | 副本2 |
規(guī)劃4個(gè)節(jié)點(diǎn), 2個(gè)分片, 每個(gè)分片2個(gè)副本。 分片1的副本在主機(jī)clickhouse1和clickhouse2上, 2分片的副本在主機(jī)clickhouse3和clickhouse4上。
操作系統(tǒng)準(zhǔn)備工作:
(1)、修改主機(jī)名
hostname按照上面主機(jī)名進(jìn)行修改。
(2)、關(guān)閉防火墻、selinux等。
(3)、配置/etc/hosts
必須在/etc/hosts配置主機(jī)名和ip地址映射關(guān)系, 否則副本之間的數(shù)據(jù)不能同步。
2 安裝配置zookeeper
下載zookeeper,zookeeper版本要求3.4.5以上。
將conf目錄下的zoo_sample.cfg復(fù)制一份,命名為:zoo.cfg
環(huán)境配置:
Zookeeper的配置:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/root/apache-zookeeper-3.6.2-bin/data dataLogDir=/root/apache-zookeeper-3.6.2-bin/log # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1## Metrics Providers # # https://prometheus.io Metrics Exporter #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider #metricsProvider.httpPort=7000 #metricsProvider.exportJvmInfo=true上面配置目錄需要手工創(chuàng)建。
然后啟動(dòng)zookeeper即可。
啟動(dòng)命令:
3 在所有的主機(jī)安裝clickhouse
4 修改clickhouse的網(wǎng)絡(luò)相關(guān)配置
修改配置文件:/etc/clickhouse-server/config.xml
打開以下注釋,并做相關(guān)修改:
clickhouse1上的修改如下:
<listen_host>::1</listen_host> <listen_host>192.168.106.103</listen_host>Clickhouse2上的修改如下:
<listen_host>::1</listen_host> <listen_host>192.168.106.104</listen_host>Clickhouse3上的修改如下:
<listen_host>::1</listen_host> <listen_host>192.168.106.105</listen_host>Clickhouse4上的修改如下:
<listen_host>::1</listen_host> <listen_host>192.168.106.106</listen_host>5 增加配置文件:/etc/metrika.xml
clickhouse1的配置如下:
Clickhouse2的配置如下:
<?xml version="1.0" encoding="utf-8"?><yandex> <clickhouse_remote_servers> <mycluster> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.103</host> <port>9000</port> </replica> <replica> <host>192.168.106.104</host> <port>9000</port> </replica> </shard> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.105</host> <port>9000</port> </replica> <replica> <host>192.168.106.106</host> <port>9000</port> </replica> </shard> </mycluster> </clickhouse_remote_servers> <zookeeper-servers> <node index="1"> <host>192.168.106.103</host> <port>2181</port> </node> </zookeeper-servers> <macros> <layer>01</layer> <shard>01</shard> <replica>192.168.106.104</replica></macros> </yandex>Clickhouse3的配置如下:
<?xml version="1.0" encoding="utf-8"?><yandex> <clickhouse_remote_servers> <mycluster> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.103</host> <port>9000</port> </replica> <replica> <host>192.168.106.104</host> <port>9000</port> </replica> </shard> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.105</host> <port>9000</port> </replica> <replica> <host>192.168.106.106</host> <port>9000</port> </replica> </shard> </mycluster> </clickhouse_remote_servers> <zookeeper-servers> <node index="1"> <host>192.168.106.103</host> <port>2181</port> </node> </zookeeper-servers> <macros> <layer>01</layer> <shard>02</shard> <replica>192.168.106.105</replica> </macros> </yandex>Clickhouse4的配置如下:
<?xml version="1.0" encoding="utf-8"?><yandex> <clickhouse_remote_servers> <mycluster> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.103</host> <port>9000</port> </replica> <replica> <host>192.168.106.104</host> <port>9000</port> </replica> </shard> <shard> <internal_replication>true</internal_replication> <replica> <host>192.168.106.105</host> <port>9000</port> </replica> <replica> <host>192.168.106.106</host> <port>9000</port> </replica> </shard> </mycluster> </clickhouse_remote_servers> <zookeeper-servers> <node index="1"> <host>192.168.106.103</host> <port>2181</port> </node> </zookeeper-servers> <macros> <layer>01</layer> <shard>02</shard> <replica>192.168.106.106</replica> </macros> </yandex>其中如下這段配置在每個(gè)節(jié)點(diǎn)是不相同的:
<macros> <layer>01</layer> <shard>01</shard> <replica>192.168.106.103</replica> </macros>layer表示分層, shard表示分片的編號(hào), 按照配置順序從1開始。這里的01表示第一個(gè)分片。 replica配置副本的標(biāo)識(shí), 這里配置為本機(jī)的主機(jī)名。 使用這三個(gè)參數(shù)可以唯一表示一個(gè)副本分片。 這里表示layer為01的分片1的副本,副本標(biāo)識(shí):192.168.106.103。
配置完成后, 在每個(gè)節(jié)點(diǎn)啟動(dòng)ClickHouse服務(wù)。
systemctl restart clickhouse-server
5 查看系統(tǒng)表
clickhouse1 :) select * from system.clusters where cluster='mycluster';SELECT * FROM system.clusters WHERE cluster = 'mycluster'┌─cluster───┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name───────┬─host_address────┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─estimated_recovery_time─┐ │ mycluster │ 1 │ 1 │ 1 │ 192.168.106.103 │ 192.168.106.103 │ 9000 │ 1 │ default │ │ 0 │ 0 │ │ mycluster │ 1 │ 1 │ 2 │ 192.168.106.104 │ 192.168.106.104 │ 9000 │ 0 │ default │ │ 0 │ 0 │ │ mycluster │ 2 │ 1 │ 1 │ 192.168.106.105 │ 192.168.106.105 │ 9000 │ 0 │ default │ │ 0 │ 0 │ │ mycluster │ 2 │ 1 │ 2 │ 192.168.106.106 │ 192.168.106.106 │ 9000 │ 0 │ default │ │ 0 │ 0 │ └───────────┴───────────┴──────────────┴─────────────┴─────────────────┴─────────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘4 rows in set. Elapsed: 0.005 sec. clickhouse1 :)總結(jié)
以上是生活随笔為你收集整理的17_clickhouse分布式集群部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 泰米时空神武(泰米时空)
- 下一篇: 蜡笔小新2014剧场版再见了日本版(蜡笔