原來的集群沒有高可用而且配置很低,所有準備將一個3分片1副本集群遷到1分片2副本的高配置集群,數據量比較大。
雖然官方已經標記clickhouse-copier已經過時,但為了方便和高效還是用了copier,效果還挺好
以下是使用步驟:
- 服務器上下載copier解壓后,首先需要準備keeper.xml文件,目標端使用的是clickhouse-keeper,這里配置還是zookeeper但是不影響
<!-- config.xml -->
<clickhouse><logger><level>trace</level><size>100M</size><log>./log/clickhouse-copier/copier/log.log</log><errorlog>./log/clickhouse-copier/copier/log.err.log</errorlog><count>3</count></logger># 填入對應的 keeper的ip地址<zookeeper><node index="1"><host>172.23.3.44</host><port>9181</port></node><node index="2"><host>172.23.3.55</host><port>9181</port></node><node index="3"><host>172.23.3.66</host><port>9181</port></node></zookeeper></clickhouse>
- 準備遷移任務文件task_migrate_all.xml,可以將需要遷移的表放在一個文件,或者分成多個文件都可,但保證需要遷移的表在源集群所有節點都有,可以建空表來跳過檢查,否則會報錯
<clickhouse><remote_servers>##源集群地址<source_cluster><shard><internal_replication>false</internal_replication><replica><host>172.23.3.11</host> <port>9000</port><user>user_name</user><password>pwd</password></replica></shard><shard><internal_replication>false</internal_replication><replica><host>172.23.3.12</host> <port>9000</port><user>user_name</user><password>pwd</password></replica></shard><shard><internal_replication>false</internal_replication><replica><host>172.23.3.13</host> <port>9000</port><user>user_name</user><password>pwd</password></replica></shard></source_cluster>#目標集群地址<destination_cluster><shard><internal_replication>true</internal_replication><replica><host>172.23.3.44</host> <port>9000</port><user>user_name</user><password>pwd</password></replica><replica><host>172.23.3.55</host> <port>9000</port><user>user_name</user><password>pwd</password></replica></shard></destination_cluster></remote_servers># 并發線程<max_workers>12</max_workers>#對源庫只讀<settings_pull><readonly>1</readonly></settings_pull><!-- Setting used to insert (push) data to destination cluster tables --><settings_push><readonly>0</readonly></settings_push><settings><connect_timeout>3</connect_timeout><!-- Sync insert is set forcibly, leave it here just in case. --><distributed_foreground_insert>1</distributed_foreground_insert></settings># 需要遷移的表,可以tables里面可以寫多張表<tables><table_sms_send><cluster_pull>source_cluster</cluster_pull><database_pull>test_qwe</database_pull><table_pull>sms_send</table_pull><cluster_push>destination_cluster</cluster_push><database_push>test_qwe</database_push><table_push>sms_send</table_push># 因為是多副本,需要使用復制表,否則只有單節點有數據<engine>ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{cluster}/{shard}/{database}/{table}', '{replica}')PARTITION BY toYYYYMM(create_time)ORDER BY (id, phone_number, state, create_time)</engine># 1分片不需要分片鍵,這里設置為1<sharding_key>1</sharding_key></table_sms_send><table_use_car><cluster_pull>source_cluster</cluster_pull><database_pull>test_qwe</database_pull><table_pull>use_car</table_pull><cluster_push>destination_cluster</cluster_push><database_push>testqwe</database_push><table_push>use_car</table_push><engine>ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{cluster}/{shard}/{database}/{table}', '{replica}', add_time)ORDER BY (id, detail_id)</engine><sharding_key>1</sharding_key></table_use_car></tables></clickhouse>
- 在clickhouse-copier解壓目錄執行命令開始遷移 .
# 這里task-path表示keeper存儲的遷移任務路徑
/clickhouse-copier --config keeper.xml --task-path /clickhouse/copier_task/mig_test --task-file=task_migrate_all.xml