这是我参与11月更文挑战的第11天,活动详情查看:2021最后一次更文挑战
一、单机
安装步骤
官网安装文档:clickhouse.tech/docs/zh/get…
1. 上传4个文件到目录
clickhouse-common-static—ClickHouse编译的二进制文件。clickhouse-server— 创建clickhouse-server软连接,并安装默认配置服务clickhouse-client— 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。clickhouse-common-static-dbg— 带有调试信息的ClickHouse二进制文件。
# 这 4 个文件
# clickhouse-common-static-20.5.4.40-1.el7.x86_64.rpm
# clickhouse-server-20.5.4.40-1.el7.x86_64.rpm
# clickhouse-server-common-20.5.4.40-1.el7.x86_64.rpm
# clickhouse-client-20.5.4.40-1.el7.x86_64.rpm
第三种方式,下载好rpm包,离线安装
wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-server-common-20.5.4.40-1.el7.x86_64.rpm/download.rpm
wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-common-static-20.5.4.40-1.el7.x86_64.rpm/download.rpm
wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-server-20.5.4.40-1.el7.x86_64.rpm/download.rpm
wget --content-disposition https://packagecloud.io/Altinity/clickhouse/packages/el/7/clickhouse-client-20.5.4.40-1.el7.x86_64.rpm/download.rpm
2. 分别安装这4个 rpm 文件
命令:rpm -ivh ./*.rpm
# 实操如下:
[root@linux121 ck]# pwd
/opt/software/ck
[root@linux121 ck]# ll
total 90452
-rw-r--r-- 1 root root 6376 Apr 25 11:51 clickhouse-client-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 57490408 Apr 25 11:51 clickhouse-common-static-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 35102796 Apr 25 11:51 clickhouse-server-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 12988 Apr 25 11:51 clickhouse-server-common-20.5.4.40-1.el7.x86_64.rpm
[root@linux121 ck]# rpm -ivh ./*.rpm
Preparing... ################################# [100%]
Updating / installing...
1:clickhouse-server-common-20.5.4.4################################# [ 25%]
2:clickhouse-common-static-20.5.4.4################################# [ 50%]
3:clickhouse-server-20.5.4.40-1.el7################################# [ 75%]
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
4:clickhouse-client-20.5.4.40-1.el7################################# [100%]
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
3. 启动 ClickServer
- 启动:
systemctl start clickhouse-server - 查看状态:
systemctl status clickhouse-server
# 实操如下
[root@linux121 clickhouse-server]# systemctl start clickhouse-server
[root@linux121 clickhouse-server]# systemctl status clickhouse-server
● clickhouse-server.service - LSB: Yandex clickhouse-server daemon
Loaded: loaded (/etc/rc.d/init.d/clickhouse-server; bad; vendor preset: disabled)
Active: active (exited) since Sun 2021-04-25 12:08:44 CST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 5248 ExecStart=/etc/rc.d/init.d/clickhouse-server start (code=exited, status=0/SUCCESS)
Apr 25 12:08:44 linux121 systemd[1]: Starting LSB: Yandex clickhouse-server daemon...
Apr 25 12:08:44 linux121 su[5256]: (to clickhouse) root on none
Apr 25 12:08:44 linux121 clickhouse-server[5248]: Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: ...ckhouse/
Apr 25 12:08:44 linux121 su[5263]: (to clickhouse) root on none
Apr 25 12:08:44 linux121 su[5265]: (to clickhouse) root on none
Apr 25 12:08:44 linux121 su[5269]: (to clickhouse) root on none
Apr 25 12:08:44 linux121 su[5273]: (to clickhouse) root on none
Apr 25 12:08:44 linux121 clickhouse-server[5248]: DONE
Apr 25 12:08:44 linux121 systemd[1]: Started LSB: Yandex clickhouse-server daemon.
Hint: Some lines were ellipsized, use -l to show in full.
4. 使用 client 连接 server
进入客户端 clickhouse-client
# 实操如下
[root@linux121 clickhouse-server]# clickhouse-client
ClickHouse client version 20.5.4.40.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.5.4 revision 54435.
linux121 :)
linux121 :) show databases;
SHOW DATABASES
┌─name───────────────────────────┐
│ _temporary_and_external_tables │
│ default │
│ system │
└────────────────────────────────┘
3 rows in set. Elapsed: 0.005 sec.
二、集群
需要 Zookeeper
安装步骤
环境如下:
hostname | IP | 备注 |
|---|---|---|
| linux121 | 172.16.64.121 | 主节点 |
| linux122 | 172.16.64.122 | 从节点 |
| linux123 | 172.16.64.123 | 从节点 |
每个节点均有
Zookeeper。
1. 安装部署
将4个包发送到各个节点:
[root@linux121 opt]# pwd
/opt
$ scp -r software root@linux122:$PWD
$ scp -r software root@linux123:$PWD
命令:rpm -ivh ./*.rpm
# 实操如下:
[root@linux121 ck]# pwd
/opt/software/ck
[root@linux121 ck]# ll
total 90452
-rw-r--r-- 1 root root 6376 Apr 25 11:51 clickhouse-client-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 57490408 Apr 25 11:51 clickhouse-common-static-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 35102796 Apr 25 11:51 clickhouse-server-20.5.4.40-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 12988 Apr 25 11:51 clickhouse-server-common-20.5.4.40-1.el7.x86_64.rpm
[root@linux121 ck]# rpm -ivh ./*.rpm
Preparing... ################################# [100%]
Updating / installing...
1:clickhouse-server-common-20.5.4.4################################# [ 25%]
2:clickhouse-common-static-20.5.4.4################################# [ 50%]
3:clickhouse-server-20.5.4.40-1.el7################################# [ 75%]
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
4:clickhouse-client-20.5.4.40-1.el7################################# [100%]
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
2. 各节点修改配置文件 config.xml
命令:vi /etc/clickhouse-server/config.xml
[root@linux121 clickhouse-server]# pwd
/etc/clickhouse-server
[root@linux121 clickhouse-server]# vi config.xml
修改 config.xml 文件
<listen_host>::</listen_host>
<!-- Same for hosts with disabled ipv6: -->
<!-- <listen_host>0.0.0.0</listen_host> -->
修改 config.xml 文件,新增
# zookeeper 标签上面增加
<!-- 新增外部配置文件metrika.xml -->
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
将此配置发送到其他节点:
scp config.xml root@linux122:/etc/clickhouse-server/config.xml
scp config.xml root@linux123:/etc/clickhouse-server/config.xml
3. 各节点创建配置文件 metrika.xml
Tips:
ck用 9000端口,跟Hadoop冲突,这里先把Hadoop停掉
命令: vi /etc/clickhouse-server/config.d/metrika.xml
共设置 3个分片,每个分片只有1个副本;
<yandex>
<clickhouse_remote_servers>
<perftest_3shards_1replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>linux121</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>linux122</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>linux123</host>
<port>9000</port>
</replica>
</shard>
</perftest_3shards_1replicas>
</clickhouse_remote_servers>
<!--zookeeper相关配置-->
<zookeeper-servers>
<node index="1">
<host>linux121</host>
<port>2182</port>
</node>
<node index="2">
<host>linux122</host>
<port>2182</port>
</node>
<node index="3">
<host>linux123</host>
<port>2182</port>
</node>
</zookeeper-servers>
<macros>
<replica>linux121</replica>
</macros>
<networks>
<ip>::/0</ip>
</networks>
<clickhouse_compression>
<case>
<min_part_size>10000000000</min_part_size>
<min_part_size_ratio>0.01</min_part_size_ratio>
<method>lz4</method>
</case>
</clickhouse_compression>
</yandex>
将此配置发送到其他节点:
scp -r config.d root@linux122:$PWD
scp -r config.d root@linux123:$PWD
4. 所有节点均启动 clickhouse-server
启动前,需要启动 Zookeeper。
凡凡这边写了脚本自动起: sh zk.sh start
# 脚本在 linux121 上
[root@linux121 shells]# pwd
/root/shells
[root@linux121 shells]# ll
total 4
-rw-r--r--. 1 root root 240 Aug 27 2020 zk.sh
[root@linux121 shells]# sh zk.sh start
start zookeeper server...
ZooKeeper JMX enabled by default
Using config: /opt/lagou/servers/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/lagou/servers/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/lagou/servers/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
# 查看是否起来
# QuorumPeerMain 是 zk 的
[root@linux121 shells]# jps
1120 -- process information unavailable
5842 Jps
5812 QuorumPeerMain
命令:systemctl start clickhouse-server
# 每个节点都要启动
[root@linux121 software]# systemctl start clickhouse-server
[root@linux122 software]# systemctl start clickhouse-server
[root@linux123 software]# systemctl start clickhouse-server
5. 查看部署结果
# 1. 进入客户端
clickhouse-client
# 2. 查看结果
select * from system.clusters;
实操如下:
[root@linux121 software]# clickhouse-client
ClickHouse client version 20.5.4.40.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.5.4 revision 54435.
linux121 :) select * from system.clusters;
SELECT *
FROM system.clusters
┌─cluster───────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name─┬─host_address──┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─estimated_recovery_time─┐
│ perftest_3shards_1replicas │ 1 │ 1 │ 1 │ linux121 │ 172.16.64.121 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ perftest_3shards_1replicas │ 2 │ 1 │ 1 │ linux122 │ 172.16.64.122 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ perftest_3shards_1replicas │ 3 │ 1 │ 1 │ linux123 │ 172.16.64.123 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards │ 1 │ 1 │ 1 │ 127.0.0.1 │ 127.0.0.1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards │ 2 │ 1 │ 1 │ 127.0.0.2 │ 127.0.0.2 │ 9000 │ 0 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_localhost │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_cluster_two_shards_localhost │ 2 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_shard_localhost │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_shard_localhost_secure │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9440 │ 0 │ default │ │ 0 │ 0 │
│ test_unavailable_shard │ 1 │ 1 │ 1 │ localhost │ ::1 │ 9000 │ 1 │ default │ │ 0 │ 0 │
│ test_unavailable_shard │ 2 │ 1 │ 1 │ localhost │ ::1 │ 1 │ 0 │ default │ │ 0 │ 0 │
└───────────────────────────────────┴───────────┴──────────────┴─────────────┴───────────┴───────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────────────┘
11 rows in set. Elapsed: 0.007 sec.
这样就算启动成功了。