diff --git a/docs/architecture/cluster-deployment.md b/docs/architecture/cluster-deployment.md
deleted file mode 100644
index af00312b8ac..00000000000
--- a/docs/architecture/cluster-deployment.md
+++ /dev/null
@@ -1,153 +0,0 @@
----
-slug: /architecture/cluster-deployment
-sidebar_label: 'Cluster Deployment'
-sidebar_position: 100
-title: 'Cluster Deployment'
-description: 'By going through this tutorial, you will learn how to set up a simple ClickHouse cluster.'
----
-
-This tutorial assumes you've already set up a [local ClickHouse server](../getting-started/install/install.mdx)
-
-By going through this tutorial, you'll learn how to set up a simple ClickHouse cluster. It'll be small, but fault-tolerant and scalable. Then we will use one of the example datasets to fill it with data and execute some demo queries.
-
-## Cluster Deployment {#cluster-deployment}
-
-This ClickHouse cluster will be a homogeneous cluster. Here are the steps:
-
-1. Install ClickHouse server on all machines of the cluster
-2. Set up cluster configs in configuration files
-3. Create local tables on each instance
-4. Create a [Distributed table](../engines/table-engines/special/distributed.md)
-
-A [distributed table](../engines/table-engines/special/distributed.md) is a kind of "view" to the local tables in a ClickHouse cluster. A SELECT query from a distributed table executes using resources of all cluster's shards. You may specify configs for multiple clusters and create multiple distributed tables to provide views for different clusters.
-
-Here is an example config for a cluster with three shards, with one replica each:
-
-```xml
-
-
-
-
- example-perftest01j.clickhouse.com
- 9000
-
-
-
-
- example-perftest02j.clickhouse.com
- 9000
-
-
-
-
- example-perftest03j.clickhouse.com
- 9000
-
-
-
-
-```
-
-For further demonstration, let's create a new local table with the same `CREATE TABLE` query that we used for `hits_v1` in the single node deployment tutorial, but with a different table name:
-
-```sql
-CREATE TABLE tutorial.hits_local (...) ENGINE = MergeTree() ...
-```
-
-Creating a distributed table provides a view into the local tables of the cluster:
-
-```sql
-CREATE TABLE tutorial.hits_all AS tutorial.hits_local
-ENGINE = Distributed(perftest_3shards_1replicas, tutorial, hits_local, rand());
-```
-
-A common practice is to create similar distributed tables on all machines of the cluster. This allows running distributed queries on any machine of the cluster. There's also an alternative option to create a temporary distributed table for a given SELECT query using [remote](../sql-reference/table-functions/remote.md) table function.
-
-Let's run [INSERT SELECT](../sql-reference/statements/insert-into.md) into the distributed table to spread the table to multiple servers.
-
-```sql
-INSERT INTO tutorial.hits_all SELECT * FROM tutorial.hits_v1;
-```
-
-As you would expect, computationally heavy queries run N times faster if they utilize 3 servers instead of one.
-
-In this case, we use a cluster with 3 shards, and each shard contains a single replica.
-
-To provide resilience in a production environment, we recommend that each shard contain 2-3 replicas spread between multiple availability zones or datacenters (or at least racks). Note that ClickHouse supports an unlimited number of replicas.
-
-Here is an example config for a cluster of one shard containing three replicas:
-
-```xml
-
- ...
-
-
-
- example-perftest01j.clickhouse.com
- 9000
-
-
- example-perftest02j.clickhouse.com
- 9000
-
-
- example-perftest03j.clickhouse.com
- 9000
-
-
-
-
-```
-
-To enable native replication [ZooKeeper](http://zookeeper.apache.org/), is required. ClickHouse takes care of data consistency on all replicas and runs a restore procedure after a failure automatically. It's recommended to deploy the ZooKeeper cluster on separate servers (where no other processes including ClickHouse are running).
-
-:::note Note
-ZooKeeper is not a strict requirement: in some simple cases, you can duplicate the data by writing it into all the replicas from your application code. This approach is **not** recommended, as in this case, ClickHouse won't be able to guarantee data consistency on all replicas. Thus, it becomes the responsibility of your application.
-:::
-
-ZooKeeper locations are specified in the configuration file:
-
-```xml
-
-
- zoo01.clickhouse.com
- 2181
-
-
- zoo02.clickhouse.com
- 2181
-
-
- zoo03.clickhouse.com
- 2181
-
-
-```
-
-Also, we need to set macros for identifying each shard and replica which are used on table creation:
-
-```xml
-
- 01
- 01
-
-```
-
-If there are no replicas at the moment of replicated table creation, a new first replica is instantiated. If there are already live replicas, the new replica clones data from existing ones. You have an option to create all replicated tables first, and then insert data to it. Another option is to create some replicas and add the others after or during data insertion.
-
-```sql
-CREATE TABLE tutorial.hits_replica (...)
-ENGINE = ReplicatedMergeTree(
- '/clickhouse_perftest/tables/{shard}/hits',
- '{replica}'
-)
-...
-```
-
-Here we use the [ReplicatedMergeTree](../engines/table-engines/mergetree-family/replication.md) table engine. In parameters, we specify the ZooKeeper path containing the shard and replica identifiers.
-
-```sql
-INSERT INTO tutorial.hits_replica SELECT * FROM tutorial.hits_local;
-```
-
-Replication operates in multi-master mode. Data can be loaded into any replica, and the system then syncs it with other instances automatically. Replication is asynchronous so at a given moment, not all replicas may contain recently inserted data. At least one replica should be up to allow for data ingestion. Others will sync up data and repair consistency once they become active again. Note that this approach allows for the low possibility of loss of recently inserted data.
diff --git a/docs/deployment-guides/horizontal-scaling.md b/docs/deployment-guides/horizontal-scaling.md
deleted file mode 100644
index 7215e598799..00000000000
--- a/docs/deployment-guides/horizontal-scaling.md
+++ /dev/null
@@ -1,487 +0,0 @@
----
-slug: /architecture/horizontal-scaling
-sidebar_label: 'Scaling out'
-sidebar_position: 10
-title: 'Scaling out'
-description: 'Page describing an example architecture designed to provide scalability'
----
-
-import Image from '@theme/IdealImage';
-import ReplicationShardingTerminology from '@site/docs/_snippets/_replication-sharding-terminology.md';
-import ConfigFileNote from '@site/docs/_snippets/_config-files.md';
-import scalingOut1 from '@site/static/images/deployment-guides/scaling-out-1.png';
-
-## Description {#description}
-This example architecture is designed to provide scalability. It includes three nodes: two combined ClickHouse plus coordination (ClickHouse Keeper) servers, and a third server with only ClickHouse Keeper to finish the quorum of three. With this example, we'll create a database, table, and a distributed table that will be able to query the data on both of the nodes.
-
-## Level: Basic {#level-basic}
-
-
-
-## Environment {#environment}
-### Architecture Diagram {#architecture-diagram}
-
-
-
-|Node|Description|
-|----|-----------|
-|`chnode1`|Data + ClickHouse Keeper|
-|`chnode2`|Data + ClickHouse Keeper|
-|`chnode3`|Used for ClickHouse Keeper quorum|
-
-:::note
-In production environments we strongly recommend that ClickHouse Keeper runs on dedicated hosts. This basic configuration runs the Keeper functionality within the ClickHouse Server process. The instructions for deploying ClickHouse Keeper standalone are available in the [installation documentation](/getting-started/install/install.mdx).
-:::
-
-## Install {#install}
-
-Install Clickhouse on three servers following the [instructions for your archive type](/getting-started/install/install.mdx) (.deb, .rpm, .tar.gz, etc.). For this example, you will follow the installation instructions for ClickHouse Server and Client on all three machines.
-
-## Editing configuration files {#editing-configuration-files}
-
-
-
-## chnode1 configuration {#chnode1-configuration}
-
-For `chnode1`, there are five configuration files. You may choose to combine these files into a single file, but for clarity in the documentation it may be simpler to look at them separately. As you read through the configuration files, you will see that most of the configuration is the same between `chnode1` and `chnode2`; the differences will be highlighted.
-
-### Network and logging configuration {#network-and-logging-configuration}
-
-These values can be customized as you wish. This example configuration gives you a debug log that will roll over at 1000M three times. ClickHouse will listen on the IPv4 network on ports 8123 and 9000, and will use port 9009 for interserver communication.
-
-```xml title="network-and-logging.xml on chnode1"
-
-
- debug
- /var/log/clickhouse-server/clickhouse-server.log
- /var/log/clickhouse-server/clickhouse-server.err.log
- 1000M
- 3
-
- clickhouse
- 0.0.0.0
- 8123
- 9000
- 9009
-
-```
-
-### ClickHouse Keeper configuration {#clickhouse-keeper-configuration}
-
-ClickHouse Keeper provides the coordination system for data replication and distributed DDL queries execution. ClickHouse Keeper is compatible with Apache ZooKeeper. This configuration enables ClickHouse Keeper on port 9181. The highlighted line specifies that this instance of Keeper has `server_id` of 1. This is the only difference in the `enable-keeper.xml` file across the three servers. `chnode2` will have `server_id` set to `2`, and `chnode3` will have `server_id` set to `3`. The raft configuration section is the same on all three servers, and it is highlighted below to show you the relationship between `server_id` and the `server` instance within the raft configuration.
-
-:::note
-If for any reason a Keeper node is replaced or rebuilt, do not reuse an existing `server_id`. For example, if the Keeper node with `server_id` of `2` is rebuilt, give it server_id of `4` or higher.
-:::
-
-```xml title="enable-keeper.xml on chnode1"
-
-
- 9181
- # highlight-next-line
- 1
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
-
- 10000
- 30000
- trace
-
-
-
- # highlight-start
-
- 1
- chnode1
- 9234
-
- # highlight-end
-
- 2
- chnode2
- 9234
-
-
- 3
- chnode3
- 9234
-
-
-
-
-```
-
-### Macros configuration {#macros-configuration}
-
-The macros `shard` and `replica` reduce the complexity of distributed DDL. The values configured are automatically substituted in your DDL queries, which simplifies your DDL. The macros for this configuration specify the shard and replica number for each node.
-In this 2 shard 1 replica example, the replica macro is `replica_1` on both chnode1 and chnode2 as there is only one replica. The shard macro is `1` on chnode1 and `2` on chnode2.
-
-```xml title="macros.xml on chnode1"
-
-
- # highlight-next-line
- 1
- replica_1
-
-
-```
-
-### Replication and sharding configuration {#replication-and-sharding-configuration}
-
-Starting from the top:
-- The `remote_servers` section of the XML specifies each of the clusters in the environment. The attribute `replace=true` replaces the sample `remote_servers` in the default ClickHouse configuration with the `remote_servers` configuration specified in this file. Without this attribute, the remote servers in this file would be appended to the list of samples in the default.
-- In this example, there is one cluster named `cluster_2S_1R`.
-- A secret is created for the cluster named `cluster_2S_1R` with the value `mysecretphrase`. The secret is shared across all of the remote servers in the environment to ensure that the correct servers are joined together.
-- The cluster `cluster_2S_1R` has two shards, and each of those shards has one replica. Take a look at the architecture diagram toward the beginning of this document, and compare it with the two `shard` definitions in the XML below. In each of the shard definitions there is one replica. The replica is for that specific shard. The host and port for that replica is specified. The replica for the first shard in the configuration is stored on `chnode1`, and the replica for the second shard in the configuration is stored on `chnode2`.
-- Internal replication for the shards is set to true. Each shard can have the `internal_replication` parameter defined in the config file. If this parameter is set to true, the write operation selects the first healthy replica and writes data to it.
-
-```xml title="remote-servers.xml on chnode1"
-
-
-
- mysecretphrase
-
- true
-
- chnode1
- 9000
-
-
-
- true
-
- chnode2
- 9000
-
-
-
-
-
-```
-
-### Configuring the use of Keeper {#configuring-the-use-of-keeper}
-
-Up above a few files ClickHouse Keeper was configured. This configuration file `use-keeper.xml` is configuring ClickHouse Server to use ClickHouse Keeper for the coordination of replication and distributed DDL. This file specifies that ClickHouse Server should use Keeper on nodes chnode1 - 3 on port 9181, and the file is the same on `chnode1` and `chnode2`.
-
-```xml title="use-keeper.xml on chnode1"
-
-
-
- chnode1
- 9181
-
-
- chnode2
- 9181
-
-
- chnode3
- 9181
-
-
-
-```
-
-## chnode2 configuration {#chnode2-configuration}
-
-As the configuration is very similar on `chnode1` and `chnode2`, only the differences will be pointed out here.
-
-### Network and logging configuration {#network-and-logging-configuration-1}
-
-```xml title="network-and-logging.xml on chnode2"
-
-
- debug
- /var/log/clickhouse-server/clickhouse-server.log
- /var/log/clickhouse-server/clickhouse-server.err.log
- 1000M
- 3
-
- clickhouse
- 0.0.0.0
- 8123
- 9000
- 9009
-
-```
-
-### ClickHouse Keeper configuration {#clickhouse-keeper-configuration-1}
-
-This file contains one of the two differences between `chnode1` and `chnode2`. In the Keeper configuration the `server_id` is set to `2`.
-
-```xml title="enable-keeper.xml on chnode2"
-
-
- 9181
- # highlight-next-line
- 2
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
-
- 10000
- 30000
- trace
-
-
-
-
- 1
- chnode1
- 9234
-
- # highlight-start
-
- 2
- chnode2
- 9234
-
- # highlight-end
-
- 3
- chnode3
- 9234
-
-
-
-
-```
-
-### Macros configuration {#macros-configuration-1}
-
-The macros configuration has one of the differences between `chnode1` and `chnode2`. `shard` is set to `2` on this node.
-
-```xml title="macros.xml on chnode2"
-
-
- # highlight-next-line
- 2
- replica_1
-
-
-```
-
-### Replication and sharding configuration {#replication-and-sharding-configuration-1}
-
-```xml title="remote-servers.xml on chnode2"
-
-
-
- mysecretphrase
-
- true
-
- chnode1
- 9000
-
-
-
- true
-
- chnode2
- 9000
-
-
-
-
-
-```
-
-### Configuring the use of Keeper {#configuring-the-use-of-keeper-1}
-
-```xml title="use-keeper.xml on chnode2"
-
-
-
- chnode1
- 9181
-
-
- chnode2
- 9181
-
-
- chnode3
- 9181
-
-
-
-```
-
-## chnode3 configuration {#chnode3-configuration}
-
-As `chnode3` is not storing data and is only used for ClickHouse Keeper to provide the third node in the quorum, `chnode3` has only two configuration files, one to configure the network and logging, and one to configure ClickHouse Keeper.
-
-### Network and logging configuration {#network-and-logging-configuration-2}
-
-```xml title="network-and-logging.xml on chnode3"
-
-
- debug
- /var/log/clickhouse-server/clickhouse-server.log
- /var/log/clickhouse-server/clickhouse-server.err.log
- 1000M
- 3
-
- clickhouse
- 0.0.0.0
- 8123
- 9000
- 9009
-
-```
-
-### ClickHouse Keeper configuration {#clickhouse-keeper-configuration-2}
-
-```xml title="enable-keeper.xml on chnode3"
-
-
- 9181
- # highlight-next-line
- 3
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
-
- 10000
- 30000
- trace
-
-
-
-
- 1
- chnode1
- 9234
-
-
- 2
- chnode2
- 9234
-
- # highlight-start
-
- 3
- chnode3
- 9234
-
- # highlight-end
-
-
-
-```
-
-## Testing {#testing}
-
-1. Connect to `chnode1` and verify that the cluster `cluster_2S_1R` configured above exists
-
-```sql title="Query"
-SHOW CLUSTERS
-```
-
-```response title="Response"
-┌─cluster───────┐
-│ cluster_2S_1R │
-└───────────────┘
-```
-
-2. Create a database on the cluster
-
-```sql title="Query"
-CREATE DATABASE db1 ON CLUSTER cluster_2S_1R
-```
-
-```response title="Response"
-┌─host────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
-│ chnode2 │ 9000 │ 0 │ │ 1 │ 0 │
-│ chnode1 │ 9000 │ 0 │ │ 0 │ 0 │
-└─────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
-```
-
-3. Create a table with MergeTree table engine on the cluster.
-:::note
-We do not need not to specify parameters on the table engine since these will be automatically defined based on our macros
-:::
-
-```sql title="Query"
-CREATE TABLE db1.table1 ON CLUSTER cluster_2S_1R
-(
- `id` UInt64,
- `column1` String
-)
-ENGINE = MergeTree
-ORDER BY id
-```
-```response title="Response"
-┌─host────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
-│ chnode1 │ 9000 │ 0 │ │ 1 │ 0 │
-│ chnode2 │ 9000 │ 0 │ │ 0 │ 0 │
-└─────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
-```
-
-4. Connect to `chnode1` and insert a row
-
-```sql title="Query"
-INSERT INTO db1.table1 (id, column1) VALUES (1, 'abc');
-```
-
-5. Connect to `chnode2` and insert a row
-
-```sql title="Query"
-INSERT INTO db1.table1 (id, column1) VALUES (2, 'def');
-```
-
-6. Connect to either node, `chnode1` or `chnode2` and you will see only the row that was inserted into that table on that node.
-for example, on `chnode2`
-
-```sql title="Query"
-SELECT * FROM db1.table1;
-```
-
-```response title="Response"
-┌─id─┬─column1─┐
-│ 2 │ def │
-└────┴─────────┘
-```
-
-
-7. Create a distributed table to query both shards on both nodes.
-(In this example, the `rand()` function is set as the sharding key so that it randomly distributes each insert)
-
-```sql title="Query"
-CREATE TABLE db1.table1_dist ON CLUSTER cluster_2S_1R
-(
- `id` UInt64,
- `column1` String
-)
-ENGINE = Distributed('cluster_2S_1R', 'db1', 'table1', rand())
-```
-
-```response title="Response"
-┌─host────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
-│ chnode2 │ 9000 │ 0 │ │ 1 │ 0 │
-│ chnode1 │ 9000 │ 0 │ │ 0 │ 0 │
-└─────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
-```
-
-8. Connect to either `chnode1` or `chnode2` and query the distributed table to see both rows.
-
-```sql title="Query"
-SELECT * FROM db1.table1_dist;
-```
-
-```reponse title="Response"
-┌─id─┬─column1─┐
-│ 2 │ def │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 1 │ abc │
-└────┴─────────┘
-```
-
-
-## More information about: {#more-information-about}
-
-- The [Distributed Table Engine](/engines/table-engines/special/distributed.md)
-- [ClickHouse Keeper](/guides/sre/keeper/index.md)
diff --git a/docs/deployment-guides/replicated.md b/docs/deployment-guides/replicated.md
deleted file mode 100644
index 2fd2463ea28..00000000000
--- a/docs/deployment-guides/replicated.md
+++ /dev/null
@@ -1,560 +0,0 @@
----
-slug: /architecture/replication
-sidebar_label: 'Replication for fault tolerance'
-sidebar_position: 10
-title: 'Replication for fault tolerance'
-description: 'Page describing an example architecture with five servers configured. Two are used to host copies of the data and the rest are used to coordinate the replication of data'
----
-
-import Image from '@theme/IdealImage';
-import ReplicationShardingTerminology from '@site/docs/_snippets/_replication-sharding-terminology.md';
-import ConfigFileNote from '@site/docs/_snippets/_config-files.md';
-import KeeperConfigFileNote from '@site/docs/_snippets/_keeper-config-files.md';
-import ReplicationArchitecture from '@site/static/images/deployment-guides/architecture_1s_2r_3_nodes.png';
-
-## Description {#description}
-In this architecture, there are five servers configured. Two are used to host copies of the data. The other three servers are used to coordinate the replication of data. With this example, we'll create a database and table that will be replicated across both data nodes using the ReplicatedMergeTree table engine.
-
-## Level: Basic {#level-basic}
-
-
-
-## Environment {#environment}
-### Architecture Diagram {#architecture-diagram}
-
-
-
-|Node|Description|
-|----|-----------|
-|clickhouse-01|Data|
-|clickhouse-02|Data|
-|clickhouse-keeper-01|Distributed coordination|
-|clickhouse-keeper-02|Distributed coordination|
-|clickhouse-keeper-03|Distributed coordination|
-
-:::note
-In production environments, we strongly recommend using *dedicated* hosts for ClickHouse keeper. In test environment it is acceptable to run ClickHouse Server and ClickHouse Keeper combined on the same server. The other basic example, [Scaling out](/deployment-guides/horizontal-scaling.md), uses this method. In this example we present the recommended method of separating Keeper from ClickHouse Server. The Keeper servers can be smaller, 4GB RAM is generally enough for each Keeper server until your ClickHouse Servers grow very large.
-:::
-
-## Install {#install}
-
-Install ClickHouse server and client on the two servers `clickhouse-01` and `clickhouse-02` following the [instructions for your archive type](/getting-started/install/install.mdx) (.deb, .rpm, .tar.gz, etc.).
-
-Install ClickHouse Keeper on the three servers `clickhouse-keeper-01`, `clickhouse-keeper-02` and `clickhouse-keeper-03` following the [instructions for your archive type](/getting-started/install/install.mdx) (.deb, .rpm, .tar.gz, etc.).
-
-## Editing configuration files {#editing-configuration-files}
-
-
-
-## clickhouse-01 configuration {#clickhouse-01-configuration}
-
-For clickhouse-01 there are five configuration files. You may choose to combine these files into a single file, but for clarity in the documentation it may be simpler to look at them separately. As you read through the configuration files you will see that most of the configuration is the same between clickhouse-01 and clickhouse-02; the differences will be highlighted.
-
-### Network and logging configuration {#network-and-logging-configuration}
-
-These values can be customized as you wish. This example configuration gives you:
-- a debug log that will roll over at 1000M three times
-- the name displayed when you connect with `clickhouse-client` is `cluster_1S_2R node 1`
-- ClickHouse will listen on the IPV4 network on ports 8123 and 9000.
-
-```xml title="/etc/clickhouse-server/config.d/network-and-logging.xml on clickhouse-01"
-
-
- debug
- /var/log/clickhouse-server/clickhouse-server.log
- /var/log/clickhouse-server/clickhouse-server.err.log
- 1000M
- 3
-
- cluster_1S_2R node 1
- 0.0.0.0
- 8123
- 9000
-
-```
-
-### Macros configuration {#macros-configuration}
-
-The macros `shard` and `replica` reduce the complexity of distributed DDL. The values configured are automatically substituted in your DDL queries, which simplifies your DDL. The macros for this configuration specify the shard and replica number for each node.
-In this 1 shard 2 replica example, the replica macro is `replica_1` on clickhouse-01 and `replica_2` on clickhouse-02. The shard macro is `1` on both clickhouse-01 and clickhouse-02 as there is only one shard.
-
-```xml title="/etc/clickhouse-server/config.d/macros.xml on clickhouse-01"
-
-
- 01
-
- 01
- cluster_1S_2R
-
-
-```
-
-### Replication and sharding configuration {#replication-and-sharding-configuration}
-
-Starting from the top:
-- The remote_servers section of the XML specifies each of the clusters in the environment. The attribute `replace=true` replaces the sample remote_servers in the default ClickHouse configuration with the remote_server configuration specified in this file. Without this attribute the remote servers in this file would be appended to the list of samples in the default.
-- In this example, there is one cluster named `cluster_1S_2R`.
-- A secret is created for the cluster named `cluster_1S_2R` with the value `mysecretphrase`. The secret is shared across all of the remote servers in the environment to ensure that the correct servers are joined together.
-- The cluster `cluster_1S_2R` has one shard, and two replicas. Take a look at the architecture diagram toward the beginning of this document, and compare it with the `shard` definition in the XML below. The shard definition contains two replicas. The host and port for each replica is specified. One replica is stored on `clickhouse-01`, and the other replica is stored on `clickhouse-02`.
-- Internal replication for the shard is set to true. Each shard can have the internal_replication parameter defined in the config file. If this parameter is set to true, the write operation selects the first healthy replica and writes data to it.
-
-```xml title="/etc/clickhouse-server/config.d/remote-servers.xml on clickhouse-01"
-
-
-
- mysecretphrase
-
- true
-
- clickhouse-01
- 9000
-
-
- clickhouse-02
- 9000
-
-
-
-
-
-```
-
-### Configuring the use of Keeper {#configuring-the-use-of-keeper}
-
-This configuration file `use-keeper.xml` is configuring ClickHouse Server to use ClickHouse Keeper for the coordination of replication and distributed DDL. This file specifies that ClickHouse Server should use Keeper on nodes clickhouse-keeper-01 - 03 on port 9181, and the file is the same on `clickhouse-01` and `clickhouse-02`.
-
-```xml title="/etc/clickhouse-server/config.d/use-keeper.xml on clickhouse-01"
-
-
-
-
- clickhouse-keeper-01
- 9181
-
-
- clickhouse-keeper-02
- 9181
-
-
- clickhouse-keeper-03
- 9181
-
-
-
-```
-
-## clickhouse-02 configuration {#clickhouse-02-configuration}
-
-As the configuration is very similar on clickhouse-01 and clickhouse-02 only the differences will be pointed out here.
-
-### Network and logging configuration {#network-and-logging-configuration-1}
-
-This file is the same on both clickhouse-01 and clickhouse-02, with the exception of `display_name`.
-
-```xml title="/etc/clickhouse-server/config.d/network-and-logging.xml on clickhouse-02"
-
-
- debug
- /var/log/clickhouse-server/clickhouse-server.log
- /var/log/clickhouse-server/clickhouse-server.err.log
- 1000M
- 3
-
-
- cluster_1S_2R node 2
- 0.0.0.0
- 8123
- 9000
-
-```
-
-### Macros configuration {#macros-configuration-1}
-
-The macros configuration is different between clickhouse-01 and clickhouse-02. `replica` is set to `02` on this node.
-
-```xml title="/etc/clickhouse-server/config.d/macros.xml on clickhouse-02"
-
-
- 01
-
- 02
- cluster_1S_2R
-
-
-```
-
-### Replication and sharding configuration {#replication-and-sharding-configuration-1}
-
-This file is the same on both clickhouse-01 and clickhouse-02.
-
-```xml title="/etc/clickhouse-server/config.d/remote-servers.xml on clickhouse-02"
-
-
-
- mysecretphrase
-
- true
-
- clickhouse-01
- 9000
-
-
- clickhouse-02
- 9000
-
-
-
-
-
-```
-
-### Configuring the use of Keeper {#configuring-the-use-of-keeper-1}
-
-This file is the same on both clickhouse-01 and clickhouse-02.
-
-```xml title="/etc/clickhouse-server/config.d/use-keeper.xml on clickhouse-02"
-
-
-
-
- clickhouse-keeper-01
- 9181
-
-
- clickhouse-keeper-02
- 9181
-
-
- clickhouse-keeper-03
- 9181
-
-
-
-```
-
-## clickhouse-keeper-01 configuration {#clickhouse-keeper-01-configuration}
-
-
-
-ClickHouse Keeper provides the coordination system for data replication and distributed DDL queries execution. ClickHouse Keeper is compatible with Apache ZooKeeper. This configuration enables ClickHouse Keeper on port 9181. The highlighted line specifies that this instance of Keeper has server_id of 1. This is the only difference in the `enable-keeper.xml` file across the three servers. `clickhouse-keeper-02` will have `server_id` set to `2`, and `clickhouse-keeper-03` will have `server_id` set to `3`. The raft configuration section is the same on all three servers, it is highlighted below to show you the relationship between `server_id` and the `server` instance within the raft configuration.
-
-:::note
-If for any reason a Keeper node is replaced or rebuilt, do not reuse an existing `server_id`. For example, if the Keeper node with `server_id` of `2` is rebuilt, give it server_id of `4` or higher.
-:::
-
-```xml title="/etc/clickhouse-keeper/keeper_config.xml on clickhouse-keeper-01"
-
-
- trace
- /var/log/clickhouse-keeper/clickhouse-keeper.log
- /var/log/clickhouse-keeper/clickhouse-keeper.err.log
- 1000M
- 3
-
- 0.0.0.0
-
- 9181
-
- 1
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
- 10000
- 30000
- trace
-
-
-
-
- 1
- clickhouse-keeper-01
- 9234
-
-
-
- 2
- clickhouse-keeper-02
- 9234
-
-
- 3
- clickhouse-keeper-03
- 9234
-
-
-
-
-```
-
-## clickhouse-keeper-02 configuration {#clickhouse-keeper-02-configuration}
-
-There is only one line difference between `clickhouse-keeper-01` and `clickhouse-keeper-02`. `server_id` is set to `2` on this node.
-
-```xml title="/etc/clickhouse-keeper/keeper_config.xml on clickhouse-keeper-02"
-
-
- trace
- /var/log/clickhouse-keeper/clickhouse-keeper.log
- /var/log/clickhouse-keeper/clickhouse-keeper.err.log
- 1000M
- 3
-
- 0.0.0.0
-
- 9181
-
- 2
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
- 10000
- 30000
- trace
-
-
-
- 1
- clickhouse-keeper-01
- 9234
-
-
-
- 2
- clickhouse-keeper-02
- 9234
-
-
-
- 3
- clickhouse-keeper-03
- 9234
-
-
-
-
-```
-
-## clickhouse-keeper-03 configuration {#clickhouse-keeper-03-configuration}
-
-There is only one line difference between `clickhouse-keeper-01` and `clickhouse-keeper-03`. `server_id` is set to `3` on this node.
-
-```xml title="/etc/clickhouse-keeper/keeper_config.xml on clickhouse-keeper-03"
-
-
- trace
- /var/log/clickhouse-keeper/clickhouse-keeper.log
- /var/log/clickhouse-keeper/clickhouse-keeper.err.log
- 1000M
- 3
-
- 0.0.0.0
-
- 9181
-
- 3
- /var/lib/clickhouse/coordination/log
- /var/lib/clickhouse/coordination/snapshots
-
- 10000
- 30000
- trace
-
-
-
- 1
- clickhouse-keeper-01
- 9234
-
-
- 2
- clickhouse-keeper-02
- 9234
-
-
-
- 3
- clickhouse-keeper-03
- 9234
-
-
-
-
-
-```
-
-## Testing {#testing}
-
-To gain experience with ReplicatedMergeTree and ClickHouse Keeper you can run the following commands which will have you:
-- Create a database on the cluster configured above
-- Create a table on the database using the ReplicatedMergeTree table engine
-- Insert data on one node and query it on another node
-- Stop one ClickHouse server node
-- Insert more data on the running node
-- Restart the stopped node
-- Verify that the data is available when querying the restarted node
-
-### Verify that ClickHouse Keeper is running {#verify-that-clickhouse-keeper-is-running}
-
-The `mntr` command is used to verify that the ClickHouse Keeper is running and to get state information about the relationship of the three Keeper nodes. In the configuration used in this example there are three nodes working together. The nodes will elect a leader, and the remaining nodes will be followers. The `mntr` command gives information related to performance, and whether a particular node is a follower or a leader.
-
-:::tip
-You may need to install `netcat` in order to send the `mntr` command to Keeper. Please see the [nmap.org](https://nmap.org/ncat/) page for download information.
-:::
-
-```bash title="run from a shell on clickhouse-keeper-01, clickhouse-keeper-02, and clickhouse-keeper-03"
-echo mntr | nc localhost 9181
-```
-```response title="response from a follower"
-zk_version v23.3.1.2823-testing-46e85357ce2da2a99f56ee83a079e892d7ec3726
-zk_avg_latency 0
-zk_max_latency 0
-zk_min_latency 0
-zk_packets_received 0
-zk_packets_sent 0
-zk_num_alive_connections 0
-zk_outstanding_requests 0
-# highlight-next-line
-zk_server_state follower
-zk_znode_count 6
-zk_watch_count 0
-zk_ephemerals_count 0
-zk_approximate_data_size 1271
-zk_key_arena_size 4096
-zk_latest_snapshot_size 0
-zk_open_file_descriptor_count 46
-zk_max_file_descriptor_count 18446744073709551615
-```
-
-```response title="response from a leader"
-zk_version v23.3.1.2823-testing-46e85357ce2da2a99f56ee83a079e892d7ec3726
-zk_avg_latency 0
-zk_max_latency 0
-zk_min_latency 0
-zk_packets_received 0
-zk_packets_sent 0
-zk_num_alive_connections 0
-zk_outstanding_requests 0
-# highlight-next-line
-zk_server_state leader
-zk_znode_count 6
-zk_watch_count 0
-zk_ephemerals_count 0
-zk_approximate_data_size 1271
-zk_key_arena_size 4096
-zk_latest_snapshot_size 0
-zk_open_file_descriptor_count 48
-zk_max_file_descriptor_count 18446744073709551615
-# highlight-start
-zk_followers 2
-zk_synced_followers 2
-# highlight-end
-```
-
-### Verify ClickHouse cluster functionality {#verify-clickhouse-cluster-functionality}
-
-Connect to node `clickhouse-01` with `clickhouse client` in one shell, and connect to node `clickhouse-02` with `clickhouse client` in another shell.
-
-1. Create a database on the cluster configured above
-
-```sql title="run on either node clickhouse-01 or clickhouse-02"
-CREATE DATABASE db1 ON CLUSTER cluster_1S_2R
-```
-```response
-┌─host──────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
-│ clickhouse-02 │ 9000 │ 0 │ │ 1 │ 0 │
-│ clickhouse-01 │ 9000 │ 0 │ │ 0 │ 0 │
-└───────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
-```
-
-2. Create a table on the database using the ReplicatedMergeTree table engine
-```sql title="run on either node clickhouse-01 or clickhouse-02"
-CREATE TABLE db1.table1 ON CLUSTER cluster_1S_2R
-(
- `id` UInt64,
- `column1` String
-)
-ENGINE = ReplicatedMergeTree
-ORDER BY id
-```
-```response
-┌─host──────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
-│ clickhouse-02 │ 9000 │ 0 │ │ 1 │ 0 │
-│ clickhouse-01 │ 9000 │ 0 │ │ 0 │ 0 │
-└───────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
-```
-3. Insert data on one node and query it on another node
-```sql title="run on node clickhouse-01"
-INSERT INTO db1.table1 (id, column1) VALUES (1, 'abc');
-```
-
-4. Query the table on the node `clickhouse-02`
-```sql title="run on node clickhouse-02"
-SELECT *
-FROM db1.table1
-```
-```response
-┌─id─┬─column1─┐
-│ 1 │ abc │
-└────┴─────────┘
-```
-
-5. Insert data on the other node and query it on the node `clickhouse-01`
-```sql title="run on node clickhouse-02"
-INSERT INTO db1.table1 (id, column1) VALUES (2, 'def');
-```
-
-```sql title="run on node clickhouse-01"
-SELECT *
-FROM db1.table1
-```
-```response
-┌─id─┬─column1─┐
-│ 1 │ abc │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 2 │ def │
-└────┴─────────┘
-```
-
-6. Stop one ClickHouse server node
-Stop one of the ClickHouse server nodes by running an operating system command similar to the command used to start the node. If you used `systemctl start` to start the node, then use `systemctl stop` to stop it.
-
-7. Insert more data on the running node
-```sql title="run on the running node"
-INSERT INTO db1.table1 (id, column1) VALUES (3, 'ghi');
-```
-
-Select the data:
-```sql title="run on the running node"
-SELECT *
-FROM db1.table1
-```
-```response
-┌─id─┬─column1─┐
-│ 1 │ abc │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 2 │ def │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 3 │ ghi │
-└────┴─────────┘
-```
-
-8. Restart the stopped node and select from there also
-
-```sql title="run on the restarted node"
-SELECT *
-FROM db1.table1
-```
-```response
-┌─id─┬─column1─┐
-│ 1 │ abc │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 2 │ def │
-└────┴─────────┘
-┌─id─┬─column1─┐
-│ 3 │ ghi │
-└────┴─────────┘
-```
diff --git a/docs/deployment-guides/replication-sharding-examples/01_1_shard_2_replicas.md b/docs/deployment-guides/replication-sharding-examples/01_1_shard_2_replicas.md
new file mode 100644
index 00000000000..2c736a25db9
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/01_1_shard_2_replicas.md
@@ -0,0 +1,808 @@
+---
+slug: /architecture/replication
+sidebar_label: 'Replication'
+sidebar_position: 10
+title: 'Replicating data'
+description: 'Page describing an example architecture with five servers configured. Two are used to host copies of the data and the rest are used to coordinate the replication of data'
+---
+
+import Image from '@theme/IdealImage';
+import ReplicationShardingTerminology from '@site/docs/_snippets/_replication-sharding-terminology.md';
+import ReplicationArchitecture from '@site/static/images/deployment-guides/replication-sharding-examples/replication.png';
+import ConfigFileNote from '@site/docs/_snippets/_config-files.md';
+import KeeperConfigFileNote from '@site/docs/_snippets/_keeper-config-files.md';
+import ConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx';
+import ListenHost from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx';
+import ServerParameterTable from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_server_parameter_table.mdx';
+import KeeperConfig from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx';
+import KeeperConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx';
+import VerifyKeeperStatus from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx';
+import DedicatedKeeperServers from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx';
+import ExampleFiles from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx';
+
+> In this example, you'll learn how to set up a simple ClickHouse cluster which
+replicates the data. There are five servers configured. Two are used to host
+copies of the data. The other three servers are used to coordinate the replication
+of data.
+
+The architecture of the cluster you will be setting up is shown below:
+
+
+
+
+
+## Prerequisites {#pre-requisites}
+
+- You've set up a [local ClickHouse server](/install) before
+- You are familiar with basic configuration concepts of ClickHouse such as [configuration files](/operations/configuration-files)
+- You have docker installed on your machine
+
+
+
+## Set up directory structure and test environment {#set-up}
+
+
+
+In this tutorial, you will use [Docker compose](https://docs.docker.com/compose/) to
+set up the ClickHouse cluster. This setup could be modified to work
+for separate local machines, virtual machines or cloud instances as well.
+
+Run the following commands to set up the directory structure for this example:
+
+```bash
+mkdir cluster_1S_2R
+cd cluster_1S_2R
+
+# Create clickhouse-keeper directories
+for i in {01..03}; do
+ mkdir -p fs/volumes/clickhouse-keeper-${i}/etc/clickhouse-keeper
+done
+
+# Create clickhouse-server directories
+for i in {01..02}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server
+done
+```
+
+Add the following `docker-compose.yml` file to the `clickhouse-cluster` directory:
+
+```yaml title="docker-compose.yml"
+version: '3.8'
+services:
+ clickhouse-01:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-01
+ hostname: clickhouse-01
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8123:8123"
+ - "127.0.0.1:9000:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-02:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-02
+ hostname: clickhouse-02
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8124:8123"
+ - "127.0.0.1:9001:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-keeper-01:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-01
+ hostname: clickhouse-keeper-01
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9181:9181"
+ clickhouse-keeper-02:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-02
+ hostname: clickhouse-keeper-02
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9182:9181"
+ clickhouse-keeper-03:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-03
+ hostname: clickhouse-keeper-03
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9183:9181"
+```
+
+Create the following sub-directories and files:
+
+```bash
+for i in {01..02}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d/config.xml
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d/users.xml
+done
+```
+
+
+
+## Configure ClickHouse nodes {#configure-clickhouse-servers}
+
+### Server setup {#server-setup}
+
+Now modify each empty configuration file `config.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/config.d`. The lines which are
+highlighted below need to be changed to be specific to each node:
+
+```xml
+
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+
+ cluster_1S_2R node 1
+ 0.0.0.0
+ 8123
+ 9000
+
+
+ users.xml
+
+
+ /var/lib/clickhouse/access/
+
+
+
+ /clickhouse/task_queue/ddl
+
+
+
+
+ true
+
+ clickhouse-01
+ 9000
+
+
+ clickhouse-02
+ 9000
+
+
+
+
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+
+
+ 01
+ 01
+ cluster_1S_2R
+
+
+
+```
+
+| Directory | File |
+|-----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-01/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml) |
+| `fs/volumes/clickhouse-02/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml) |
+
+Each section of the above configuration file is explained in more detail below.
+
+#### Networking and logging {#networking}
+
+
+
+Logging is defined in the `` block. This example configuration gives
+you a debug log that will roll over at 1000M three times:
+
+```xml
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+```
+
+For more information on logging configuration, see the comments included in the
+default ClickHouse [configuration file](https://github.com/ClickHouse/ClickHouse/blob/master/programs/server/config.xml).
+
+#### Cluster configuration {#cluster-configuration}
+
+Configuration for the cluster is set up in the `` block.
+Here the cluster name `cluster_1S_2R` is defined.
+
+The `` block defines the layout of the cluster,
+using the `` and `` settings, and acts as a
+template for distributed DDL queries, which are queries that execute across the
+cluster using the `ON CLUSTER` clause. By default, distributed DDL queries
+are allowed, but can also be turned off with setting `allow_distributed_ddl_queries`.
+
+`internal_replication` is set to true so that data is written to just one of the replicas.
+
+```xml
+
+
+
+
+
+
+ true
+
+ clickhouse-01
+ 9000
+
+
+ clickhouse-02
+ 9000
+
+
+
+
+```
+
+
+
+#### Keeper configuration {#keeper-config-explanation}
+
+The `` section tells ClickHouse where ClickHouse Keeper (or ZooKeeper) is running.
+As we are using a ClickHouse Keeper cluster, each `` of the cluster needs to be specified,
+along with its hostname and port number using the `` and `` tags respectively.
+
+Set up of ClickHouse Keeper is explained in the next step of the tutorial.
+
+```xml
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+```
+
+:::note
+Although it is possible to run ClickHouse Keeper on the same server as ClickHouse Server,
+in production environments we strongly recommend that ClickHouse Keeper runs on dedicated hosts.
+:::
+
+#### Macros configuration {#macros-config-explanation}
+
+Additionally, the `` section is used to define parameter substitutions for
+replicated tables. These are listed in `system.macros` and allow using substitutions
+like `{shard}` and `{replica}` in queries.
+
+```xml
+
+ 01
+ 01
+ cluster_1S_2R
+
+```
+
+:::note
+These will be defined uniquely depending on the layout of the cluster.
+:::
+
+### User configuration {#user-config}
+
+Now modify each empty configuration file `users.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/users.d` with the following:
+
+```xml title="/users.d/users.xml"
+
+
+
+
+ 10000000000
+ 0
+ in_order
+ 1
+
+
+
+
+ 1
+ default
+
+ ::/0
+
+ default
+ 1
+ 1
+ 1
+ 1
+
+
+
+
+
+ 3600
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+
+
+```
+
+| Directory | File |
+|-----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-01/etc/clickhouse-server/users.d` | [`users.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-01/etc/clickhouse-server/users.d/users.xml) |
+| `fs/volumes/clickhouse-02/etc/clickhouse-server/users.d` | [`users.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-02/etc/clickhouse-server/users.d/users.xml) |
+
+In this example, the default user is configured without a password for simplicity.
+In practice, this is discouraged.
+
+:::note
+In this example, each `users.xml` file is identical for all nodes in the cluster.
+:::
+
+## Configure ClickHouse Keeper {#configure-clickhouse-keeper-nodes}
+
+### Keeper setup {#configuration-explanation}
+
+
+
+| Directory | File |
+|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-keeper-01/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-02/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-03/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_1S_2R/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml) |
+
+
+
+## Test the setup {#test-the-setup}
+
+Make sure that docker is running on your machine.
+Start the cluster using the `docker-compose up` command from the root of the `cluster_1S_2R` directory:
+
+```bash
+docker-compose up -d
+```
+
+You should see docker begin to pull the ClickHouse and Keeper images,
+and then start the containers:
+
+```bash
+[+] Running 6/6
+ ✔ Network cluster_1s_2r_default Created
+ ✔ Container clickhouse-keeper-03 Started
+ ✔ Container clickhouse-keeper-02 Started
+ ✔ Container clickhouse-keeper-01 Started
+ ✔ Container clickhouse-01 Started
+ ✔ Container clickhouse-02 Started
+```
+
+To verify that the cluster is running, connect to either `clickhouse-01` or `clickhouse-02` and run the
+following query. The command to connect to the first node is shown:
+
+```bash
+# Connect to any node
+docker exec -it clickhouse-01 clickhouse-client
+```
+
+If successful, you will see the ClickHouse client prompt:
+
+```response
+cluster_1S_2R node 1 :)
+```
+
+Run the following query to check what cluster topologies are defined for which
+hosts:
+
+```sql title="Query"
+SELECT
+ cluster,
+ shard_num,
+ replica_num,
+ host_name,
+ port
+FROM system.clusters;
+```
+
+```response title="Response"
+ ┌─cluster───────┬─shard_num─┬─replica_num─┬─host_name─────┬─port─┐
+1. │ cluster_1S_2R │ 1 │ 1 │ clickhouse-01 │ 9000 │
+2. │ cluster_1S_2R │ 1 │ 2 │ clickhouse-02 │ 9000 │
+3. │ default │ 1 │ 1 │ localhost │ 9000 │
+ └───────────────┴───────────┴─────────────┴───────────────┴──────┘
+```
+
+Run the following query to check the status of the ClickHouse Keeper cluster:
+
+```sql title="Query"
+SELECT *
+FROM system.zookeeper
+WHERE path IN ('/', '/clickhouse')
+```
+
+```response title="Response"
+ ┌─name───────┬─value─┬─path────────┐
+1. │ sessions │ │ /clickhouse │
+2. │ task_queue │ │ /clickhouse │
+3. │ keeper │ │ / │
+4. │ clickhouse │ │ / │
+ └────────────┴───────┴─────────────┘
+```
+
+
+
+With this, you have successfully set up a ClickHouse cluster with a single shard and two replicas.
+In the next step, you will create a table in the cluster.
+
+## Create a database {#creating-a-database}
+
+Now that you have verified the cluster is correctly setup and is running, you
+will be recreating the same table as the one used in the [UK property prices](/getting-started/example-datasets/uk-price-paid)
+example dataset tutorial. It consists of around 30 million rows of prices paid
+for real-estate property in England and Wales since 1995.
+
+Connect to the client of each host by running each of the following commands from separate terminal
+tabs or windows:
+
+```bash
+docker exec -it clickhouse-01 clickhouse-client
+docker exec -it clickhouse-02 clickhouse-client
+```
+
+You can run the query below from clickhouse-client of each host to confirm that
+there are no databases created yet, apart from the default ones:
+
+```sql title="Query"
+SHOW DATABASES;
+```
+
+```response title="Response"
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+ └────────────────────┘
+```
+
+From the `clickhouse-01` client run the following **distributed** DDL query using the
+`ON CLUSTER` clause to create a new database called `uk`:
+
+```sql
+CREATE DATABASE IF NOT EXISTS uk
+-- highlight-next-line
+ON CLUSTER cluster_1S_2R;
+```
+
+You can again run the same query as before from the client of each host
+to confirm that the database has been created across the cluster despite running
+the query only `clickhouse-01`:
+
+```sql
+SHOW DATABASES;
+```
+
+```response
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+#highlight-next-line
+5. │ uk │
+ └────────────────────┘
+```
+
+## Create a table on the cluster {#creating-a-table}
+
+Now that the database has been created, create a table on the cluster.
+Run the following query from any of the host clients:
+
+```sql
+CREATE TABLE IF NOT EXISTS uk.uk_price_paid_local
+--highlight-next-line
+ON CLUSTER cluster_1S_2R
+(
+ price UInt32,
+ date Date,
+ postcode1 LowCardinality(String),
+ postcode2 LowCardinality(String),
+ type Enum8('terraced' = 1, 'semi-detached' = 2, 'detached' = 3, 'flat' = 4, 'other' = 0),
+ is_new UInt8,
+ duration Enum8('freehold' = 1, 'leasehold' = 2, 'unknown' = 0),
+ addr1 String,
+ addr2 String,
+ street LowCardinality(String),
+ locality LowCardinality(String),
+ town LowCardinality(String),
+ district LowCardinality(String),
+ county LowCardinality(String)
+)
+--highlight-next-line
+ENGINE = ReplicatedMergeTree
+ORDER BY (postcode1, postcode2, addr1, addr2);
+```
+
+Notice that it is identical to the query used in the original `CREATE` statement of the
+[UK property prices](/getting-started/example-datasets/uk-price-paid) example dataset tutorial,
+except for the `ON CLUSTER` clause and use of the `ReplicatedMergeTree` engine.
+
+The `ON CLUSTER` clause is designed for distributed execution of DDL (Data Definition Language)
+queries such as `CREATE`, `DROP`, `ALTER`, and `RENAME`, ensuring that these
+schema changes are applied across all nodes in a cluster.
+
+The [`ReplicatedMergeTree`](https://clickhouse.com/docs/engines/table-engines/mergetree-family/replication#converting-from-mergetree-to-replicatedmergetree)
+engine works just as the ordinary `MergeTree` table engine, but it will also replicate the data.
+
+You can run the query below from either `clickhouse-01` or `clickhouse-02` client
+to confirm that the table has been created across the cluster:
+
+```sql title="Query"
+SHOW TABLES IN uk;
+```
+
+```response title="Response"
+ ┌─name────────────────┐
+1. │ uk_price_paid. │
+ └─────────────────────┘
+```
+
+## Insert data {#inserting-data}
+
+As the data set is large and takes a few minutes to completely ingest, we will
+insert only a small subset to begin with.
+
+Insert a smaller subset of the data using the query below from `clickhouse-01`:
+
+```sql
+INSERT INTO uk.uk_price_paid_local
+SELECT
+ toUInt32(price_string) AS price,
+ parseDateTimeBestEffortUS(time) AS date,
+ splitByChar(' ', postcode)[1] AS postcode1,
+ splitByChar(' ', postcode)[2] AS postcode2,
+ transform(a, ['T', 'S', 'D', 'F', 'O'], ['terraced', 'semi-detached', 'detached', 'flat', 'other']) AS type,
+ b = 'Y' AS is_new,
+ transform(c, ['F', 'L', 'U'], ['freehold', 'leasehold', 'unknown']) AS duration,
+ addr1,
+ addr2,
+ street,
+ locality,
+ town,
+ district,
+ county
+FROM url(
+ 'http://prod1.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-complete.csv',
+ 'CSV',
+ 'uuid_string String,
+ price_string String,
+ time String,
+ postcode String,
+ a String,
+ b String,
+ c String,
+ addr1 String,
+ addr2 String,
+ street String,
+ locality String,
+ town String,
+ district String,
+ county String,
+ d String,
+ e String'
+) SETTINGS max_http_get_redirects=10;
+LIMIT 10000;
+```
+
+Notice that the data is completely replicated on each host:
+
+```sql
+-- clickhouse-01
+SELECT count(*)
+FROM uk.uk_price_paid_local
+
+-- ┌─count()─┐
+-- 1.│ 10000 │
+-- └─────────┘
+
+-- clickhouse-02
+SELECT count(*)
+FROM uk.uk_price_paid_local
+
+-- ┌─count()─┐
+-- 1.│ 10000 │
+-- └─────────┘
+```
+
+To demonstrate what happens when one of the hosts fails, create a simple test database
+and test table from either of the hosts:
+
+```sql
+CREATE DATABASE IF NOT EXISTS test ON CLUSTER cluster_1S_2R;
+CREATE TABLE test.test_table ON CLUSTER cluster_1S_2R
+(
+ `id` UInt64,
+ `name` String
+)
+ENGINE = ReplicatedMergeTree
+ORDER BY id;
+```
+
+As with the `uk_price_paid` table, we can insert data from either host:
+
+```sql
+INSERT INTO test.test_table (id, name) VALUES (1, 'Clicky McClickface');
+```
+
+But what will happen if one of the hosts is down? To simulate this, stop
+`clickhouse-01` by running:
+
+```bash
+docker stop clickhouse-01
+```
+
+Check that the host is down by running:
+
+```bash
+docker-compose ps
+```
+
+```response title="Response"
+NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
+clickhouse-02 clickhouse/clickhouse-server:latest "/entrypoint.sh" clickhouse-02 X minutes ago Up X minutes 127.0.0.1:8124->8123/tcp, 127.0.0.1:9001->9000/tcp
+clickhouse-keeper-01 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-01 X minutes ago Up X minutes 127.0.0.1:9181->9181/tcp
+clickhouse-keeper-02 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-02 X minutes ago Up X minutes 127.0.0.1:9182->9181/tcp
+clickhouse-keeper-03 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-03 X minutes ago Up X minutes 127.0.0.1:9183->9181/tcp
+```
+
+With `clickhouse-01` now down, insert another row of data into the test table
+and query the table:
+
+```sql
+INSERT INTO test.test_table (id, name) VALUES (2, 'Alexey Milovidov');
+SELECT * FROM test.test_table;
+```
+
+```response title="Response"
+ ┌─id─┬─name───────────────┐
+1. │ 1 │ Clicky McClickface │
+2. │ 2 │ Alexey Milovidov │
+ └────┴────────────────────┘
+```
+
+Now restart `clickhouse-01` with the following command (you can run `docker-compose ps` again after to confirm):
+
+```sql
+docker start clickhouse-01
+```
+
+Query the test table again from `clickhouse-01` after running `docker exec -it clickhouse-01 clickhouse-client`:
+
+```sql title="Query"
+SELECT * FROM test.test_table
+```
+
+```response title="Response"
+ ┌─id─┬─name───────────────┐
+1. │ 1 │ Clicky McClickface │
+2. │ 2 │ Alexey Milovidov │
+ └────┴────────────────────┘
+```
+
+If at this stage you would like to ingest the full UK property price dataset
+to play around with, you can run the following queries to do so:
+
+```sql
+TRUNCATE TABLE uk.uk_price_paid_local ON CLUSTER cluster_1S_2R;
+INSERT INTO uk.uk_price_paid_local
+SELECT
+ toUInt32(price_string) AS price,
+ parseDateTimeBestEffortUS(time) AS date,
+ splitByChar(' ', postcode)[1] AS postcode1,
+ splitByChar(' ', postcode)[2] AS postcode2,
+ transform(a, ['T', 'S', 'D', 'F', 'O'], ['terraced', 'semi-detached', 'detached', 'flat', 'other']) AS type,
+ b = 'Y' AS is_new,
+ transform(c, ['F', 'L', 'U'], ['freehold', 'leasehold', 'unknown']) AS duration,
+ addr1,
+ addr2,
+ street,
+ locality,
+ town,
+ district,
+ county
+FROM url(
+ 'http://prod1.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-complete.csv',
+ 'CSV',
+ 'uuid_string String,
+ price_string String,
+ time String,
+ postcode String,
+ a String,
+ b String,
+ c String,
+ addr1 String,
+ addr2 String,
+ street String,
+ locality String,
+ town String,
+ district String,
+ county String,
+ d String,
+ e String'
+ ) SETTINGS max_http_get_redirects=10;
+LIMIT 10000;
+```
+
+Query the table from `clickhouse-02` or `clickhouse-01`:
+
+```sql title="Query"
+SELECT count(*) FROM uk.uk_price_paid_local;
+```
+
+```response title="Response"
+ ┌──count()─┐
+1. │ 30212555 │ -- 30.21 million
+ └──────────┘
+```
+
+
+
+## Conclusion {#conclusion}
+
+The advantage of this cluster topology is that with two replicas,
+your data exists on two separate hosts. If one host fails, the other replica
+continues serving data without any loss. This eliminates single points of
+failure at the storage level.
+
+When one host goes down, the remaining replica is still able to:
+- Handle read queries without interruption
+- Accept new writes (depending on your consistency settings)
+- Maintain service availability for applications
+
+When the failed host comes back online, it is able to:
+- Automatically sync missing data from the healthy replica
+- Resume normal operations without manual intervention
+- Restore full redundancy quickly
+
+In the next example, we'll look at how to set up a cluster with two shards but
+only one replica.
diff --git a/docs/deployment-guides/replication-sharding-examples/02_2_shards_1_replica.md b/docs/deployment-guides/replication-sharding-examples/02_2_shards_1_replica.md
new file mode 100644
index 00000000000..f367445dd07
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/02_2_shards_1_replica.md
@@ -0,0 +1,828 @@
+---
+slug: /architecture/horizontal-scaling
+sidebar_label: 'Scaling'
+sidebar_position: 10
+title: 'Scaling'
+description: 'Page describing an example architecture designed to provide scalability'
+---
+
+import Image from '@theme/IdealImage';
+import ReplicationShardingTerminology from '@site/docs/_snippets/_replication-sharding-terminology.md';
+import ShardingArchitecture from '@site/static/images/deployment-guides/replication-sharding-examples/sharding.png';
+import ConfigFileNote from '@site/docs/_snippets/_config-files.md';
+import KeeperConfigFileNote from '@site/docs/_snippets/_keeper-config-files.md';
+import ConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx';
+import ListenHost from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx';
+import ServerParameterTable from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_server_parameter_table.mdx';
+import KeeperConfig from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx';
+import KeeperConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx';
+import VerifyKeeperStatus from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx';
+import DedicatedKeeperServers from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx';
+import ExampleFiles from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx';
+
+> In this example, you'll learn how to set up a simple ClickHouse cluster which
+scales. There are five servers configured. Two are used to shard the data.
+The other three servers are used for coordination.
+
+The architecture of the cluster you will be setting up is shown below:
+
+
+
+
+
+## Prerequisites {#pre-requisites}
+
+- You've set up a [local ClickHouse server](/install) before
+- You are familiar with basic configuration concepts of ClickHouse such as [configuration files](/operations/configuration-files)
+- You have docker installed on your machine
+
+
+
+## Set up directory structure and test environment {#set-up}
+
+
+
+In this tutorial, you will use [Docker compose](https://docs.docker.com/compose/) to
+set up the ClickHouse cluster. This setup could be modified to work
+for separate local machines, virtual machines or cloud instances as well.
+
+Run the following commands to set up the directory structure for this example:
+
+```bash
+mkdir cluster_2S_1R
+cd cluster_2S_1R
+
+# Create clickhouse-keeper directories
+for i in {01..03}; do
+ mkdir -p fs/volumes/clickhouse-keeper-${i}/etc/clickhouse-keeper
+done
+
+# Create clickhouse-server directories
+for i in {01..02}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server
+done
+```
+
+Add the following `docker-compose.yml` file to the `clickhouse-cluster` directory:
+
+```yaml title="docker-compose.yml"
+version: '3.8'
+services:
+ clickhouse-01:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-01
+ hostname: clickhouse-01
+ networks:
+ cluster_2S_1R:
+ ipv4_address: 192.168.7.1
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8123:8123"
+ - "127.0.0.1:9000:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-02:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-02
+ hostname: clickhouse-02
+ networks:
+ cluster_2S_1R:
+ ipv4_address: 192.168.7.2
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8124:8123"
+ - "127.0.0.1:9001:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-keeper-01:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-01
+ hostname: clickhouse-keeper-01
+ networks:
+ cluster_2S_1R:
+ ipv4_address: 192.168.7.5
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9181:9181"
+ clickhouse-keeper-02:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-02
+ hostname: clickhouse-keeper-02
+ networks:
+ cluster_2S_1R:
+ ipv4_address: 192.168.7.6
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9182:9181"
+ clickhouse-keeper-03:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-03
+ hostname: clickhouse-keeper-03
+ networks:
+ cluster_2S_1R:
+ ipv4_address: 192.168.7.7
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9183:9181"
+networks:
+ cluster_2S_1R:
+ driver: bridge
+ ipam:
+ config:
+ - subnet: 192.168.7.0/24
+ gateway: 192.168.7.254
+```
+
+Create the following sub-directories and files:
+
+```bash
+for i in {01..02}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d/config.xml
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d/users.xml
+done
+```
+
+
+
+## Configure ClickHouse nodes {#configure-clickhouse-servers}
+
+### Server setup {#server-setup}
+
+Now modify each empty configuration file `config.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/config.d`. The lines which are
+highlighted below need to be changed to be specific to each node:
+
+```xml
+
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+
+ cluster_2S_1R node 1
+ 0.0.0.0
+ 8123
+ 9000
+
+
+ users.xml
+
+
+ /var/lib/clickhouse/access/
+
+
+
+ /clickhouse/task_queue/ddl
+
+
+
+
+
+ clickhouse-01
+ 9000
+
+
+
+
+ clickhouse-02
+ 9000
+
+
+
+
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+
+
+ 01
+ 01
+
+
+
+```
+
+| Directory | File |
+|-----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-01/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml) |
+| `fs/volumes/clickhouse-02/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml) |
+
+Each section of the above configuration file is explained in more detail below.
+
+#### Networking and logging {#networking}
+
+
+
+Logging is defined in the `` block. This example configuration gives
+you a debug log that will roll over at 1000M three times:
+
+```xml
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+```
+
+For more information on logging configuration, see the comments included in the
+default ClickHouse [configuration file](https://github.com/ClickHouse/ClickHouse/blob/master/programs/server/config.xml).
+
+#### Cluster configuration {#cluster-configuration}
+
+Configuration for the cluster is set up in the `` block.
+Here the cluster name `cluster_2S_1R` is defined.
+
+The `` block defines the layout of the cluster,
+using the `` and `` settings, and acts as a
+template for distributed DDL queries, which are queries that execute across the
+cluster using the `ON CLUSTER` clause. By default, distributed DDL queries
+are allowed, but can also be turned off with setting `allow_distributed_ddl_queries`.
+
+`internal_replication` is set to true so that data is written to just one of the replicas.
+
+```xml
+
+
+
+
+ clickhouse-01
+ 9000
+
+
+
+
+ clickhouse-02
+ 9000
+
+
+
+
+```
+
+
+
+#### Keeper configuration {#keeper-config-explanation}
+
+The `` section tells ClickHouse where ClickHouse Keeper (or ZooKeeper) is running.
+As we are using a ClickHouse Keeper cluster, each `` of the cluster needs to be specified,
+along with its hostname and port number using the `` and `` tags respectively.
+
+Set up of ClickHouse Keeper is explained in the next step of the tutorial.
+
+```xml
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+```
+
+:::note
+Although it is possible to run ClickHouse Keeper on the same server as ClickHouse Server,
+in production environments we strongly recommend that ClickHouse Keeper runs on dedicated hosts.
+:::
+
+#### Macros configuration {#macros-config-explanation}
+
+Additionally, the `` section is used to define parameter substitutions for
+replicated tables. These are listed in `system.macros` and allow using substitutions
+like `{shard}` and `{replica}` in queries.
+
+```xml
+
+ 01
+ 01
+
+```
+
+:::note
+These will be defined uniquely depending on the layout of the cluster.
+:::
+
+### User configuration {#user-config}
+
+Now modify each empty configuration file `users.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/users.d` with the following:
+
+```xml title="/users.d/users.xml"
+
+
+
+
+ 10000000000
+ 0
+ in_order
+ 1
+
+
+
+
+ 1
+ default
+
+ ::/0
+
+ default
+ 1
+ 1
+ 1
+ 1
+
+
+
+
+
+ 3600
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+
+
+```
+
+| Directory | File |
+|-----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-01/etc/clickhouse-server/users.d` | [`users.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-01/etc/clickhouse-server/users.d/users.xml) |
+| `fs/volumes/clickhouse-02/etc/clickhouse-server/users.d` | [`users.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-02/etc/clickhouse-server/users.d/users.xml) |
+
+In this example, the default user is configured without a password for simplicity.
+In practice, this is discouraged.
+
+:::note
+In this example, each `users.xml` file is identical for all nodes in the cluster.
+:::
+
+## Configure ClickHouse Keeper {#configure-clickhouse-keeper-nodes}
+
+### Keeper setup {#configuration-explanation}
+
+
+
+| Directory | File |
+|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-keeper-01/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-02/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-03/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_1R/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml) |
+
+
+
+## Test the setup {#test-the-setup}
+
+Make sure that docker is running on your machine.
+Start the cluster using the `docker-compose up` command from the root of the `cluster_2S_1R` directory:
+
+```bash
+docker-compose up -d
+```
+
+You should see docker begin to pull the ClickHouse and Keeper images,
+and then start the containers:
+
+```bash
+[+] Running 6/6
+ ✔ Network cluster_2s_1r_default Created
+ ✔ Container clickhouse-keeper-03 Started
+ ✔ Container clickhouse-keeper-02 Started
+ ✔ Container clickhouse-keeper-01 Started
+ ✔ Container clickhouse-01 Started
+ ✔ Container clickhouse-02 Started
+```
+
+To verify that the cluster is running, connect to either `clickhouse-01` or `clickhouse-02` and run the
+following query. The command to connect to the first node is shown:
+
+```bash
+# Connect to any node
+docker exec -it clickhouse-01 clickhouse-client
+```
+
+If successful, you will see the ClickHouse client prompt:
+
+```response
+cluster_2S_1R node 1 :)
+```
+
+Run the following query to check what cluster topologies are defined for which
+hosts:
+
+```sql title="Query"
+SELECT
+ cluster,
+ shard_num,
+ replica_num,
+ host_name,
+ port
+FROM system.clusters;
+```
+
+```response title="Response"
+ ┌─cluster───────┬─shard_num─┬─replica_num─┬─host_name─────┬─port─┐
+1. │ cluster_2S_1R │ 1 │ 1 │ clickhouse-01 │ 9000 │
+2. │ cluster_2S_1R │ 2 │ 1 │ clickhouse-02 │ 9000 │
+3. │ default │ 1 │ 1 │ localhost │ 9000 │
+ └───────────────┴───────────┴─────────────┴───────────────┴──────┘
+```
+
+Run the following query to check the status of the ClickHouse Keeper cluster:
+
+```sql title="Query"
+SELECT *
+FROM system.zookeeper
+WHERE path IN ('/', '/clickhouse')
+```
+
+```response title="Response"
+ ┌─name───────┬─value─┬─path────────┐
+1. │ task_queue │ │ /clickhouse │
+2. │ sessions │ │ /clickhouse │
+3. │ clickhouse │ │ / │
+4. │ keeper │ │ / │
+ └────────────┴───────┴─────────────┘
+```
+
+
+
+With this, you have successfully set up a ClickHouse cluster with a single shard and two replicas.
+In the next step, you will create a table in the cluster.
+
+## Create a database {#creating-a-database}
+
+Now that you have verified the cluster is correctly setup and is running, you
+will be recreating the same table as the one used in the [UK property prices](/getting-started/example-datasets/uk-price-paid)
+example dataset tutorial. It consists of around 30 million rows of prices paid
+for real-estate property in England and Wales since 1995.
+
+Connect to the client of each host by running each of the following commands from separate terminal
+tabs or windows:
+
+```bash
+docker exec -it clickhouse-01 clickhouse-client
+docker exec -it clickhouse-02 clickhouse-client
+```
+
+You can run the query below from clickhouse-client of each host to confirm that
+there are no databases created yet, apart from the default ones:
+
+```sql title="Query"
+SHOW DATABASES;
+```
+
+```response title="Response"
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+ └────────────────────┘
+```
+
+From the `clickhouse-01` client run the following **distributed** DDL query using the
+`ON CLUSTER` clause to create a new database called `uk`:
+
+```sql
+CREATE DATABASE IF NOT EXISTS uk
+-- highlight-next-line
+ON CLUSTER cluster_2S_1R;
+```
+
+You can again run the same query as before from the client of each host
+to confirm that the database has been created across the cluster despite running
+the query only `clickhouse-01`:
+
+```sql
+SHOW DATABASES;
+```
+
+```response
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+#highlight-next-line
+5. │ uk │
+ └────────────────────┘
+```
+
+## Create a table on the cluster {#creating-a-table}
+
+Now that the database has been created, you will create a distributed table.
+Distributed tables are tables which have access to shards located on different
+hosts and are defined using the `Distributed` table engine. The distributed table
+acts as the interface across all the shards in the cluster.
+
+Run the following query from any of the host clients:
+
+```sql
+CREATE TABLE IF NOT EXISTS uk.uk_price_paid_local
+--highlight-next-line
+ON CLUSTER cluster_2S_1R
+(
+ price UInt32,
+ date Date,
+ postcode1 LowCardinality(String),
+ postcode2 LowCardinality(String),
+ type Enum8('terraced' = 1, 'semi-detached' = 2, 'detached' = 3, 'flat' = 4, 'other' = 0),
+ is_new UInt8,
+ duration Enum8('freehold' = 1, 'leasehold' = 2, 'unknown' = 0),
+ addr1 String,
+ addr2 String,
+ street LowCardinality(String),
+ locality LowCardinality(String),
+ town LowCardinality(String),
+ district LowCardinality(String),
+ county LowCardinality(String)
+)
+ENGINE = MergeTree
+ORDER BY (postcode1, postcode2, addr1, addr2);
+```
+
+Notice that it is identical to the query used in the original `CREATE` statement of the
+[UK property prices](/getting-started/example-datasets/uk-price-paid) example dataset tutorial,
+except for the `ON CLUSTER` clause.
+
+The `ON CLUSTER` clause is designed for distributed execution of DDL (Data Definition Language)
+queries such as `CREATE`, `DROP`, `ALTER`, and `RENAME`, ensuring that these
+schema changes are applied across all nodes in a cluster.
+
+You can run the query below from each host's client to confirm that the table has been created across the cluster:
+
+```sql title="Query"
+SHOW TABLES IN uk;
+```
+
+```response title="Response"
+ ┌─name────────────────┐
+1. │ uk_price_paid_local │
+ └─────────────────────┘
+```
+
+## Insert data into a distributed table {#inserting-data}
+
+Before we insert the UK price paid data, let's perform a quick experiment to see
+what happens when we insert data into an ordinary table from either host.
+
+Create a test database and table with the following query from either host:
+
+```sql
+CREATE DATABASE IF NOT EXISTS test ON CLUSTER cluster_2S_1R;
+CREATE TABLE test.test_table ON CLUSTER cluster_2S_1R
+(
+ `id` UInt64,
+ `name` String
+)
+ENGINE = ReplicatedMergeTree
+ORDER BY id;
+```
+
+Now from `clickhouse-01` run the following `INSERT` query:
+
+```sql
+INSERT INTO test.test_table (id, name) VALUES (1, 'Clicky McClickface');
+```
+
+Switch over to `clickhouse-02` and run the following `INSERT` query:
+
+```sql title="Query"
+INSERT INTO test.test_table (id, name) VALUES (1, 'Alexey Milovidov');
+```
+
+Now from `clickhouse-01` or `clickhouse-02` run the following query:
+
+```sql
+-- from clickhouse-01
+SELECT * FROM test.test_table;
+-- ┌─id─┬─name───────────────┐
+-- 1.│ 1 │ Clicky McClickface │
+-- └────┴────────────────────┘
+
+--from clickhouse-02
+SELECT * FROM test.test_table;
+-- ┌─id─┬─name───────────────┐
+-- 1.│ 1 │ Alexey Milovidov │
+-- └────┴────────────────────┘
+```
+
+You will notice that only the row that was inserted into the table on that
+particular host is returned and not both rows.
+
+To read the data from the two shards we need an interface which can handle queries
+across all the shards, combining the data from both shards when we run select queries
+on it, and handling the insertion of data to the separate shards when we run insert queries.
+
+In ClickHouse this interface is called a distributed table, which we create using
+the [`Distributed`](/engines/table-engines/special/distributed) table engine. Let's take a look at how it works.
+
+Create a distributed table with the following query:
+
+```sql
+CREATE TABLE test.test_table_dist ON CLUSTER cluster_2S_1R AS test.test_table
+ENGINE = Distributed('cluster_2S_1R', 'test', 'test_table', rand())
+```
+
+In this example, the `rand()` function is chosen as the sharding key so that
+inserts are randomly distributed across the shards.
+
+Now query the distributed table from either host and you will get back
+both of the rows which were inserted on the two hosts:
+
+```sql
+ ┌─id─┬─name───────────────┐
+1. │ 1 │ Alexey Milovidov │
+2. │ 1 │ Clicky McClickface │
+ └────┴────────────────────┘
+```
+
+Let's do the same for our UK property prices data. From any of the host clients,
+run the following query to create a distributed table using the existing table
+we created previously with `ON CLUSTER`:
+
+```sql
+CREATE TABLE IF NOT EXISTS uk.uk_price_paid_distributed
+ON CLUSTER cluster_2S_1R
+ENGINE = Distributed('cluster_2S_1R', 'uk', 'uk_price_paid_local', rand());
+```
+
+Now connect to either of the hosts and insert the data:
+
+```sql
+INSERT INTO uk.uk_price_paid_distributed
+SELECT
+ toUInt32(price_string) AS price,
+ parseDateTimeBestEffortUS(time) AS date,
+ splitByChar(' ', postcode)[1] AS postcode1,
+ splitByChar(' ', postcode)[2] AS postcode2,
+ transform(a, ['T', 'S', 'D', 'F', 'O'], ['terraced', 'semi-detached', 'detached', 'flat', 'other']) AS type,
+ b = 'Y' AS is_new,
+ transform(c, ['F', 'L', 'U'], ['freehold', 'leasehold', 'unknown']) AS duration,
+ addr1,
+ addr2,
+ street,
+ locality,
+ town,
+ district,
+ county
+FROM url(
+ 'http://prod1.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-complete.csv',
+ 'CSV',
+ 'uuid_string String,
+ price_string String,
+ time String,
+ postcode String,
+ a String,
+ b String,
+ c String,
+ addr1 String,
+ addr2 String,
+ street String,
+ locality String,
+ town String,
+ district String,
+ county String,
+ d String,
+ e String'
+) SETTINGS max_http_get_redirects=10;
+```
+
+Once the data is inserted, you can check the number of rows using the distributed
+table:
+
+```sql title="Query"
+SELECT count(*)
+FROM uk.uk_price_paid_distributed
+```
+
+```response title="Response"
+ ┌──count()─┐
+1. │ 30212555 │ -- 30.21 million
+ └──────────┘
+```
+
+If you run the following query on either host you will see that the data has been
+more or less evenly distributed across the shards (keeping in mind the choice of which
+shard to insert into was set with `rand()` so results may differ for you):
+
+```sql
+-- from clickhouse-01
+SELECT count(*)
+FROM uk.uk_price_paid_local
+-- ┌──count()─┐
+-- 1. │ 15107353 │ -- 15.11 million
+-- └──────────┘
+
+--from clickhouse-02
+SELECT count(*)
+FROM uk.uk_price_paid_local
+-- ┌──count()─┐
+-- 1. │ 15105202 │ -- 15.11 million
+-- └──────────┘
+```
+
+What will happen if one of the hosts fails? Let's simulate this by shutting down
+`clickhouse-01`:
+
+```bash
+docker stop clickhouse-01
+```
+
+Check that the host is down by running:
+
+```bash
+docker-compose ps
+```
+
+```response title="Response"
+NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
+clickhouse-02 clickhouse/clickhouse-server:latest "/entrypoint.sh" clickhouse-02 X minutes ago Up X minutes 127.0.0.1:8124->8123/tcp, 127.0.0.1:9001->9000/tcp
+clickhouse-keeper-01 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-01 X minutes ago Up X minutes 127.0.0.1:9181->9181/tcp
+clickhouse-keeper-02 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-02 X minutes ago Up X minutes 127.0.0.1:9182->9181/tcp
+clickhouse-keeper-03 clickhouse/clickhouse-keeper:latest-alpine "/entrypoint.sh" clickhouse-keeper-03 X minutes ago Up X minutes 127.0.0.1:9183->9181/tcp
+```
+
+Now from `clickhouse-02` run the same select query we ran before on the distributed
+table:
+
+```sql
+SELECT count(*)
+FROM uk.uk_price_paid_distributed
+```
+
+```response title="Response"
+Received exception from server (version 25.5.2):
+Code: 279. DB::Exception: Received from localhost:9000. DB::Exception: All connection tries failed. Log:
+
+Code: 32. DB::Exception: Attempt to read after eof. (ATTEMPT_TO_READ_AFTER_EOF) (version 25.5.2.47 (official build))
+Code: 209. DB::NetException: Timeout: connect timed out: 192.168.7.1:9000 (clickhouse-01:9000, 192.168.7.1, local address: 192.168.7.2:37484, connection timeout 1000 ms). (SOCKET_TIMEOUT) (version 25.5.2.47 (official build))
+#highlight-next-line
+Code: 198. DB::NetException: Not found address of host: clickhouse-01: (clickhouse-01:9000, 192.168.7.1, local address: 192.168.7.2:37484). (DNS_ERROR) (version 25.5.2.47 (official build))
+
+: While executing Remote. (ALL_CONNECTION_TRIES_FAILED)
+```
+
+Unfortunately, our cluster is not fault-tolerant. If one of the hosts fails, the
+cluster is considered unhealthy and the query fails compared to the replicated
+table we saw in the [previous example](/architecture/replication) for which
+we were able to insert data even when one of the hosts failed.
+
+
+
+## Conclusion {#conclusion}
+
+The advantage of this cluster topology is that data gets distributed across
+separate hosts and uses half the storage per node. More importantly, queries
+are processed across both shards, which is more efficient in terms of memory
+utilization and reduces I/O per host.
+
+The main disadvantage of this cluster topology is, of course, that losing one of
+the hosts renders us unable to serve queries.
+
+In the [next example](/architecture/cluster-deployment), we'll look at how to
+set up a cluster with two shards and two replicas offering both scalability and
+fault tolerance.
diff --git a/docs/deployment-guides/replication-sharding-examples/03_2_shards_2_replicas.md b/docs/deployment-guides/replication-sharding-examples/03_2_shards_2_replicas.md
new file mode 100644
index 00000000000..0fed83e9f9c
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/03_2_shards_2_replicas.md
@@ -0,0 +1,748 @@
+---
+slug: /architecture/cluster-deployment
+sidebar_label: 'Replication + Scaling'
+sidebar_position: 100
+title: 'Replication + Scaling'
+description: 'By going through this tutorial, you will learn how to set up a simple ClickHouse cluster.'
+---
+
+import Image from '@theme/IdealImage';
+import SharedReplicatedArchitecture from '@site/static/images/deployment-guides/replication-sharding-examples/both.png';
+import ConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx';
+import ListenHost from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx';
+import KeeperConfig from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx';
+import KeeperConfigExplanation from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx';
+import VerifyKeeperStatus from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx';
+import DedicatedKeeperServers from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx';
+import ExampleFiles from '@site/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx';
+
+> In this example, you'll learn how to set up a simple ClickHouse cluster which
+both replicates and scales. It consisting of two shards and two replicas with a
+3-node ClickHouse Keeper cluster for managing coordination and keeping quorum
+in the cluster.
+
+The architecture of the cluster you will be setting up is shown below:
+
+
+
+
+
+## Prerequisites {#prerequisites}
+
+- You've set up a [local ClickHouse server](/install) before
+- You are familiar with basic configuration concepts of ClickHouse such as [configuration files](/operations/configuration-files)
+- You have docker installed on your machine
+
+
+
+## Set up directory structure and test environment {#set-up}
+
+
+
+In this tutorial, you will use [Docker compose](https://docs.docker.com/compose/) to
+set up the ClickHouse cluster. This setup could be modified to work
+for separate local machines, virtual machines or cloud instances as well.
+
+Run the following commands to set up the directory structure for this example:
+
+```bash
+mkdir cluster_2S_2R
+cd cluster_2S_2R
+
+# Create clickhouse-keeper directories
+for i in {01..03}; do
+ mkdir -p fs/volumes/clickhouse-keeper-${i}/etc/clickhouse-keeper
+done
+
+# Create clickhouse-server directories
+for i in {01..04}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server
+done
+```
+
+Add the following `docker-compose.yml` file to the `clickhouse-cluster` directory:
+
+```yaml title="docker-compose.yml"
+version: '3.8'
+services:
+ clickhouse-01:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-01
+ hostname: clickhouse-01
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-01/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8123:8123"
+ - "127.0.0.1:9000:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-02:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-02
+ hostname: clickhouse-02
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-02/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8124:8123"
+ - "127.0.0.1:9001:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-03:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-03
+ hostname: clickhouse-03
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-03/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-03/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8125:8123"
+ - "127.0.0.1:9002:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-04:
+ image: "clickhouse/clickhouse-server:latest"
+ user: "101:101"
+ container_name: clickhouse-04
+ hostname: clickhouse-04
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-04/etc/clickhouse-server/config.d/config.xml:/etc/clickhouse-server/config.d/config.xml
+ - ${PWD}/fs/volumes/clickhouse-04/etc/clickhouse-server/users.d/users.xml:/etc/clickhouse-server/users.d/users.xml
+ ports:
+ - "127.0.0.1:8126:8123"
+ - "127.0.0.1:9003:9000"
+ depends_on:
+ - clickhouse-keeper-01
+ - clickhouse-keeper-02
+ - clickhouse-keeper-03
+ clickhouse-keeper-01:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-01
+ hostname: clickhouse-keeper-01
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9181:9181"
+ clickhouse-keeper-02:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-02
+ hostname: clickhouse-keeper-02
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9182:9181"
+ clickhouse-keeper-03:
+ image: "clickhouse/clickhouse-keeper:latest-alpine"
+ user: "101:101"
+ container_name: clickhouse-keeper-03
+ hostname: clickhouse-keeper-03
+ volumes:
+ - ${PWD}/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
+ ports:
+ - "127.0.0.1:9183:9181"
+```
+
+Create the following sub-directories and files:
+
+```bash
+for i in {01..04}; do
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d
+ mkdir -p fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/config.d/config.xml
+ touch fs/volumes/clickhouse-${i}/etc/clickhouse-server/users.d/users.xml
+done
+```
+
+
+
+## Configure ClickHouse nodes {#configure-clickhouse-servers}
+
+### Server setup {#server-setup}
+
+Now modify each empty configuration file `config.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/config.d`. The lines which are
+highlighted below need to be changed to be specific to each node:
+
+```xml
+
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+
+ cluster_2S_2R node 1
+ 0.0.0.0
+ 8123
+ 9000
+
+
+ users.xml
+
+
+ /var/lib/clickhouse/access/
+
+
+
+ /clickhouse/task_queue/ddl
+
+
+
+
+ true
+
+ clickhouse-01
+ 9000
+
+
+ clickhouse-03
+ 9000
+
+
+
+ true
+
+ clickhouse-02
+ 9000
+
+
+ clickhouse-04
+ 9000
+
+
+
+
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+
+
+ 01
+ 01
+
+
+
+```
+
+| Directory | File |
+|-----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-01/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-01/etc/clickhouse-server/config.d/config.xml) |
+| `fs/volumes/clickhouse-02/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-02/etc/clickhouse-server/config.d/config.xml) |
+| `fs/volumes/clickhouse-03/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-03/etc/clickhouse-server/config.d/config.xml) |
+| `fs/volumes/clickhouse-04/etc/clickhouse-server/config.d` | [`config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-04/etc/clickhouse-server/config.d/config.xml) |
+
+Each section of the above configuration file is explained in more detail below.
+
+#### Networking and logging {#networking}
+
+
+
+Logging configuration is defined in the `` block. This example configuration gives
+you a debug log that will roll over at 1000M three times:
+
+```xml
+
+ debug
+ /var/log/clickhouse-server/clickhouse-server.log
+ /var/log/clickhouse-server/clickhouse-server.err.log
+ 1000M
+ 3
+
+```
+
+For more information on logging configuration, see the comments included in the
+default ClickHouse [configuration file](https://github.com/ClickHouse/ClickHouse/blob/master/programs/server/config.xml).
+
+#### Cluster configuration {#cluster-config}
+
+Configuration for the cluster is set up in the `` block.
+Here the cluster name `cluster_2S_2R` is defined.
+
+The `` block defines the layout of the cluster,
+using the `` and `` settings, and acts as a
+template for distributed DDL queries, which are queries that execute across the
+cluster using the `ON CLUSTER` clause. By default, distributed DDL queries
+are allowed, but can also be turned off with setting `allow_distributed_ddl_queries`.
+
+`internal_replication` is set to true so that data is written to just one of the replicas.
+
+```xml
+
+
+
+
+
+
+ true
+
+ clickhouse-01
+ 9000
+
+
+ clickhouse-03
+ 9000
+
+
+
+ true
+
+ clickhouse-02
+ 9000
+
+
+ clickhouse-04
+ 9000
+
+
+
+
+```
+
+The `` section defines the layout of the cluster,
+and acts as a template for distributed DDL queries, which are queries that execute
+across the cluster using the `ON CLUSTER` clause.
+
+#### Keeper configuration {#keeper-config-explanation}
+
+The `` section tells ClickHouse where ClickHouse Keeper (or ZooKeeper) is running.
+As we are using a ClickHouse Keeper cluster, each `` of the cluster needs to be specified,
+along with its hostname and port number using the `` and `` tags respectively.
+
+Set up of ClickHouse Keeper is explained in the next step of the tutorial.
+
+```xml
+
+
+ clickhouse-keeper-01
+ 9181
+
+
+ clickhouse-keeper-02
+ 9181
+
+
+ clickhouse-keeper-03
+ 9181
+
+
+```
+
+:::note
+Although it is possible to run ClickHouse Keeper on the same server as ClickHouse Server,
+in production environments we strongly recommend that ClickHouse Keeper runs on dedicated hosts.
+:::
+
+#### Macros configuration {#macros-config-explanation}
+
+Additionally, the `` section is used to define parameter substitutions for
+replicated tables. These are listed in `system.macros` and allow using substitutions
+like `{shard}` and `{replica}` in queries.
+
+```xml
+
+ 01
+ 01
+
+```
+
+### User configuration {#cluster-configuration}
+
+Now modify each empty configuration file `users.xml` located at
+`fs/volumes/clickhouse-{}/etc/clickhouse-server/users.d` with the following:
+
+```xml title="/users.d/users.xml"
+
+
+
+
+ 10000000000
+ 0
+ in_order
+ 1
+
+
+
+
+ 1
+ default
+
+ ::/0
+
+ default
+ 1
+ 1
+ 1
+ 1
+
+
+
+
+
+ 3600
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+
+
+```
+
+In this example, the default user is configured without a password for simplicity.
+In practice, this is discouraged.
+
+:::note
+In this example, each `users.xml` file is identical for all nodes in the cluster.
+:::
+
+## Configure ClickHouse Keeper {#configure-clickhouse-keeper-nodes}
+
+Next you will configure ClickHouse Keeper, which is used for coordination.
+
+### Keeper setup {#configuration-explanation}
+
+
+
+| Directory | File |
+|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `fs/volumes/clickhouse-keeper-01/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-keeper-01/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-02/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-keeper-02/etc/clickhouse-keeper/keeper_config.xml) |
+| `fs/volumes/clickhouse-keeper-03/etc/clickhouse-server/config.d` | [`keeper_config.xml`](https://github.com/ClickHouse/examples/blob/main/docker-compose-recipes/recipes/cluster_2S_2R/fs/volumes/clickhouse-keeper-03/etc/clickhouse-keeper/keeper_config.xml) |
+
+
+
+## Test the setup {#test-the-setup}
+
+Make sure that docker is running on your machine.
+Start the cluster using the `docker-compose up` command from the root of the `cluster_2S_2R` directory:
+
+```bash
+docker-compose up -d
+```
+
+You should see docker begin to pull the ClickHouse and Keeper images,
+and then start the containers:
+
+```bash
+[+] Running 8/8
+ ✔ Network cluster_2s_2r_default Created
+ ✔ Container clickhouse-keeper-03 Started
+ ✔ Container clickhouse-keeper-02 Started
+ ✔ Container clickhouse-keeper-01 Started
+ ✔ Container clickhouse-01 Started
+ ✔ Container clickhouse-02 Started
+ ✔ Container clickhouse-04 Started
+ ✔ Container clickhouse-03 Started
+```
+
+To verify that the cluster is running, connect to any one of the nodes and run the
+following query. The command to connect to the first node is shown:
+
+```bash
+# Connect to any node
+docker exec -it clickhouse-01 clickhouse-client
+```
+
+If successful, you will see the ClickHouse client prompt:
+
+```response
+cluster_2S_2R node 1 :)
+```
+
+Run the following query to check what cluster topologies are defined for which
+hosts:
+
+```sql title="Query"
+SELECT
+ cluster,
+ shard_num,
+ replica_num,
+ host_name,
+ port
+FROM system.clusters;
+```
+
+```response title="Response"
+ ┌─cluster───────┬─shard_num─┬─replica_num─┬─host_name─────┬─port─┐
+1. │ cluster_2S_2R │ 1 │ 1 │ clickhouse-01 │ 9000 │
+2. │ cluster_2S_2R │ 1 │ 2 │ clickhouse-03 │ 9000 │
+3. │ cluster_2S_2R │ 2 │ 1 │ clickhouse-02 │ 9000 │
+4. │ cluster_2S_2R │ 2 │ 2 │ clickhouse-04 │ 9000 │
+5. │ default │ 1 │ 1 │ localhost │ 9000 │
+ └───────────────┴───────────┴─────────────┴───────────────┴──────┘
+```
+
+Run the following query to check the status of the ClickHouse Keeper cluster:
+
+```sql title="Query"
+SELECT *
+FROM system.zookeeper
+WHERE path IN ('/', '/clickhouse')
+```
+
+```response title="Response"
+ ┌─name───────┬─value─┬─path────────┐
+1. │ task_queue │ │ /clickhouse │
+2. │ sessions │ │ /clickhouse │
+3. │ keeper │ │ / │
+4. │ clickhouse │ │ / │
+ └────────────┴───────┴─────────────┘
+```
+
+
+
+With this, you have successfully set up a ClickHouse cluster with two shards and two replicas.
+In the next step, you will create a table in the cluster.
+
+## Create a database {#creating-a-database}
+
+Now that you have verified the cluster is correctly setup and is running, you
+will be recreating the same table as the one used in the [UK property prices](/getting-started/example-datasets/uk-price-paid)
+example dataset tutorial. It consists of around 30 million rows of prices paid
+for real-estate property in England and Wales since 1995.
+
+Connect to the client of each host by running each of the following commands from separate terminal
+tabs or windows:
+
+```bash
+docker exec -it clickhouse-01 clickhouse-client
+docker exec -it clickhouse-02 clickhouse-client
+docker exec -it clickhouse-03 clickhouse-client
+docker exec -it clickhouse-04 clickhouse-client
+```
+
+You can run the query below from clickhouse-client of each host to confirm that there are no databases created yet,
+apart from the default ones:
+
+```sql title="Query"
+SHOW DATABASES;
+```
+
+```response title="Response"
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+ └────────────────────┘
+```
+
+From the `clickhouse-01` client run the following **distributed** DDL query using the
+`ON CLUSTER` clause to create a new database called `uk`:
+
+```sql
+CREATE DATABASE IF NOT EXISTS uk
+-- highlight-next-line
+ON CLUSTER cluster_2S_2R;
+```
+
+You can again run the same query as before from the client of each host
+to confirm that the database has been created across the cluster despite running
+the query only from `clickhouse-01`:
+
+```sql
+SHOW DATABASES;
+```
+
+```response
+ ┌─name───────────────┐
+1. │ INFORMATION_SCHEMA │
+2. │ default │
+3. │ information_schema │
+4. │ system │
+#highlight-next-line
+5. │ uk │
+ └────────────────────┘
+```
+
+## Create a distributed table on the cluster {#creating-a-table}
+
+Now that the database has been created, next you will create a distributed table.
+Distributed tables are tables which have access to shards located on different
+hosts and are defined using the `Distributed` table engine. The distributed table
+acts as the interface across all the shards in the cluster.
+
+Run the following query from any of the host clients:
+
+```sql
+CREATE TABLE IF NOT EXISTS uk.uk_price_paid_local
+--highlight-next-line
+ON CLUSTER cluster_2S_2R
+(
+ price UInt32,
+ date Date,
+ postcode1 LowCardinality(String),
+ postcode2 LowCardinality(String),
+ type Enum8('terraced' = 1, 'semi-detached' = 2, 'detached' = 3, 'flat' = 4, 'other' = 0),
+ is_new UInt8,
+ duration Enum8('freehold' = 1, 'leasehold' = 2, 'unknown' = 0),
+ addr1 String,
+ addr2 String,
+ street LowCardinality(String),
+ locality LowCardinality(String),
+ town LowCardinality(String),
+ district LowCardinality(String),
+ county LowCardinality(String)
+)
+--highlight-next-line
+ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/{table}/{shard}', '{replica}')
+ORDER BY (postcode1, postcode2, addr1, addr2);
+```
+
+Notice that it is identical to the query used in the original `CREATE` statement of the
+[UK property prices](/getting-started/example-datasets/uk-price-paid) example dataset tutorial,
+except for the `ON CLUSTER` clause and use of the `ReplicatedMergeTree` engine.
+
+The `ON CLUSTER` clause is designed for distributed execution of DDL (Data Definition Language)
+queries such as `CREATE`, `DROP`, `ALTER`, and `RENAME`, ensuring that these
+schema changes are applied across all nodes in a cluster.
+
+The [`ReplicatedMergeTree`](https://clickhouse.com/docs/engines/table-engines/mergetree-family/replication#converting-from-mergetree-to-replicatedmergetree)
+engine works just as the ordinary `MergeTree` table engine, but it will also replicate the data.
+It requires two parameters to be specified:
+
+- `zoo_path`: The Keeper/ZooKeeper path to the table's metadata.
+- `replica_name`: The table's replica name.
+
+
+
+The `zoo_path` parameter can be set to anything you choose, although it is recommended to follow
+the convention of using prefix
+
+```text
+/clickhouse/tables/{shard}/{database}/{table}
+```
+
+where:
+- `{database}` and `{table}` will be replaced automatically.
+- `{shard}` and `{replica}` are macros which were [defined](#macros-config-explanation)
+ previously in the `config.xml` file of each ClickHouse node.
+
+You can run the query below from each host's client to confirm that the table has been created across the cluster:
+
+```sql title="Query"
+SHOW TABLES IN uk;
+```
+
+```response title="Response"
+ ┌─name────────────────┐
+1. │ uk_price_paid_local │
+ └─────────────────────┘
+```
+
+## Insert data into a distributed table {#inserting-data-using-distributed}
+
+To insert data into the distributed table, `ON CLUSTER` cannot be used as it does
+not apply to DML (Data Manipulation Language) queries such as `INSERT`, `UPDATE`,
+and `DELETE`. To insert data, it is necessary to make use of the
+[`Distributed`](/engines/table-engines/special/distributed) table engine.
+
+From any of the host clients, run the following query to create a distributed table
+using the existing table we created previously with `ON CLUSTER` and use of the
+`ReplicatedMergeTree`:
+
+```sql
+CREATE TABLE IF NOT EXISTS uk.uk_price_paid_distributed
+ON CLUSTER cluster_2S_2R
+ENGINE = Distributed('cluster_2S_2R', 'uk', 'uk_price_paid_local', rand());
+```
+
+On each host you will now see the following tables in the `uk` database:
+
+```sql
+ ┌─name──────────────────────┐
+1. │ uk_price_paid_distributed │
+2. │ uk_price_paid_local │
+ └───────────────────────────┘
+```
+
+Data can be inserted into the `uk_price_paid_distributed` table from any of the
+host clients using the following query:
+
+```sql
+INSERT INTO uk.uk_price_paid_distributed
+SELECT
+ toUInt32(price_string) AS price,
+ parseDateTimeBestEffortUS(time) AS date,
+ splitByChar(' ', postcode)[1] AS postcode1,
+ splitByChar(' ', postcode)[2] AS postcode2,
+ transform(a, ['T', 'S', 'D', 'F', 'O'], ['terraced', 'semi-detached', 'detached', 'flat', 'other']) AS type,
+ b = 'Y' AS is_new,
+ transform(c, ['F', 'L', 'U'], ['freehold', 'leasehold', 'unknown']) AS duration,
+ addr1,
+ addr2,
+ street,
+ locality,
+ town,
+ district,
+ county
+FROM url(
+ 'http://prod1.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-complete.csv',
+ 'CSV',
+ 'uuid_string String,
+ price_string String,
+ time String,
+ postcode String,
+ a String,
+ b String,
+ c String,
+ addr1 String,
+ addr2 String,
+ street String,
+ locality String,
+ town String,
+ district String,
+ county String,
+ d String,
+ e String'
+) SETTINGS max_http_get_redirects=10;
+```
+
+Run the following query to confirm that the data inserted has been evenly distributed
+across the nodes of our cluster:
+
+```sql
+SELECT count(*)
+FROM uk.uk_price_paid_distributed;
+
+SELECT count(*) FROM uk.uk_price_paid_local;
+```
+
+```response
+ ┌──count()─┐
+1. │ 30212555 │ -- 30.21 million
+ └──────────┘
+
+ ┌──count()─┐
+1. │ 15105983 │ -- 15.11 million
+ └──────────┘
+```
+
+
\ No newline at end of file
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx
new file mode 100644
index 00000000000..b2afbc447dc
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_config_explanation.mdx
@@ -0,0 +1,24 @@
+- The `config.d` directory contains ClickHouse server configuration file `config.xml`,
+ in which custom configuration for each ClickHouse node is defined. This
+ configuration gets combined with the default `config.xml` ClickHouse configuration
+ file that comes with every ClickHouse installation.
+- The `users.d` directory contains user configuration file `users.xml`, in which
+ custom configuration for users is defined. This configuration gets combined with
+ the default ClickHouse `users.xml` configuration file that comes with every
+ ClickHouse installation.
+
+:::tip Custom configuration directories
+It is a best practice to make use of the `config.d` and `users.d` directories when
+writing your own configuration, rather than directly modifying the default configuration
+in `/etc/clickhouse-server/config.xml` and `etc/clickhouse-server/users.xml`.
+
+The line
+
+```xml
+
+```
+
+Ensures that the configuration sections defined in the `config.d` and `users.d`
+directories override the default configuration sections defined in the default
+`config.xml` and `users.xml` files.
+:::
\ No newline at end of file
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx
new file mode 100644
index 00000000000..0326e23d49c
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_dedicated_keeper_servers.mdx
@@ -0,0 +1,8 @@
+:::note
+Although it is possible to run ClickHouse Server and ClickHouse Keeper combined on the same server,
+we strongly recommend using *dedicated* hosts for ClickHouse keeper in production environments,
+which is the approach we will demonstrate in this example.
+
+Keeper servers can be smaller, and 4GB RAM is generally enough for each Keeper server
+until your ClickHouse Servers grow large.
+:::
\ No newline at end of file
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx
new file mode 100644
index 00000000000..55ecdec7618
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_config.mdx
@@ -0,0 +1,67 @@
+In order for replication to work, a ClickHouse keeper cluster needs to be set up and
+configured. ClickHouse Keeper provides the coordination system for data replication,
+acting as a stand in replacement for Zookeeper, which could also be used.
+ClickHouse Keeper is, however, recommended, as it provides better guarantees and
+reliability and uses fewer resources than ZooKeeper. For high availability and to
+keep quorum, it is recommended to run at least three ClickHouse Keeper nodes.
+
+:::note
+ClickHouse Keeper can run on any node of the cluster alongside ClickHouse, although
+it is recommended to have it run on a dedicated node which allows scaling and
+managing the ClickHouse Keeper cluster independently of the database cluster.
+:::
+
+Create the `keeper_config.xml` files for each ClickHouse Keeper node
+using the following command from the root of the example folder:
+
+```bash
+for i in {01..03}; do
+ touch fs/volumes/clickhouse-keeper-${i}/etc/clickhouse-keeper/keeper_config.xml
+done
+```
+
+Modify the empty configuration files which were created in each
+node directory `fs/volumes/clickhouse-keeper-{}/etc/clickhouse-keeper`. The
+highlighted lines below need to be changed to be specific to each node:
+
+```xml title="/config.d/config.xml"
+
+
+ information
+ /var/log/clickhouse-keeper/clickhouse-keeper.log
+ /var/log/clickhouse-keeper/clickhouse-keeper.err.log
+ 1000M
+ 3
+
+ 0.0.0.0
+
+ 9181
+
+ 1
+ /var/lib/clickhouse/coordination/log
+ /var/lib/clickhouse/coordination/snapshots
+
+ 10000
+ 30000
+ information
+
+
+
+ 1
+ clickhouse-keeper-01
+ 9234
+
+
+ 2
+ clickhouse-keeper-02
+ 9234
+
+
+ 3
+ clickhouse-keeper-03
+ 9234
+
+
+
+
+```
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx
new file mode 100644
index 00000000000..230dab5e9ce
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_keeper_explanation.mdx
@@ -0,0 +1,34 @@
+Each configuration file will contain the following unique configuration (shown below).
+The `server_id` used should be unique for that particular ClickHouse Keeper node
+in the cluster and match the server `` defined in the `` section.
+`tcp_port` is the port used by _clients_ of ClickHouse Keeper.
+
+```xml
+9181
+{id}
+```
+
+The following section is used to configure the servers that participate in the
+quorum for the [raft consensus algorithm](https://en.wikipedia.org/wiki/Raft_(algorithm)):
+
+```xml
+
+
+ 1
+ clickhouse-keeper-01
+
+
+ 9234
+
+
+ 2
+ clickhouse-keeper-02
+ 9234
+
+
+ 3
+ clickhouse-keeper-03
+ 9234
+
+
+```
\ No newline at end of file
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx
new file mode 100644
index 00000000000..df3c71edf44
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_listen_host.mdx
@@ -0,0 +1,21 @@
+External communication to the network interface is enabled by activating the listen
+host setting. This ensures that the ClickHouse server host is reachable by other
+hosts:
+
+```xml
+0.0.0.0
+```
+
+The port for the HTTP API is set to `8123`:
+
+```xml
+8123
+```
+
+The TCP port for interaction by ClickHouse's native protocol between clickhouse-client
+and other native ClickHouse tools, and clickhouse-server and other clickhouse-servers
+is set to `9000`:
+
+```xml
+9000
+```
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_server_parameter_table.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_server_parameter_table.mdx
new file mode 100644
index 00000000000..4586778b803
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_server_parameter_table.mdx
@@ -0,0 +1,6 @@
+For each server, the following parameters are specified:
+
+| Parameter | Description | Default Value |
+|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
+| `host` | The address of the remote server. You can use either the domain or the IPv4 or IPv6 address. If you specify the domain, the server makes a DNS request when it starts, and the result is stored as long as the server is running. If the DNS request fails, the server does not start. If you change the DNS record, you need to restart the server. | - |
+| `port` | The TCP port for messenger activity (`tcp_port` in the config, usually set to 9000). Not to be confused with `http_port`. | - |
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx
new file mode 100644
index 00000000000..15f60053792
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_verify_keeper_using_mntr.mdx
@@ -0,0 +1,70 @@
+The `mntr` command is also commonly used to verify that ClickHouse Keeper is
+running and to get state information about the relationship of the three Keeper nodes.
+In the configuration used in this example, there are three nodes working together.
+The nodes will elect a leader, and the remaining nodes will be followers.
+
+The `mntr` command gives information related to performance, and whether a particular
+node is a follower or a leader.
+
+:::tip
+You may need to install `netcat` in order to send the `mntr` command to Keeper.
+Please see the [nmap.org](https://nmap.org/ncat/) page for download information.
+:::
+
+Run the command below from a shell on `clickhouse-keeper-01`, `clickhouse-keeper-02`, and
+`clickhouse-keeper-03` to check the status of each Keeper node. The command
+for `clickhouse-keeper-01` is shown below:
+
+```bash
+docker exec -it clickhouse-keeper-01 echo mntr | nc localhost 9181
+```
+
+The response below shows an example response from a follower node:
+
+```response title="Response"
+zk_version v23.3.1.2823-testing-46e85357ce2da2a99f56ee83a079e892d7ec3726
+zk_avg_latency 0
+zk_max_latency 0
+zk_min_latency 0
+zk_packets_received 0
+zk_packets_sent 0
+zk_num_alive_connections 0
+zk_outstanding_requests 0
+# highlight-next-line
+zk_server_state follower
+zk_znode_count 6
+zk_watch_count 0
+zk_ephemerals_count 0
+zk_approximate_data_size 1271
+zk_key_arena_size 4096
+zk_latest_snapshot_size 0
+zk_open_file_descriptor_count 46
+zk_max_file_descriptor_count 18446744073709551615
+```
+
+The response below shows an example response from a leader node:
+
+```response title="Response"
+zk_version v23.3.1.2823-testing-46e85357ce2da2a99f56ee83a079e892d7ec3726
+zk_avg_latency 0
+zk_max_latency 0
+zk_min_latency 0
+zk_packets_received 0
+zk_packets_sent 0
+zk_num_alive_connections 0
+zk_outstanding_requests 0
+# highlight-next-line
+zk_server_state leader
+zk_znode_count 6
+zk_watch_count 0
+zk_ephemerals_count 0
+zk_approximate_data_size 1271
+zk_key_arena_size 4096
+zk_latest_snapshot_size 0
+zk_open_file_descriptor_count 48
+zk_max_file_descriptor_count 18446744073709551615
+# highlight-start
+zk_followers 2
+zk_synced_followers 2
+# highlight-end
+```
\ No newline at end of file
diff --git a/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx b/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx
new file mode 100644
index 00000000000..880eaa8584d
--- /dev/null
+++ b/docs/deployment-guides/replication-sharding-examples/_snippets/_working_example.mdx
@@ -0,0 +1,6 @@
+:::tip Example files
+The following steps will walk you through setting up the cluster from
+scratch. If you prefer to skip these steps and jump straight to running the
+cluster, you can obtain the example
+files from the [examples repository](https://github.com/ClickHouse/examples/tree/main/docker-compose-recipes)
+:::
\ No newline at end of file
diff --git a/docs/deployment-guides/terminology.md b/docs/deployment-guides/terminology.md
index de347e53a26..1c200db2379 100644
--- a/docs/deployment-guides/terminology.md
+++ b/docs/deployment-guides/terminology.md
@@ -8,17 +8,16 @@ description: 'Page with deployment examples that are based on the advice provide
import ReplicationShardingTerminology from '@site/docs/_snippets/_replication-sharding-terminology.md';
-These deployment examples are based on the advice provided to ClickHouse users by the ClickHouse Support and Services organization. These are working examples, and we recommend that you try them and then adjust them to suit your needs. You may find an example here that fits your requirements exactly. Alternatively, should you have a requirement where data is replicated three times instead of two, you should be able to add another replica by following the patterns presented here.
+The deployment examples in this section are based on the advice provided to ClickHouse users by
+the ClickHouse Support and Services organization. These are working examples, and
+we recommend that you try them and then adjust them to suit your needs. You may find
+an example here that fits your requirements exactly.
-
-
-## Examples {#examples}
-
-### Basic {#basic}
+We offer 'recipes' of a number of different topologies in the [example repo](https://github.com/ClickHouse/examples/tree/main/docker-compose-recipes/recipes)
+and recommend taking a look at them if the examples in this section do not fit your
+needs exactly.
-- The [**Scaling out**](/deployment-guides/horizontal-scaling.md) example shows how to shard your data across two nodes, and use a distributed table. This results in having data on two ClickHouse nodes. The two ClickHouse nodes also run ClickHouse Keeper providing distributed synchronization. A third node runs ClickHouse Keeper standalone to complete the ClickHouse Keeper quorum.
-
-- The [**Replication for fault tolerance**](/deployment-guides/replicated.md) example shows how to replicate your data across two nodes, and use a ReplicatedMergeTree table. This results in having data on two ClickHouse nodes. In addition to the two ClickHouse server nodes there are three ClickHouse Keeper standalone nodes to manage replication.
+
-
-### Intermediate {#intermediate}
-
-- Coming soon
-
-### Advanced {#advanced}
-
-- Coming soon
diff --git a/docs/managing-data/core-concepts/shards.md b/docs/managing-data/core-concepts/shards.md
index 431c0d06270..c8bdc850ea2 100644
--- a/docs/managing-data/core-concepts/shards.md
+++ b/docs/managing-data/core-concepts/shards.md
@@ -49,7 +49,7 @@ CREATE TABLE uk.uk_price_paid_simple_dist ON CLUSTER test_cluster
ENGINE = Distributed('test_cluster', 'uk', 'uk_price_paid_simple', rand())
```
-The `ON CLUSTER` clause makes the DDL statement a [distributed DDL statement](/docs/sql-reference/distributed-ddl), instructing ClickHouse to create the table on all servers listed in the `test_cluster` [cluster definition](/docs/architecture/horizontal-scaling#replication-and-sharding-configuration). Distributed DDL requires an additional [Keeper](https://clickhouse.com/clickhouse/keeper) component in the [cluster architecture](/docs/architecture/horizontal-scaling#architecture-diagram).
+The `ON CLUSTER` clause makes the DDL statement a [distributed DDL statement](/docs/sql-reference/distributed-ddl), instructing ClickHouse to create the table on all servers listed in the `test_cluster` [cluster definition](/architecture/replication/#configure-clickhouse-servers). Distributed DDL requires an additional [Keeper](https://clickhouse.com/clickhouse/keeper) component in the [cluster architecture](/architecture/horizontal-scaling).
For the [distributed engine parameters](/docs/engines/table-engines/special/distributed#distributed-parameters), we specify the cluster name (`test_cluster`), the database name (`uk`) for the sharded target table, the sharded target table's name (`uk_price_paid_simple`), and the **sharding key** for INSERT routing. In this example, we use the [rand](/sql-reference/functions/random-functions#rand) function to randomly assign rows to shards. However, any expression—even complex ones—can be used as a sharding key, depending on the use case. The next section illustrates how INSERT routing works.
@@ -86,7 +86,7 @@ Then, the ClickHouse server hosting the initially targeted distributed table ③
Replication in ClickHouse ensures **data integrity** and **failover** by maintaining **copies of shard data** across multiple servers. Since hardware failures are inevitable, replication prevents data loss by ensuring that each shard has multiple replicas. Writes can be directed to any replica, either directly or via a [distributed table](#distributed-table-creation), which selects a replica for the operation. Changes are automatically propagated to other replicas. In case of a failure or maintenance, data remains available on other replicas, and once a failed host recovers, it synchronizes automatically to stay up to date.
-Note that replication requires a [Keeper](https://clickhouse.com/clickhouse/keeper) component in the [cluster architecture](/docs/architecture/horizontal-scaling#architecture-diagram).
+Note that replication requires a [Keeper](https://clickhouse.com/clickhouse/keeper) component in the [cluster architecture](/architecture/horizontal-scaling).
The following diagram illustrates a ClickHouse cluster with six servers, where the two table shards `Shard-1` and `Shard-2` introduced earlier each have three replicas. A query is sent to this cluster:
diff --git a/docs/use-cases/observability/clickstack/migration/elastic/concepts.md b/docs/use-cases/observability/clickstack/migration/elastic/concepts.md
index 4f97360fb90..ce66ed3333b 100644
--- a/docs/use-cases/observability/clickstack/migration/elastic/concepts.md
+++ b/docs/use-cases/observability/clickstack/migration/elastic/concepts.md
@@ -169,7 +169,7 @@ On a single node, execution lanes split data into independent ranges allowing co
Query execution is further parallelized by:
1. **SIMD vectorization**: operations on columnar data use [CPU SIMD instructions](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) (e.g., [AVX512](https://en.wikipedia.org/wiki/AVX-512)), allowing batch processing of values.
-2. **Cluster-level parallelism**: in distributed setups, each node performs query processing locally. [Partial aggregation states](https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states#working-with-aggregation-states) are streamed to the initiating node and merged. If the query's `GROUP BY` keys align with the [sharding keys](/architecture/horizontal-scaling#shard), merging can be [minimized or avoided entirely](/operations/settings/settings#distributed_group_by_no_merge).
+2. **Cluster-level parallelism**: in distributed setups, each node performs query processing locally. [Partial aggregation states](https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states#working-with-aggregation-states) are streamed to the initiating node and merged. If the query's `GROUP BY` keys align with the sharding keys, merging can be [minimized or avoided entirely](/operations/settings/settings#distributed_group_by_no_merge).
This model enables efficient scaling across cores and nodes, making ClickHouse well-suited for large-scale analytics. The use of *partial aggregation states* allows intermediate results from different threads and nodes to be merged without loss of accuracy.
diff --git a/sidebars.js b/sidebars.js
index 66230ab576c..2e40815f502 100644
--- a/sidebars.js
+++ b/sidebars.js
@@ -1350,10 +1350,18 @@ const sidebars = {
link: { type: "doc", id: "deployment-guides/index" },
items: [
"deployment-guides/terminology",
- "deployment-guides/horizontal-scaling",
- "deployment-guides/replicated",
- "deployment-guides/parallel-replicas",
- "architecture/cluster-deployment",
+ {
+ type: "category",
+ label: "Examples",
+ collapsed: false,
+ items: [
+ {
+ type: "autogenerated",
+ dirName: "deployment-guides/replication-sharding-examples",
+ }
+ ]
+ },
+ "deployment-guides/parallel-replicas"
]
},
"guides/separation-storage-compute",
diff --git a/src/css/custom.scss b/src/css/custom.scss
index 21ef6708b10..58f8e7c3ca2 100644
--- a/src/css/custom.scss
+++ b/src/css/custom.scss
@@ -17,6 +17,29 @@ html[data-theme="dark"] {
background-attachment: fixed;
}
+/* This is a fix for the issue where paragraphs have 1rem margin bottom but
+look strange when there is a code block after the paragraph
+*/
+p {
+ margin-bottom: 0rem;
+}
+
+/* We only want to have a gap between successive paragraphs elements,
+not between paragraphs and other elements like code blocks
+*/
+p + * {
+ margin-top: 1rem;
+}
+
+/*
+Fix for the issue where there is no gap between a paragraph which follows
+a list
+ */
+ul + p,
+ol + p {
+ margin-top: 1rem;
+}
+
body {
font-size: var(--default-font);
line-height: var(--default-line-height);
diff --git a/src/theme/CodeBlock/index.js b/src/theme/CodeBlock/index.js
index 4270505174e..1d523f36c26 100644
--- a/src/theme/CodeBlock/index.js
+++ b/src/theme/CodeBlock/index.js
@@ -2,14 +2,18 @@ import React, {useState, useRef, useCallback, useEffect} from 'react';
import styles from './styles.module.css';
import CodeViewer from "../../components/CodeViewer";
-
-function countLines(text) {
- // Handle undefined or null input
- if (!text) return 1; // Return 1 as default line count
- // Split the string by newline characters
- const lines = text.split('\n');
- // Return the number of lines
- return lines.length;
+function countLines(text = '') {
+ if (typeof text !== 'string') {
+ return 1; // Default to 1 line for non-string inputs
+ }
+
+ const trimmedText = text.trim();
+ if (!trimmedText) {
+ return 1; // Return 1 for empty or whitespace-only strings
+ }
+
+ const lines = trimmedText.split('\n');
+ return Math.max(1, lines.length); // Ensure at least 1 line is returned
}
function parseMetaString(meta = '') {
diff --git a/static/images/deployment-guides/architecture_1s_2r_3_nodes.png b/static/images/deployment-guides/architecture_1s_2r_3_nodes.png
deleted file mode 100644
index a8d39ee2436..00000000000
Binary files a/static/images/deployment-guides/architecture_1s_2r_3_nodes.png and /dev/null differ
diff --git a/static/images/deployment-guides/replication-sharding-examples/both.png b/static/images/deployment-guides/replication-sharding-examples/both.png
new file mode 100644
index 00000000000..d2be118b640
Binary files /dev/null and b/static/images/deployment-guides/replication-sharding-examples/both.png differ
diff --git a/static/images/deployment-guides/replication-sharding-examples/replication.png b/static/images/deployment-guides/replication-sharding-examples/replication.png
new file mode 100644
index 00000000000..27b791fceef
Binary files /dev/null and b/static/images/deployment-guides/replication-sharding-examples/replication.png differ
diff --git a/static/images/deployment-guides/replication-sharding-examples/sharding.png b/static/images/deployment-guides/replication-sharding-examples/sharding.png
new file mode 100644
index 00000000000..aa7469d6051
Binary files /dev/null and b/static/images/deployment-guides/replication-sharding-examples/sharding.png differ
diff --git a/static/images/deployment-guides/scaling-out-1.png b/static/images/deployment-guides/scaling-out-1.png
deleted file mode 100644
index 36696c1c801..00000000000
Binary files a/static/images/deployment-guides/scaling-out-1.png and /dev/null differ