Creating a ClickHouse cluster

ClickHouse cluster is one or more database hosts that can have replication configured between them.

Important

When creating a ClickHouse cluster with two or more hosts, Managed Service for ClickHouse automatically creates a cluster of three ZooKeeper hosts for managing replication and fault tolerance. These hosts are considered when calculating the resource quotas used in the cloud and when calculating the cost of the cluster. For more information, see the section on replication for ClickHouse.

The number of hosts that can be created together with a ClickHouse cluster depends on the storage option selected:

  • When using network drives, you can request any number of hosts (from one to the limits of the current quota).
  • When using SSDs, you can create at least two replicas along with the cluster (a minimum of two replicas is required to ensure fault tolerance). If the available folder resources are still sufficient after creating a cluster, you can add extra replicas.
  1. In the management console, select the folder where you want to create a DB cluster.
  2. Click on Managed Service for ClickHouse.
  3. Click Create cluster and select the necessary DBMS. Once a cluster is created, you cannot change the DBMS.
  4. Enter the cluster name in the Cluster name field. The cluster name must be unique within the folder.
  5. Select the environment where you want to create the cluster (you cannot change the environment after cluster creation):
    • production — for stable versions of your apps.
    • prestable — to perform testing, including that of the Managed Service for ClickHouse service itself. The prestable environment is updated more often, which means that known problems are fixed sooner in it, but this may cause backward incompatible changes.
  6. Select the host class that will define the technical specifications of the VMs where the DB hosts will be deployed. For the list of available classes, see the section Host classes. When you change the host class for the cluster, the characteristics of all existing instances change, too.
  7. In the Storage size section:
    • Select the type of storage, either a more flexible network type (network-hdd or network-nvme) or faster local SSD storage (local-nvme). The size of the local storage can only be changed in increments of 100 GB.
    • Select the size to be used for data and backups. For more information about how backups take up storage space, see Backups.
  8. In the Database section, specify DB attributes:
    • DB name
    • User name
    • User password (a minimum of 8 characters).
  9. In the Hosts section, specify parameters for database hosts created with the cluster (keep in mind that if you use SSDs when creating ClickHouse clusters, you can set at least two hosts). To change the added host, place the cursor on the host line and click .
  10. Click Create cluster.

If you don't have Yandex.Cloud CLI, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id flag.

To create a cluster:

  1. See the description of the CLI's create cluster command:

    $ yc managed-clickhouse cluster create --help
    
  2. Check whether the folder has any subnets for the cluster hosts:

    $ yc vpc subnet list
    

    If there are no subnets in the folder, create the necessary subnets in the VPC service.

  3. Specify the cluster parameters in the create command (the example shows only mandatory flags):

    $ yc managed-clickhouse cluster create \
       --name <cluster name> \
       --environment <prestable or production> \
       --network-name <network name> \
       --host type=<clickhouse or zookeeper>,zone-id=<availability zone>,subnet-id=<subnet ID> \
       --resource-preset <host class> \
       --clickhouse-disk-type <network-hdd | network-nvme | local-nvme> \
       --clickhouse-disk-size <storage size in GB> \
       --user name=<username>,password=<user password> \
       --database name=<DB name>
    

    The subnet ID subnet-id should be specified if the selected availability zone contains two or more subnets.

Examples

Creating a single-host cluster

To create a cluster with a single host, you should pass a single parameter, --host.

Let's say we need to create a ClickHouse cluster with the following characteristics:

  • Named mych.
  • In the production environment.
  • In the default network.
  • With a single ClickHouse host of the s1.nano class in the b0rcctk2rvtr8efcch64 subnet and the ru-central1-c availability zone.
  • With SSD network storage of 20 GB.
  • With one user (user1) and the password user1user1.
  • With one db1 database.

Run the command:

$ yc managed-clickhouse cluster create \
     --name mych \
     --environment=production \
     --network-name default \
     --clickhouse-resource-preset s1.nano \
     --host type=clickhouse,zone-id=ru-central1-c,subnet-id=b0cl69g98qumiqmtg12a \
     --clickhouse-disk-size 20 \
     --clickhouse-disk-type network-nvme \
     --user name=user1,password=user1user1 \
     --database name=db1