1)找到zookeeper主节点
zkServer.sh status
查看返回结果:
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leaderMode说明:
值为leader 代表当前节点为zookeeper的领导节点
2)停3个zookeeper的节点,生成zookeeper快照
3)(建议)启动 后再停止 zookeeper的领导节点,强制生成一致快照
4)使用clickhouse keeper-converter转换zookeeper快照
clickhouse keeper-converter --zookeeper-logs-dir /var/log/zklog/version-2 --zookeeper-snapshots-dir /var/log/zkdata/version-2 --output-dir /var/log/temp/keeper/snapshots
docker容器部署的话:
docker exec -it $(docker ps|grep clickhouse-node|awk '{print $1}') clickhouse keeper-converter --zookeeper-logs-dir /var/log/zklog/version-2 --zookeeper-snapshots-dir /var/log/zkdata/version-2 --output-dir /var/log/temp/keeper/snapshots
参数说明:--zookeeper-logs-dir 后跟zookeeper的日志目录
--zookeeper-snapshots-dir 后跟zookeeper的快照目录
--output-dir 后跟转换后的快照所在目录
备注: keeper-converter 是clickhouse中的一个转换工具
最新版本的 做了软链接,可以直接使用clickhouse-keeper-converter 命令
低版本clickhouse(例如:22.3.3.44 ,版本查看命令:clickhouse-client --version),keeper-converter工具未做软连接,需要使用clickhouse keeper-converter
5)将转换后的快照,复制到clickhouse的几台节点上
例如:/var/lib/clickhouse/coordination/snapshots 如果是docker部署,copy到对应的宿主机挂载目录下
6)启动clickhouse(配置好clickhouse-keeper)
clickhouse-keeper直接嵌入到clickhouse中
将以下配置 放到clickhouse的配置文件中
其中: <server_id>1</server_id> 为Keeper集群的每个节点唯一ID,因此每个节点的配置应该不同,可分别为1,2,3
XML<keeper_server> <tcp_port>9181</tcp_port> <server_id>1</server_id> <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path> <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path> <coordination_settings> <operation_timeout_ms>10000</operation_timeout_ms> <session_timeout_ms>30000</session_timeout_ms> <raft_logs_level>warning</raft_logs_level> </coordination_settings> <raft_configuration> <server> <id>1</id> <hostname>chnode1.domain.com</hostname> <port>9234</port> </server> <server> <id>2</id> <hostname>chnode2.domain.com</hostname> <port>9234</port> </server> <server> <id>3</id> <hostname>chnode3.domain.com</hostname> <port>9234</port> </server> </raft_configuration> </keeper_server> <!-- 启用clickhouse-keeper --> <zookeeper> <node> <host>chnode1.domain.com</host> <port>9181</port> </node> <node> <host>chnode2.domain.com</host> <port>9181</port> </node> <node> <host>chnode3.domain.com</host> <port>9181</port> </node> </zookeeper>
官网参考文档:https://clickhouse.com/docs/en/guides/sre/keeper/clickhouse-keeper