ClickHouse搭建

Clickhouse搭建简述

clickhouse在进行搭建时,是使用clickhouse脚本进行搭建,所以解压clickhouse文件后直接运行文件的脚本即可

操作步骤

解压文件

1
2
3
4
tar -zxvf /opt/software/clickhouse-common-static-dbg-21.9.4.3/ -C /opt/module/
tar -zxvf /opt/software/clickhouse-common-static-21.9.4.35.tgz -C /opt/module/
tar -zxvf /opt/software/clickhouse-server-21.9.4.35.tgz -C /opt/module/
tar -zxvf /opt/software/clickhouse-client-21.9.4.35.tgz -C /opt/module/

clickhouse有以上四个文件需要解压,解压无顺序要求

执行脚本

1
2
3
4
./clickhouse-common-static-dbg-21.9.4.3//install/doinst.sh 
./clickhouse-common-static-21.9.4.35/install/doinst.sh
./clickhouse-client-21.9.4.35/install/doinst.sh
./clickhouse-server-21.9.4.35/install/doinst.sh

四个脚本文件严格意义上来说没有顺序,一般来说是先执行两个common文件,其次是client客户端文件,最后是server服务文件。

这样的顺序主要是方便截图。

commonclient文件执行后没有结果显示,server文件执行后有结果显示,所以最后使用server文件

启动Clickhouse

启动

1
systemctl start clickhouse-server

重启

1
systemctl restart clickhouse-server

查询状态

1
systemctl status clickhouse-server

运行状态:

运行状态示例
运行状态示例

关闭状态:

关闭状态示例
关闭状态示例

关闭

1
systemctl stop clickhouse-server

登录Clickhouse

1
clickhouse-client --port 9000 --host master --password 123456

clickhouse的默认端口号为9000,但是hadoop3.x版本中的hadoop默认端口也是9000,所以会出现端口占用的情况,所以我们需要更改clickhouse的默认端口号以此来保证端口不会出现重复占用的情况。

更改Clickhouse端口号

搜索test_shard_localhost,其中有8个端口为9000的文件需要修改为9001;

注意9440端口文件,即test_shard_localhost_secure不需要进行修改;

  • 以下是修改文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
>  590     <remote_servers>
> 591 <!-- Test only shard config for testing distributed storage -->
> 592 <test_shard_localhost>
> 593 <!-- Inter-server per-cluster secret for Distributed queries
> 594 default: no secret (no authentication will be performed)
> 595
> 596 If set, then Distributed queries will be validated on shards, so at least:
> 597 - such cluster should exist on the shard,
> 598 - such cluster should have the same secret.
> 599
> 600 And also (and which is more important), the initial_user will
> 601 be used as current user for the query.
> 602
> 603 Right now the protocol is pretty simple and it only takes into account:
> 604 - cluster name
> 605 - query
> 606
> 607 Also it will be nice if the following will be implemented:
> 608 - source hostname (see interserver_http_host), but then it will depends from DNS,
> 609 it can use IP address instead, but then the you need to get correct on the initiator node.
> 610 - target hostname / ip address (same notes as for source hostname)
> 611 - time-based security tokens
> 612 -->
> 613 <!-- <secret></secret> -->
> 614
> 615 <shard>
> 616 <!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). -->
> 617 <!-- <internal_replication>false</internal_replication> -->
> 618 <!-- Optional. Shard weight when writing data. Default: 1. -->
> 619 <!-- <weight>1</weight> -->
> 620 <replica>
> 621 <host>localhost</host>
> 622 <port>9001</port>
> 623 <!-- Optional. Priority of the replica for load_balancing. Default: 1 (less value has more priority). -->
> 624 <!-- <priority>1</priority> -->
> 625 </replica>
> 626 </shard>
> 627 </test_shard_localhost>
> 628 <test_cluster_two_shards_localhost>
> 629 <shard>
> 630 <replica>
> 631 <host>localhost</host>
> 632 <port>9001</port>
> 633 </replica>
> 634 </shard>
> 635 <shard>
> 636 <replica>
> 637 <host>localhost</host>
> 638 <port>9001</port>
> 639 </replica>
> 640 </shard>
> 641 </test_cluster_two_shards_localhost>
> 642 <test_cluster_two_shards>
> 643 <shard>
> 644 <replica>
> 645 <host>127.0.0.1</host>
> 646 <port>9001</port>
> 647 </replica>
> 648 </shard>
> 649 <shard>
> 650 <replica>
> 651 <host>127.0.0.2</host>
> 652 <port>9001</port>
> 653 </replica>
> 654 </shard>
> 655 </test_cluster_two_shards>
> 656 <test_cluster_two_shards_internal_replication>
> 657 <shard>
> 658 <internal_replication>true</internal_replication>
> 659 <replica>
> 660 <host>127.0.0.1</host>
> 661 <port>9001</port>
> 662 </replica>
> 663 </shard>
> 664 <shard>
> 665 <internal_replication>true</internal_replication>
> 666 <replica>
> 667 <host>127.0.0.2</host>
> 668 <port>9001</port>
> 669 </replica>
> 670 </shard>
> 671 </test_cluster_two_shards_internal_replication>
> 672 <test_shard_localhost_secure>
> 673 <shard>
> 674 <replica>
> 675 <host>localhost</host>
> 676 <port>9440</port>
> 677 <secure>1</secure>
> 678 </replica>
> 679 </shard>
> 680 </test_shard_localhost_secure>
> 681 <test_unavailable_shard>
> 682 <shard>
> 683 <replica>
> 684 <host>localhost</host>
> 685 <port>9001</port>
> 686 </replica>
> 687 </shard>
> 688 <shard>
> 689 <replica>
> 690 <host>localhost</host>
> 691 <port>1</port>
> 692 </replica>
> 693 </shard>
> 694 </test_unavailable_shard>
> 695 </remote_servers>

  • 需要注意的是,从网上搜索的修改clickhouse端口号是(82行,查找<tcp_port>即可找到):
1
>  82     <tcp_port>9001</tcp_port>

删除监听文件

1
rm -rf /etc/clickhouse-server/config.d/listen.xml

注意事项

  • 监听文件listen.xml

在执行./clickhouse-server-21.9.4.35/install/doinst.sh 时,会需要输入clickhouse的登陆密码,如果此时不输入密码,就不会出现监听文件。