ClickHouse Connection Setup#
In this section you can see information on specific settings that must be set in your system to allow connection and operation with ClickHouse:
| Item | Description |
|---|---|
| ClickHouse Username | The ClickHouse User name |
| ClickHouse Password | The ClickHouse User password |
Table: ClickHouse connection setup
See more information on Accounts and Security for specific information on accounts and security settings for ClickHouse.
Deployment#
Critical Manufacturing MES uses ClickHouse for data persistence. Deploy the version listed in ClickHouse Requirements. For MES 12.x, use the maintained v12.0 external components installer ↗. Its README describes the supported deployment options, prerequisites, configuration, and installation commands for Kafka, ClickHouse, and S3-compatible storage. You can deploy the required components and reuse existing services as described there.
Warning
The installation scripts provide deployment guidance. Critical Manufacturing recommends consulting an expert for a production ClickHouse setup.
After installation, use the ClickHouse connection information reported by the installer when configuring the Customer Environment:
- The ClickHouse address, or the load-balancer address for a replicated cluster.
- The HTTP or HTTPS port. MES 12.x uses the HTTP interface; do not enter the native TCP port. The installer reports HTTPS port
8443for its default deployment. - The cluster name. The default installer deployment uses
default; the value must match the deployed ClickHouse cluster. - The certificate authority certificate for the HTTPS endpoint.
- The ClickHouse username and password. Keep the password in protected environment configuration.
At least one ClickHouse user must have the permissions listed in Accounts and Security. The installer's Kafka client certificates configure Kafka mTLS authentication; they do not replace the ClickHouse username, password, and HTTPS trust configuration.
Fully managed ClickHouse service#
It is also possible to use a fully managed ClickHouse service such as ClickHouse Cloud. If this is the setup you wish to deploy in your system, please contact ClickHouse on ClickHouse Support ↗ for detailed instructions on setting up ClickHouse and integrating with Confluent Cloud.
Setting Up a Replicated Cluster#
For new on-premises deployments, configure a ClickHouse cluster. To keep Data Platform available after a ClickHouse server fails, deploy more than one replica. A single-replica cluster has no redundant copy of the data.
The MES stack includes a cluster with one replica and an embedded Keeper. It requires no customer-managed Keeper or load balancer, and you cannot add replicas to it. To use more replicas, move to an external self-managed cluster.
This section only applies to external self-managed ClickHouse since ClickHouse Cloud already handles replication. For the requirements of each deployment option, see ClickHouse Requirements.
Preconditions#
- ClickHouse servers configured as a cluster, with the version listed in ClickHouse Requirements. Use two or more replicas for high availability.
- At least three ClickHouse Keeper instances, using an odd number. For sizing, use the smallest odd number greater than the number of ClickHouse replicas. See ClickHouse Keeper.
- Network access between all ClickHouse servers and all ClickHouse Keeper instances.
- A load balancer when the cluster has more than one replica.
Setup Steps#
- Install ClickHouse on each server.
- Install and start the ClickHouse Keeper instances. For the configuration details, see the ClickHouse Keeper documentation ↗.
- Define a cluster in the ClickHouse server configuration, under
remote_servers. List every server as a replica of the same shard, and give the cluster a name. - Configure the macros on each ClickHouse server. A
Replicated*MergeTreetable uses the macros to identify the shard and the replica it belongs to. - Restart the ClickHouse servers and the ClickHouse Keeper instances, so they read the new configuration.
- Confirm that the cluster appears in the
system.clusterstable. - If you use a load balancer, configure it to route connections to only one replica during the installation, as described in Load Balancer.
- Set the
Cluster Nameto the name of the cluster from step 3 when you create the Customer Environment, then install the MES.
The installation creates the Data Platform databases and tables across the cluster. When you upgrade a non-clustered deployment from an earlier version, the installation also converts the existing databases and tables to the cluster.
After the installation completes, add the remaining replicas to the load balancer. Configure failover and the sticky sessions described below before sending connections to those replicas.
Cluster Name maps to the CLICKHOUSE_CLUSTER_NAME environment variable. The Environment Manager, the HouseKeeper, and the Aggregation Engine read it. Set it to the configured cluster name for a self-managed cluster, including a cluster with only one replica. Leave it empty for ClickHouse Cloud.
Warning
The value of Cluster Name must match the cluster name in the ClickHouse server configuration. If the name does not match, the installation will fail.
Load Balancer#
A self-managed ClickHouse cluster with more than one replica requires a load balancer. Configure the MES connection settings to use its endpoint. The single-replica cluster in the MES stack does not require a load balancer. ClickHouse Cloud provides its own endpoint and does not require a customer-managed load balancer.
Configure failover so that another replica takes over when the replica serving a connection fails. If the load balancer distributes connections across replicas, enable sticky sessions based on the source IP address, with a session duration of at least 24 hours. Longer durations are supported. All connections from the same source IP address must reach the same replica during that period.
The Aggregation Engine uses dbt to read back the data it has just written. Sending a subsequent read to a replica that has not caught up can make the aggregation fail.
During installation or conversion to a cluster, route connections to only one replica. For an in-place conversion, use the original replica. Add the remaining replicas to the load balancer only after the installation completes.
Information
On ClickHouse Cloud, the MES handles read-after-write consistency. The installation sets select_sequential_consistency to 1 for every user it creates.
Connection Settings#
Point the ClickHouse connection settings at the load balancer, not at a single replica. A connection that points to one replica fails when that replica goes down. Enter these settings in the General Data step of the Customer Environment.
For a self-managed cluster with only one replica, you can point the connection settings at that replica directly. This configuration has no failover target.
Cluster Name and the connection settings serve different purposes. The connection settings tell the MES where to send the queries. Cluster Name tells the MES which cluster to create the objects on.
Note
Adding a replica to a cluster that already runs is a separate procedure. ClickHouse Keeper does not enable replication on a new replica on its own, so the databases, tables, and views must be created on it before replication starts.