文章目录
ClickHouse安装步骤
背景
经过研究ClickHouse是列式数据库,下面是在Centos7.9版本单机版的安装的演示
安装
首先安装yum-utils工具包
sudo yum install -y yum-utils
导入镜像源
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo
安装客户端和服务端
sudo yum install -y clickhouse-server clickhouse-client
启动
启动客户端
[root@WDQCVM ~]# sudo /etc/init.d/clickhouse-server start
chown -R clickhouse: '/var/run/clickhouse-server/'
Will run sudo -u 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
Waiting for server to start
Waiting for server to start
Server started
客户端无密码登录
[root@WDQCVM ~]# clickhouse-client
ClickHouse client version 23.7.4.5 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 23.7.4 revision 54465.
Warnings:
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
* Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
WDQCVM :)
WDQCVM :) show databases;
SHOW DATABASES
Query id: d5496232-585d-4439-ba57-1975132bd73f
┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default │
│ information_schema │
│ system │
└────────────────────┘
4 rows in set. Elapsed: 0.013 sec.
WDQCVM :)
用户相关
修改密码
随机生成密码
[root@WDQCVM ~]# PASSWORD=$(base64 < /dev/urandom | head -c14); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
# 明文
7Gk+4fSe6gYzB9
# 密文
3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358
密码支持 明文、password_sha256_hex、ldap配置,选择一个即可
修改密码
vim /etc/clickhouse-server/users.xml
# 找到
16 <!-
- Users and ACL. -->
17 <users>
18 <!-- If user name was not specified, 'default' user is used. -->
19 <default>
20 ......
55 <password></password>
# 将第55行换成password_sha256_hex,下面的是密文
<password_sha256_hex>3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358</password_sha256_hex>
# 替换后是这样的
54 -->
55 <password_sha256_hex>3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358</password_sha256_hex>
56
修改完即可生效,需要输入密码了
[root@WDQCVM ~]# clickhouse-client
ClickHouse client version 23.7.4.5 (official build).
Connecting to localhost:9000 as user default.
Password for user (default):
登录验证
输入密码直接登录
clickhouse-client -h ip地址 -d 数据库 -m -u 用户名 --password 明文密码
[root@WDQCVM ~]# clickhouse-client -h 127.0.0.1 -d default -m -u default --password '7Gk+4fSe6gYzB9'
ClickHouse client version 23.7.4.5 (official build).
Connecting to database default at 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 23.7.4 revision 54465.
Warnings:
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
* Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
WDQCVM :)
新增用户
在users标签中进行新增
<users>
<user>
<name>darren</name>
<password_sha256_hex>3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358</password_sha256_hex>
<profile>default</profile>
</user>
</users>
config配置文件
常用的配置在此文件
如日志级别、日志路径
端口设置
最大内存、缓存、存放路径
时区
IP访问限制
心跳等都在此文件中配置
下面是不限制IP访问的配置方法
[root@WDQCVM clickhouse-server]# vim /etc/clickhouse-server/config.xml
<!-- Same for hosts without support for IPv6: -->
# 将这个本来注释的放开,即可其他机器也能访问
<listen_host>0.0.0.0</listen_host>
基本操作
创建数据库
# 查看有多少数据库
WDQCVM :) show databases;
SHOW DATABASES
Query id: 75256e46-2bae-45e8-b438-5d1b60d04403
┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default │
│ information_schema │
│ system │
└────────────────────┘
4 rows in set. Elapsed: 0.012 sec.
# 创建数据库
WDQCVM :) CREATE DATABASE IF NOT EXISTS darren;
CREATE DATABASE IF NOT EXISTS darren
Query id: d42bf64d-edfb-4853-b2c6-7e54cd8876eb
Ok.
0 rows in set. Elapsed: 0.029 sec.
# 切换数据库
WDQCVM :) use darren;
USE darren
Query id: c35e2a42-869c-46f0-83a1-3bc78f96323b
Ok.
0 rows in set. Elapsed: 0.006 sec.
WDQCVM :)
以上用法和MySQL没有什么差别,可以说学习成本降低了不少。
服务管理
上文我们启动了,则需使用对应的停止命令将其停止后才能
# 启动
sudo /etc/init.d/clickhouse-server start
# 停止
sudo /etc/init.d/clickhouse-server stop
启动、状态、停止、重启、开机启动
sudo systemctl start clickhouse-server
sudo systemctl status clickhouse-server
sudo systemctl stop clickhouse-server
sudo systemctl restart clickhouse-server
sudo systemctl enable clickhouse-server
使用客户端连接端口为
- 8123: http端口、程序调用,网站访问可以使用,这是 ClickHouse 提供的主要查询接口之一。
- 9000: TCP端口、clickhouse-client使用9000,原生查询端口可能更高效,适用于一些需要更快速查询性能的场景。
- 9004: TCP 端口 9004: 这是 ClickHouse 的 Replicated 数据传输端口。在 ClickHouse 的数据复制和冗余设置中,节点之间会使用此端口进行数据同步和传输。
- 9009: 这是 ClickHouse 的原生 TCP 管理接口端口。该端口与 ClickHouse 进行管理和控制,如执行重载配置、查看状态、执行查询分析等。