警告
本文最后更新于 2021-08-20,文中内容可能已过时。
Clickhouse
是一款高性能的列式存储数据库。
安装
参考官网安装页面。
源代码安装
可以通过下载源代码的方式进行安装,网址:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# export LATEST_VERSION=`curl https://api.github.com/repos/ClickHouse/ClickHouse/tags 2>/dev/null | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1`
export LATEST_VERSION=21.8.4.51
wget https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-${LATEST_VERSION}.tgz
wget https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-dbg-${LATEST_VERSION}.tgz
wget https://repo.clickhouse.tech/tgz/stable/clickhouse-server-${LATEST_VERSION}.tgz
wget https://repo.clickhouse.tech/tgz/stable/clickhouse-client-${LATEST_VERSION}.tgz
tar -xzvf clickhouse-common-static-$LATEST_VERSION.tgz
sudo bash clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
tar -xzvf clickhouse-common-static-dbg-$LATEST_VERSION.tgz
sudo bash clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh
tar -xzvf clickhouse-server-$LATEST_VERSION.tgz
sudo bash clickhouse-server-$LATEST_VERSION/install/doinst.sh
sudo /etc/init.d/clickhouse-server start
tar -xzvf clickhouse-client-$LATEST_VERSION.tgz
sudo bash clickhouse-client-$LATEST_VERSION/install/doinst.sh
|
配置
server
的配置文件位于:/etc/clickhouse-server
client
设置访问 IP
默认只能在本机访问,可以修改 /etc/clickhouse-server/config.xml
1
2
3
4
5
6
7
8
9
|
<!-- Default values - try listen localhost on IPv4 and IPv6. -->
<!--
<listen_host>::1</listen_host>
<listen_host>127.0.0.1</listen_host>
-->
<!-- Default values - try listen localhost on IPv4 and IPv6. -->
<listen_host>::1</listen_host>
<listen_host>0.0.0.0</listen_host>
|
添加 admin 管理员
取消用户管理的注释:
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
|
<!-- User can create other users and grant rights to them. -->
<!-- <access_management>1</access_management> -->
<!-- User can create other users and grant rights to them. -->
<access_management>1</access_management>
## 使用 default 账户登录并创建其他用户
clickhouse-client -h 127.0.0.1 -u default --password ilove
## 创建账户
CREATE USER lfang IDENTIFIED WITH plaintext_password BY 'XIA...qq' DEFAULT ROLE ALL;
## 权限
GRANT all ON default to lfang;
## 使用新账户登录,可以看到数据库了
clickhouse-client -h 127.0.0.1 -u lfang --password
data101 :) show databases;
SHOW DATABASES
Query id: 005f9f65-7183-4dcc-b3b6-5187685c168c
┌─name────┐
│ default │
└─────────┘
1 rows in set. Elapsed: 0.003 sec.
|
使用
1
2
3
4
5
6
7
8
|
clickhouse-client -h 127.0.0.1 -u default --password ilove
~/anaconda3/bin/python3 -m pip install clickhouse-cli
~/anaconda3/bin/clickhouse-cli -h 127.0.0.1 -p8123 -u default -Pilove
~/anaconda3/bin/clickhouse-cli -h 192.168.1.101 -p8123 -u default -Pilove
show databases;
|
技巧