Skip to content

Commit 8d7adeb

Browse files
committed
docs:新增 spark 专栏
1 parent a211f14 commit 8d7adeb

File tree

6 files changed

+445
-4
lines changed

6 files changed

+445
-4
lines changed

docs/.vuepress/config.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ module.exports = {
197197
link: '/md/bigdata/作业帮基于 DolphinScheduler 的数据开发平台实践.md'
198198
}, ]
199199
},
200+
201+
{
202+
text: 'Spark',
203+
items: [{
204+
text: '为啥要学习Spark?',
205+
link: '/md/spark/为啥要学习Spark?.md'
206+
}, ]
207+
},
200208
]
201209
},
202210
{
@@ -377,8 +385,8 @@ module.exports = {
377385
{
378386
text: 'ClickHouse',
379387
items: [{
380-
text: '为啥要学习ClickHouse',
381-
link: '/md/ck/为啥要学习ClickHouse.md'
388+
text: 'clickhouse概述',
389+
link: '/md/ck/clickhouse概述.md'
382390
}]
383391
},
384392

@@ -658,6 +666,15 @@ module.exports = {
658666
"作业帮基于 DolphinScheduler 的数据开发平台实践",
659667
]
660668
},
669+
670+
{
671+
title: "Spark",
672+
collapsable: false,
673+
sidebarDepth: 0,
674+
children: [
675+
"00-Spark安装及启动",
676+
]
677+
},
661678
],
662679
"/md/rpc/": [{
663680
title: "RPC",
@@ -851,8 +868,10 @@ module.exports = {
851868
sidebarDepth: 0,
852869
children: [
853870
"clickhouse概述",
871+
"单机安装部署",
872+
"客户端基本操作",
854873
"为啥要学习ClickHouse",
855-
"学习基础",
874+
"为啥适合OLAP?",
856875
]
857876
}],
858877
"/md/distdb/": [{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 学习基础
1+
# 为啥适合OLAP?
22

33
## 1 简介
44

docs/md/ck/单机安装部署.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# 单机安装部署
2+
3+
4+
5+
## 1 安装
6+
7+
进入[官网](https://clickhouse.com/)点击:
8+
9+
![](https://codeselect.oss-cn-shanghai.aliyuncs.com/image-20240321134824312.png)
10+
11+
## 2 .repo文件
12+
13+
通常指Linux中用于存储软件源配置信息的文件。这些文件位于CentOS和其他基于Red Hat的Linux发行版中,用于管理系统中可用的软件包源。
14+
15+
.repo文件包含软件包管理器(如yum或dnf)所需的配置信息,包括软件源的名称、URL、GPG密钥验证等。这些信息告诉系统在哪里可以找到软件包并进行安装、更新或卸载操作。比如:https://packages.clickhouse.com/rpm/clickhouse.repo 文件内容
16+
17+
```toml
18+
[clickhouse-stable]
19+
name=ClickHouse - Stable Repository
20+
baseurl=https://packages.clickhouse.com/rpm/stable/
21+
gpgkey=https://packages.clickhouse.com/rpm/stable/repodata/repomd.xml.key
22+
gpgcheck=0
23+
repo_gpgcheck=1
24+
enabled=1
25+
26+
[clickhouse-lts]
27+
name=ClickHouse - LTS Repository
28+
baseurl=https://packages.clickhouse.com/rpm/lts/
29+
gpgkey=https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key
30+
gpgcheck=0
31+
repo_gpgcheck=1
32+
enabled=0
33+
```
34+
35+
在这个示例中,.repo文件包含了两个软件源配置:base和updates。它们分别指定了基础软件包和更新软件包的URL地址、GPG密钥验证方式等信息。
36+
37+
在使用Linux系统时,可编辑.repo文件来管理软件源,添加新的软件源、启用或禁用特定的软件源,或者修改软件源的配置信息。这样可以灵活地控制系统中软件包的来源和管理。那就按 repo 文件指引,来到[软件包下载地址](https://packages.clickhouse.com/rpm/lts/)
38+
39+
![](https://codeselect.oss-cn-shanghai.aliyuncs.com/image-20240321141454695.png)
40+
41+
时间戳格式:ISO 8601,它是一种国际标准的日期和时间表示方法。该时间戳表示的日期和时间:
42+
43+
- 年份:2022年
44+
- 月份:9月
45+
- 日期:21日
46+
- 时间:12点08分59秒
47+
- 毫秒:544毫秒
48+
- 时区:Z表示UTC时间(协调世界时)
49+
50+
51+
52+
注意需要下载四种文件:
53+
54+
- clickhouse-client-21.3.20.1-2.noarch.rpm
55+
- clickhouse-common-static-21.3.20.1-2.x86_64.rpm
56+
- clickhouse-common-static-dbg-21.3.20.1-2.x86_64.rpm
57+
- clickhouse-server-21.3.20.1-2.noarch.rpm
58+
59+
## 3 开始安装
60+
61+
在 linux 服务器的 clickhouse 目录下准备好这四个文件,然后开始安装:
62+
63+
```bash
64+
rpm -ivh *rpm
65+
```
66+
67+
安装后检查状态:
68+
69+
```bash
70+
[root@~]# systemctl status clickhouse-server
71+
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
72+
Loaded: loaded (/usr/lib/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)
73+
Active: inactive (dead)
74+
```
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# 客户端基本操作
2+
3+
## 0 clickhouse-client
4+
5+
一个原生的、基于TCP协议的命令行客户端。支持两种使用方式:
6+
7+
- 交互式模式
8+
9+
- 非交互式模式(批模式)
10+
11+
通过--query参数执行数据的查询、插入等操作,执行完成后退出。非交互式模式下默认数据格式为TabSeparated(制表符),可用FORMAT指定格式
12+
13+
ClickHouse 数据库的命令行客户端工具。它允许用户通过命令行界面与 ClickHouse 交互。
14+
15+
## 1 登录
16+
17+
```bash
18+
[root@javaedge-clickhouse-test bin]# clickhouse-client --user default --password xxxxxx
19+
ClickHouse client version 22.9.3.18 (official build).
20+
Connecting to localhost:9000 as user default.
21+
Connected to ClickHouse server version 22.9.3 revision 54460.
22+
23+
Warnings:
24+
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
25+
26+
javaedge-clickhouse-test :)
27+
```
28+
29+
可见,默认 9000 端口(可改)。
30+
31+
## 2 建表
32+
33+
```bash
34+
CREATE TABLE my_first_table
35+
(
36+
user_id UInt32,
37+
message String,
38+
timestamp DateTime,
39+
metric Float32
40+
)
41+
ENGINE = MergeTree
42+
PRIMARY KEY (user_id, timestamp)
43+
44+
CREATE TABLE my_first_table
45+
(
46+
`user_id` UInt32,
47+
`message` String,
48+
`timestamp` DateTime,
49+
`metric` Float32
50+
)
51+
ENGINE = MergeTree
52+
PRIMARY KEY (user_id, timestamp)
53+
54+
Query id: f96df3f3-8fb6-4f6e-a959-e18c151599c6
55+
56+
Ok.
57+
58+
0 rows in set. Elapsed: 0.008 sec.
59+
60+
javaedge-clickhouse-test :)
61+
```
62+
63+
使用CREATE TABLE定义一个新表。在ClickHouse中,通常的SQL DDL命令可以使用,只是需要加上ENGINE子句来指定表的引擎。使用MergeTree可充分利用ck的性能优势。
64+
65+
## 3 新增数据
66+
67+
可使用熟悉的INSERT INTO TABLE命令,但重要的是要理解,每次向MergeTree表插入数据都会在存储中创建一个**part**(文件夹)。为减少**part**的数量,建议一次性批量插入大量行(数万甚至数百万行)。
68+
69+
```bash
70+
INSERT INTO my_first_table (user_id, message, timestamp, metric) VALUES
71+
(101, 'Hello, ClickHouse!', now(), -1.0 ),
72+
(102, 'Insert a lot of rows per batch', yesterday(), 1.41421 ),
73+
(102, 'Sort your data based on your commonly-used queries', today(), 2.718 ),
74+
(101, 'Granules are the smallest chunks of data read', now() + 5, 3.14159 )
75+
76+
INSERT INTO my_first_table (user_id, message, timestamp, metric) FORMAT Values
77+
78+
Query id: 46944361-de07-4b72-ac8c-61aa9fecb85d
79+
80+
Ok.
81+
82+
4 rows in set. Elapsed: 0.005 sec.
83+
84+
javaedge-clickhouse-test :)
85+
```
86+
87+
## 4 查询
88+
89+
像常规SQL一样编写SELECT查询:
90+
91+
```sql
92+
SELECT *
93+
FROM my_first_table
94+
ORDER BY timestamp
95+
```
96+
97+
响应表格:
98+
99+
```sql
100+
┌─user_id─┬─message────────────────────────────────────────────┬───────────timestamp─┬──metric─┐
101+
│ 102 │ Insert a lot of rows per batch │ 2022-03-21 00:00:00 │ 1.41421 │
102+
│ 102 │ Sort your data based on your commonly-used queries │ 2022-03-22 00:00:00 │ 2.718 │
103+
│ 101 │ Hello, ClickHouse! │ 2022-03-22 14:04:09 │ -1 │
104+
│ 101 │ Granules are the smallest chunks of data read │ 2022-03-22 14:04:14 │ 3.14159 │
105+
└─────────┴────────────────────────────────────────────────────┴─────────────────────┴─────────┘
106+
107+
4 rows in set. Elapsed: 0.008 sec.
108+
```
109+
110+
下一步是将你的现有数据导入ClickHouse。有许多表函数和集成可用于摄入数据。
111+
112+
自定义查询格式:
113+
114+
```sql
115+
SELECT *
116+
FROM
117+
mysql(
118+
'localhost:3306',
119+
'my_database',
120+
'my_table',
121+
'postgresql_user',
122+
'password')
123+
;
124+
```
125+
126+
### 指定参数
127+
128+
查询参数格式:
129+
130+
```bash
131+
{<name>:<data type>}
132+
```
133+
134+
- name为参数名称
135+
- data type为数据类型
136+
137+
如:{parName:Array(Unt16)}
138+
139+
参数值通过命令行参数指定,格式:
140+
141+
```bash
142+
param_<name> = value
143+
```
144+
145+
146+
147+
```bash
148+
clickhouse-client --param_myid=3 -q "SELECT * FROM table WHERE a = {myid:Ulnt8}"
149+
```
150+
151+
## 5 其它
152+
153+
历史的执行语句保存在操作系统文件
154+
155+
```sql
156+
# 隐藏文件
157+
[root@clickhouse-test bin]# ll ~/.clickhouse-client-history
158+
-rw------- 1 root root 6100 Feb 18 13:34 /root/.clickhouse-client-history
159+
160+
# more
161+
CREATE TABLE default.local( ptcId String, ptcType String, dataSource String, deviceIdList String, timestamp
162+
String, lat String, lon String, region String, nodeId String, linkName String, posConfid String, heading String, motionCo
163+
nfid String, accelerationConfid String, width String, length String, height String, vehicleType String, ptcSizeConfid String,
164+
ptcTypeEx String)ENGINE = MergeTree()ORDER BY (ptcId, timestamp)SETTINGS index_granularity = 8192;
165+
```
166+
167+
退出客户端的方式:
168+
169+
- 按Ctrl + D或Ctrl+℃
170+
- 或执行命令exit、quit、logout、q、Q、:q
171+
172+
## 6 设置参数的方式
173+
174+
- 命令行设置:通过命令行的选项设置参数
175+
- 配置文件:在配置文件配置参数。命令行参数优先级高于配置文件参数
176+
177+
clickhouse-client常用参数:
178+
179+
- --host,-h:主机名,默认为localhost
180+
- --port:TCP端口,默认为9000
181+
- `--user/-u default` :使用默认用户名进行登录
182+
- `--password xxxxxx` :使用指定的密码进行身份验证。将 `xxxxxx` 替换为实际密码
183+
- --query,-q: 查询语句,在非交互式模式下使用
184+
- --queries-file,-qf:查询语句的文件路径
185+
- --multiline,-m:编写SQL语句,支持换行
186+
- --multiquery,-n:同时执行多个查询,查询语句使用分号分隔
187+
188+
### 通过配置文件传递参数
189+
190+
clickhouse-client按顺序,使用如下第一个出现的配置文件:
191+
192+
- 通过--config-file参数指定的配置文件
193+
- ./clickhouse-client.xml
194+
- ~/.clickhouse-client/config.xml
195+
- /etc/clickhouse-client/config.xml

0 commit comments

Comments
 (0)