Updated on 2022-11-18 GMT+08:00

Configuring and Importing a Sample Project

Context

Obtain the ClickHouse development sample project and import the project to IntelliJ IDEA to learn the sample project.

Prerequisites

Ensure that the difference between the local PC time and the cluster time is less than 5 minutes. If the time difference cannot be determined, contact the system administrator. You can view the time of the cluster in the lower-right corner on the FusionInsight Manager page.

Scenarios

ClickHouse provides sample projects for multiple scenarios to help you quickly learn ClickHouse projects.

Procedure

  1. Obtain the sample project folder clickhouse-examples and Maven configurations in the src directory where the sample code is decompressed. For details, see Obtaining Sample Projects from Huawei Mirrors.
  2. In the application development environment, import the sample project to the IntelliJ IDEA development environment.

    1. On the IDEA page, choose File > New > Project from Existing Sources.

    2. In the displayed Select File or Directory to Import dialog box, select the pom.xml file in the clickhouse-examples folder and click OK.
    3. Confirm subsequent configurations and click Next. If there is no special requirement, use the default values.
    4. Select the recommended JDK version and click Finish.

  3. After the project is imported, modify the clickhouse-example.properties file in the conf directory of the sample project based on the actual environment information.

    loadBalancerIPList=
    sslUsed=false
    loadBalancerHttpPort=21425
    loadBalancerHttpsPort=21426
    CLICKHOUSE_SECURITY_ENABLED=true
    user=
    password=
    clusterName=default_cluster
    databaseName=testdb
    tableName=testtb
    batchRows=10000
    batchNum=10

    Table 1 Configuration description

    Parameter

    Default Value

    Definition

    loadBalancerIPList

    -

    Mandatory. Set this parameter to the IP address list of LoadBalance.

    Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance and check the service IP addresses of all ClickHouseBalancer instances.

    Use commas (,) to separate multiple IP addresses, for example, 10.10.10.100,10.10.10.101.

    sslUsed

    false

    Whether to enable SSL encryption. You are advised to set this parameter to false for clusters in common mode.

    loadBalancerHttpPort

    21425

    HTTP port number of LoadBalance. If sslUsed is set to false, this parameter cannot be left blank.

    Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance, click the corresponding ClickHouseBalancer instance, choose Instance Configurations > All Configurations, search for lb_http_port, and obtain the parameter value. The default value is 21425.

    loadBalancerHttpsPort

    21426

    HTTPS port number of LoadBalance. If sslUsed is set to true, this parameter cannot be empty.

    Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance, click the corresponding ClickHouseBalancer instance, choose Instance Configurations > All Configurations, search for lb_https_port, and obtain the parameter value. The default value is 21426.

    CLICKHOUSE_SECURITY_ENABLED

    true

    Whether to enable the security mode. Set this parameter to false for a cluster in normal mode.

    user

    No default value

    Developer user created in Table 1.

    password

    No default value

    Password of the development user

    NOTE:

    If the user is created on FusionInsight Manager, you need to change the initial password upon the first login.

    clusterName

    default_cluster

    ClickHouse logical cluster name. Retain the default value.

    databaseName

    testdb

    Name of the database to be created in the sample code project. You can change the database name based on the site requirements.

    tableName

    testtb

    Name of the table to be created in the sample code project. You can change the table name based on the site requirements.

    batchRows

    10000

    Number of data records written in a batch.

    batchNum

    10

    Total number of batches in which data is written.

    ClickHouse uses the LoadBalance-based deployment architecture to automatically distribute user access traffic to multiple backend nodes, expanding service capabilities to external systems and improving fault tolerance. When a client application requests a cluster, Nginx-based ClickHouseBalancer is used to distribute traffic. In this way, data read/write load and high availability of application access are guaranteed.