ZooKeeper Installation and Configuration
ZooKeeper Installation and Configuration
Prepare and Start ZooKeeper
Preparation
Before beginning, determine whether ZooKeeper will run in standalone or replicated mode.
- Standalone mode: One zookeeper server to service the entire ClickHouse cluster. Best for evaluation, development, and testing.
- Should never be used for production environments.
- Replicated mode: Multiple zookeeper servers in a group called an ensemble. Replicated mode is recommended for production systems.
- A minimum of 3 zookeeper servers are required.
- 3 servers is the optimal setup that functions even with heavily loaded systems with proper tuning.
- 5 servers is less likely to lose quorum entirely, but also results in longer quorum acquisition times.
- Additional servers can be added, but should always be an odd number of servers.
Precautions
The following practices should be avoided:
- Never deploy even numbers of ZooKeeper servers in an ensemble.
- Do not install ZooKeeper on ClickHouse nodes.
- Do not share ZooKeeper with other applications like Kafka.
- Place the ZooKeeper
dataDirandlogDiron fast storage that will not be used for anything else.
Applications to Install
Install the following applications in your servers:
zookeeper(3.4.9 or later)netcat
Configure ZooKeeper
-
/etc/zookeeper/conf/myidThe
myidfile consists of a single line containing only the text of that machine’s id. Somyidof server 1 would contain the text “1” and nothing else. The id must be unique within the ensemble and should have a value between 1 and 255. -
/etc/zookeeper/conf/zoo.cfgEvery machine that is part of the ZooKeeper ensemble should know about every other machine in the ensemble. You accomplish this with a series of lines of the form server.id=host:port:port
These lines must be the same on every ZooKeeper node
-
/etc/zookeeper/conf/zoo.cfgThis setting MUST be added on every ZooKeeper node:
Install Zookeeper
Depending on your environment, follow the Apache Zookeeper Getting Started guide, or the Zookeeper Administrator's Guide.
Start ZooKeeper
Depending on your installation, start ZooKeeper with the following command:
Verify ZooKeeper is Running
Use the following commands to verify ZooKeeper is available:
Check the following files and directories to verify ZooKeeper is running and making updates:
- Logs:
/var/log/zookeeper/zookeeper.log - Snapshots:
/var/lib/zookeeper/version-2/
Connect to ZooKeeper
From the localhost, connect to ZooKeeper with the following command to verify access (replace the IP address with your Zookeeper server):
Tune ZooKeeper
The following optional settings can be used depending on your requirements.
Improve Node Communication Reliability
The following settings can be used to improve node communication reliability:
Reduce Snapshots
The following settings will create fewer snapshots which may reduce system requirements.
Documentation
- ZooKeeper Getting Started Guide
- ClickHouse Zookeeper Recommendations
- Running ZooKeeper in Production
Configuring ClickHouse to use ZooKeeper
Once ZooKeeper has been installed and configured, ClickHouse can be modified to use ZooKeeper. After the following steps are completed, a restart of ClickHouse will be required.
To configure ClickHouse to use ZooKeeper, follow the steps shown below. The recommended settings are located on ClickHouse.tech zookeeper server settings.
-
Create a configuration file with the list of ZooKeeper nodes. Best practice is to put the file in
/etc/clickhouse-server/config.d/zookeeper.xml. -
Check the
distributed_ddlparameter inconfig.xml. This parameter can be defined in another configuration file, and can change the path to any value that you like. If you have several ClickHouse clusters using the same zookeeper,distributed_ddlpath should be unique for every ClickHouse cluster setup. -
Check
/etc/clickhouse-server/preprocessed/config.xml. You should see your changes there. -
Restart ClickHouse. Check ClickHouse connection to ZooKeeper detailed in ZooKeeper Monitoring.
Converting Tables to Replicated Tables
Creating a replicated table
Replicated tables use a replicated table engine, for example ReplicatedMergeTree. The following example shows how to create a simple replicated table.
This example assumes that you have defined appropriate macro values for cluster, shard, and replica in macros.xml to enable cluster replication using zookeeper. For details consult the ClickHouse.tech Data Replication guide.
The ON CLUSTER clause ensures the table will be created on the nodes of {cluster} (a macro value). This example automatically creates a ZooKeeper path for each replica table that looks like the following:
/clickhouse/tables/{cluster}/{replica}/default/test
becomes:
/clickhouse/tables/c1/0/default/test
You can see ZooKeeper replication data for this node with the following query (updating the path based on your environment):
Removing a replicated table
To remove a replicated table, use DROP TABLE as shown in the following example. The ON CLUSTER clause ensures the table will be deleted on all nodes. Omit it to delete the table on only a single node.
As each table is deleted the node is removed from replication and the information for the replica is cleaned up. When no more replicas exist, all ZooKeeper data for the table will be cleared.
Cleaning up ZooKeeper data for replicated tables
- IMPORTANT NOTE: Cleaning up ZooKeeper data manually can corrupt replication if you make a mistake. Raise a support ticket and ask for help if you have any doubt concerning the procedure.
New ClickHouse versions now support SYSTEM DROP REPLICA which is an easier command.
For example:
ZooKeeper data for the table might not be cleared fully if there is an error when deleting the table, or the table becomes corrupted, or the replica is lost. You can clean up ZooKeeper data in this case manually using the ZooKeeper rmr command. Here is the procedure:
- Login to ZooKeeper server.
- Run
zkCli.shcommand to connect to the server. - Locate the path to be deleted, e.g.:
ls /clickhouse/tables/c1/0/default/test - Remove the path recursively, e.g.,
rmr /clickhouse/tables/c1/0/default/test

浙公网安备 33010602011771号