经过研究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
17
18
19
20 ……
55
# 将第55行换成password_sha256_hex,下面的是密文
3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358
# 替换后是这样的
54 -->
55 3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358
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标签中进行新增
darren
3facce93a682bb4abffe75498f3ad8af29eeac99e4575f6cce03556e908bf358
default
常用的配置在此文件
如日志级别、日志路径
端口设置
最大内存、缓存、存放路径
时区
IP访问限制
心跳等都在此文件中配置
下面是不限制IP访问的配置方法
[root@WDQCVM clickhouse-server]# vim /etc/clickhouse-server/config.xml
# 将这个本来注释的放开,即可其他机器也能访问
0.0.0.0
创建数据库
# 查看有多少数据库
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
使用客户端连接端口为
参考clickhouse 一(centos7安装clickhouse,设置用户名密码)