文档首页/ MapReduce服务 MRS/ 开发指南(LTS版)/ ClickHouse开发指南(安全模式)/ 调测ClickHouse应用/ 在Linux环境中调测ClickHouse应用(MRS 3.3.0及之后版本)
更新时间:2024-06-12 GMT+08:00
分享

在Linux环境中调测ClickHouse应用(MRS 3.3.0及之后版本)

ClickHouse应用程序也支持在Linux环境中运行。在程序代码完成开发后,您可以上传Jar包至准备好的Linux运行环境中运行。

前提条件

Linux环境已安装JDK,版本号需要和IntelliJ IDEA导出Jar包使用的JDK版本一致,并设置好Java环境变量。

编译并运行程序

  1. 单击IDEA右边Maven窗口的“Reload All Maven Projects”,进行maven项目依赖import。

    图1 reload projects

  2. 导出jar包

    • 选择“Maven > clickhouse-examples > Lifecycle > clean”,双击“clean”运行maven的clean命令。
    • 选择“Maven > clickhouse-examples > Lifecycle > install”,双击“install”运行maven的insatll命令。
    图2 maven工具的clean和install

  3. 将target目录下的clickhouse-examples-*.jar文件和“clickhouse-examples”目录下的“conf”文件夹复制到ClickHouse客户端安装目录下,例如“客户端安装目录/JDBC”目录或“客户端安装目录/JDBCTransaction”目录下。

    客户端安装目录/JDBC”目录,用来调测JDBC二次样例;

    客户端安装目录/JDBCTransaction”目录,用来调测事务二次样例。

  4. 登录客户端节点,进入jar文件上传目录下,修改文件权限为700。

    cd 客户端安装目录/JDBC

    或:cd 客户端安装目录/JDBCTransaction

    chmod 700 clickhouse-examples-*.jar

  5. 在“clickhouse_examples-*.jar”所在客户端目录下执行如下命令运行jar包:

    source 客户端安装目录/bigdata_env

    cd 客户端安装目录/JDBC

    或:cd 客户端安装目录/JDBCTransaction

    java -jar clickhouse-examples-*.jar

查看调测结果

ClickHouse应用程序运行完成后,可通过以下方式查看程序运行情况:

  • 通过运行结果查看程序运行情况。
  • 通过ClickHouse日志获取应用运行情况。

    即查看当前jar文件所在目录的“logs/clickhouse-example.log”日志文件,例如“客户端安装目录/JDBC/logs/clickhouse-example.log”或“客户端安装目录/JDBCTransaction/logs/clickhouse-example.log”。

jar包运行结果如下:

2023-09-21 09:08:38,944 | INFO  | main | loadBalancerIPList is 192.168.5.132, loadBalancerHttpPort is 21422, user is ck_user, clusterName is default_cluster, isSec is true, password is Admin12!. | com.huawei.clickhouse.examples.Demo.main(Demo.java:42)
2023-09-21 09:08:38,949 | INFO  | main | ckLbServerList current member is 0, ClickhouseBalancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Demo.getCkLbServerList(Demo.java:111)
2023-09-21 09:08:38,982 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:39,356 | INFO  | main | Execute query:drop table if exists testdb.testtb on cluster default_cluster no delay | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:39,537 | INFO  | main | Execute time is 181 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:39,545 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:39,580 | INFO  | main | Execute query:drop table if exists testdb.testtb_all on cluster default_cluster no delay | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:39,717 | INFO  | main | Execute time is 136 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:39,718 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:39,752 | INFO  | main | Execute query:create database if not exists testdb on cluster default_cluster | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:39,887 | INFO  | main | Execute time is 134 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:39,888 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:39,920 | INFO  | main | Execute query:create table testdb.testtb on cluster default_cluster (name String, age UInt8, date Date)engine=ReplicatedMergeTree('/clickhouse/tables/{shard}/testdb.testtb','{replica}') partition by toYYYYMM(date) order by age | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:40,064 | INFO  | main | Execute time is 143 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:40,065 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:40,096 | INFO  | main | Execute query:create table testdb.testtb_all on cluster default_cluster as testdb.testtb ENGINE = Distributed(default_cluster,testdb,testtb, rand()); | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:40,231 | INFO  | main | Execute time is 134 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:40,232 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.insertData(Util.java:143)
2023-09-21 09:08:40,447 | INFO  | main | Insert batch time is 101 ms | com.huawei.clickhouse.examples.Util.insertData(Util.java:160)
2023-09-21 09:08:42,063 | INFO  | main | Insert batch time is 113 ms | com.huawei.clickhouse.examples.Util.insertData(Util.java:160)
2023-09-21 09:08:43,564 | INFO  | main | Inert all batch time is 3224 ms | com.huawei.clickhouse.examples.Util.insertData(Util.java:164)
2023-09-21 09:08:43,564 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:43,596 | INFO  | main | Execute query:select * from testdb.testtb_all order by age limit 10 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:43,619 | INFO  | main | Execute time is 23 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:43,620 | INFO  | main | Current load balancer is 192.168.5.132:21422 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:68)
2023-09-21 09:08:43,652 | INFO  | main | Execute query:select toYYYYMM(date),count(1) from testdb.testtb_all group by toYYYYMM(date) order by count(1) DESC limit 10 | com.huawei.clickhouse.examples.Util.exeSql(Util.java:73)
2023-09-21 09:08:43,675 | INFO  | main | Execute time is 23 ms | com.huawei.clickhouse.examples.Util.exeSql(Util.java:77)
2023-09-21 09:08:43,677 | INFO  | main | name	age	date	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,677 | INFO  | main | huawei_7	4	2020-06-26	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,677 | INFO  | main | huawei_1	10	2021-01-05	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,677 | INFO  | main | huawei_12	17	2021-04-02	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,677 | INFO  | main | huawei_6	21	2021-12-02	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_8	22	2021-01-04	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_4	26	2020-05-14	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_11	30	2021-10-06	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_18	32	2020-12-15	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_0	33	2020-06-23	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,678 | INFO  | main | huawei_15	35	2020-07-13	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | toYYYYMM(date)	count()	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202006	4	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202110	2	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202101	2	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202104	2	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202001	2	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202005	1	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202012	1	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,679 | INFO  | main | 202108	1	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,680 | INFO  | main | 202107	1	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,680 | INFO  | main | 202102	1	 | com.huawei.clickhouse.examples.Demo.queryData(Demo.java:159)
2023-09-21 09:08:43,732 | INFO  | main | Name is: huawei_7, age is: 4 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,732 | INFO  | main | Name is: huawei_1, age is: 10 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,732 | INFO  | main | Name is: huawei_12, age is: 17 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,733 | INFO  | main | Name is: huawei_6, age is: 21 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,733 | INFO  | main | Name is: huawei_8, age is: 22 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,733 | INFO  | main | Name is: huawei_4, age is: 26 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,733 | INFO  | main | Name is: huawei_11, age is: 30 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,734 | INFO  | main | Name is: huawei_18, age is: 32 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,734 | INFO  | main | Name is: huawei_0, age is: 33 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)
2023-09-21 09:08:43,734 | INFO  | main | Name is: huawei_15, age is: 35 | com.huawei.clickhouse.examples.ClickhouseJDBCHaDemo.queryData(ClickhouseJDBCHaDemo.java:79)

相关文档