Importing and Configuring ClickHouse Sample Projects
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 environment 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.
- You have prepared the development environment and MRS cluster configuration files. For details, see Preparing a ClickHouse Application Running Environment.
Scenarios
ClickHouse provides sample projects for multiple scenarios to help you quickly learn ClickHouse projects.
Procedure
- Obtain the sample project from the src directory in the directory where the sample code is decompressed by referring to Obtaining the MRS Application Development Sample Project. You can select a sample based on the actual service scenario. For details about the samples, see ClickHouse Sample Project.
- In the application development environment, import the sample project to the IntelliJ IDEA development environment.
- On the IDEA page, choose File > New > Project from Existing Sources.
- In the displayed Select File or Directory to Import dialog box, select the pom.xml file in the clickhouse-examples folder and click OK.
- Confirm subsequent configurations and click Next. If there is no special requirement, use the default values.
- Select the recommended JDK version and click Finish.
- On the IDEA page, choose File > New > Project from Existing Sources.
- 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.
Versions earlier than MRS 3.1.5:
loadBalancerIPList= sslUsed=false loadBalancerHttpPort=21425 loadBalancerHttpsPort=21426 CLICKHOUSE_SECURITY_ENABLED=true user= # Passwords stored in plaintext pose security risks. Store them in ciphertext in configuration files or environment variables. password= clusterName=default_cluster databaseName=testdb tableName=testtb batchRows=10000 batchNum=10
MRS 3.1.5 or later:
loadBalancerIPList= sslUsed=false loadBalancerHttpPort=21425 loadBalancerHttpsPort=21426 CLICKHOUSE_SECURITY_ENABLED=true user= # Passwords stored in plaintext pose security risks. Store them in ciphertext in configuration files or environment variables. password= isMachineUser=false isSupportMachineUser=true clusterName=default_cluster databaseName=testdb tableName=testtb batchRows=10000 batchNum=10 clickhouse_dataSource_ip_list= native_dataSource_ip_list=
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 true for clusters in security mode.
loadBalancerHttpPort
21425
HTTP port number of LoadBalance. If sslUsed is set to false, this parameter cannot be left blank.
For versions earlier than MRS 3.2.0, 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.
MRS 3.2.0 or later: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Logical Cluster, locate the row containing the desired logical cluster, and view Ssl Port in the HTTP Balancer Port column.
loadBalancerHttpsPort
21426
HTTPS port number of LoadBalance. If sslUsed is set to true, this parameter cannot be left blank.
For versions earlier than MRS 3.2.0, 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.
MRS 3.2.0 or later: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Logical Cluster, locate the row containing the desired logical cluster, and view Ssl Port in the HTTP Balancer Port column.
CLICKHOUSE_SECURITY_ENABLED
true
Whether to enable the security mode for ClickHouse. This parameter has a fixed value of true for a cluster in security mode.
user
N/A
Developer user name prepared in Preparing User Information for Cluster Authentication.
password
N/A
Password of the development user
Passwords stored in plaintext pose security risks. Store them in ciphertext in configuration files or environment variables.
NOTE:If the user is created on FusionInsight Manager, you need to change the initial password upon the first login.
isMachineUser
false
Set this parameter to true if a machine-machine user is used for authentication.
If this parameter is set to true, the values of user and password are the username and password of the machine-machine user.
NOTE:This parameter is available only in MRS 3.1.5 or later.
isSupportMachineUser
true
Whether to support machine-machine user authentication. Value options are as follows:
true: Machine-machine user authentication is supported.
false: Machine-machine user authentication is not supported.
To set this parameter, perform the following operations:
Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Configuration then All Configurations. In the navigation pane on the left, choose ClickHouseServer(Role) > Security. On the page that is displayed, check the value of SUPPORT_MACHINE_USER.
NOTE:This parameter is available only in MRS 3.1.5 or later.
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_dataSource_ip_list
-
Mandatory. Set this parameter to the IP address list and HTTP port number of the ClickHouseBalancer instance.
Use commas (,) to separate multiple IP addresses. The format is as follows: ip:port,ip:port,ip:port.
To obtain the IP addresses and port numbers, perform the following operations:
IP address: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance and check the service IP addresses of all ClickHouseBalancer instances.
Port: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Logical Cluster, locate the row containing the desired logical cluster, and view Ssl Port in the HTTP Balancer Port column.
NOTE:This parameter is available only in MRS 3.1.5 or later.
native_dataSource_ip_list
-
Mandatory. Set this parameter to the IP address list and TCP port number of the ClickHouseBalancer instance.
Use commas (,) to separate multiple IP addresses. The format is as follows: ip:port,ip:port,ip:port.
To obtain the IP addresses and port numbers, perform the following operations:
IP address: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Instance and check the service IP addresses of all ClickHouseBalancer instances.
Port: Log in to FusionInsight Manager and choose Cluster > Services > ClickHouse. Click Logical Cluster, locate the row containing the desired logical cluster, and view Port in the TCP Balancer Port column.
NOTE:This parameter is available only in MRS 3.1.5 or later.
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot