Ubuntu安装ClickHouse

注:本文章的ubuntu的版本为:ubuntu-20.04.6-live-server-amd64。

Ubuntu(在线版)

更新软件源

复制代码
sudo apt-get update

安装apt-transport-https

允许apt工具通过https协议下载软件包。

复制代码
sudo apt-get install apt-transport-https

安装ca-certificates

ca-certificates包含了用于验证SSL/TLS证书的根证书,确保在通过https下载软件包时能够验证服务器的身份,保证下载的安全性。

复制代码
sudo apt-get install ca-certificates

安装gnupg

gnupg是一个开源的加密工具,广泛用于生成、管理和验证加密密钥。对于ClickHouse的安装过程,gnupg用于处理和验证软件源的GPG密钥。

复制代码
sudo apt-get install gnupg

下载ClickHouse的GPG密钥文件

复制代码
curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg

将地址添加到系统的软件包源列表中

复制代码
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=amd64] https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list

更新软件源

复制代码
sudo apt-get update

安装ClickHouse服务器

注:本文章安装的ClickHouse版本为25.3.2.39。

安装过程需要设置密码,账号为default。

复制代码
sudo apt-get install clickhouse-server=25.3.2.39

安装ClickHouse客户端

复制代码
sudo apt-get install clickhouse-client=25.3.2.39

启动服务

复制代码
systemctl start clickhouse-server

查看ClickHouse状态

复制代码
systemctl status clickhouse-server

看到activate即启动成功。

使用ClickHouse客户端

需要输入密码

复制代码
clickhouse-client

测试ClickHouse

复制代码
show databases;

无报错则输出数据库名。

Ubuntu(离线版)

进入下载链接选择ClickHouse版本下载:

https://packages.clickhouse.com/tgz/lts/

需下载四个文件:clickhouse-common-static,clickhouse-common-static-dbg,clickhouse-server clickhouse-client

注:本文章下载clickhouse-common-static-25.3.2.39-amd64.tgz,clickhouse-common-static-dbg-25.3.2.39-amd64.tgz,clickhouse-server-25.3.2.39-amd64.tgz,clickhouse-client-25.3.2.39-amd64.tgz。

解压文件到指定目录

复制代码
tar -xvf clickhouse-common-static-25.3.2.39-amd64.tgz -C /usr/local
tar -xvf clickhouse-common-static-dbg-25.3.2.39-amd64.tgz -C /usr/local
tar -xvf clickhouse-server-25.3.2.39-amd64.tgz -C /usr/local
tar -xvf clickhouse-client-25.3.2.39-amd64.tgz -C /usr/local

安装clickhouse-common-static

复制代码
cd /usr/local/clickhouse-common-static-25.3.2.39
install/doinst.sh

安装clickhouse-common-static-dbg

复制代码
cd /usr/local/clickhouse-common-static-dbg-25.3.2.39
install/doinst.sh

安装clickhouse-server

复制代码
cd /usr/local/clickhouse-server-25.3.2.39
install/doinst.sh

安装clickhouse-client

复制代码
cd /usr/local/clickhouse-client-25.3.2.39
install/doinst.sh

配置默认账号default的密码

复制代码
sudo vim /etc/clickhouse-server/users.xml

找到<clickhouse>标签下的<users>,<users>标签下的<default>,<default>标签下的<password>,配置密码即可。

观察生成的系统服务文件

复制代码
sudo vim /lib/systemd/system/clickhouse-server.service

系统文件如下所示:

复制代码
[Unit]
Description=ClickHouse Server (analytic DBMS for big data)
Requires=network-online.target
# NOTE: that After/Wants=time-sync.target is not enough, you need to ensure
# that the time was adjusted already, if you use systemd-timesyncd you are
# safe, but if you use ntp or some other daemon, you should configure it
# additionaly.
After=time-sync.target network-online.target
Wants=time-sync.target

[Service]
Type=notify

# NOTE: we leave clickhouse watchdog process enabled to be able to see OOM/SIGKILL traces in clickhouse-server.log files.
# If you wish to disable the watchdog and rely on systemd logs just add "Environment=CLICKHOUSE_WATCHDOG_ENABLE=0" line.
User=clickhouse
Group=clickhouse
Restart=always
RestartSec=30
# The following ClickHouse directives should be used instead of forcing SIGKILL by systemd:
# - shutdown_wait_unfinished_queries
# - shutdown_wait_unfinished
TimeoutStopSec=infinity
# Disable forwarding signals by watchdog, since with default systemd's
# kill-mode control-group, systemd will send signal to all process in cgroup.
Environment=CLICKHOUSE_WATCHDOG_NO_FORWARD=1
# Since ClickHouse is systemd aware default 1m30sec may not be enough
TimeoutStartSec=0
# %p is resolved to the systemd unit name
RuntimeDirectory=%p 
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=%t/%p/%p.pid
# Minus means that this file is optional.
EnvironmentFile=-/etc/default/%p
# Bring back /etc/default/clickhouse for backward compatibility
EnvironmentFile=-/etc/default/clickhouse
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_NET_BIND_SERVICE

[Install]
# ClickHouse should not start from the rescue shell (rescue.target).
WantedBy=multi-user.target

从系统文件内容可以看出,这种方式安装的clickhouse默认的用户及用户组是clickhouse:

复制代码
[Service]
User=clickhouse
Group=clickhouse

如果系统没有clickhouse用户及用户组,将上述代码内容注释即可。

注释后重新加载系统服务

复制代码
sudo systemctl daemon-reload

启动服务

复制代码
systemctl start clickhouse-server

查看ClickHouse状态

复制代码
systemctl status clickhouse-server

看到activate即启动成功,后续可再使用ClickHouse客户端进行下一步的测试。

设置远程连接

修改配置文件

复制代码
sudo vim /etc/clickhouse-server/config.xml

在配置文件中找到以下部分,放开注释即可

复制代码
<listen_host>0.0.0.0</listen_host>
相关推荐
wengad11 小时前
podman安装clickhouse
clickhouse·podman
l1t3 天前
duckdb、clickhouse、datafusion、cedardb、tableauhyperapi 5种分析型数据库执行递归求数独SQL比较
数据库·sql·clickhouse
l1t4 天前
一个clickhouse易错的语法问题
数据库·sql·clickhouse
流烟默5 天前
ClickHouse 集群建表实战:从引擎选择到本地表 / 分布式表落地
分布式·clickhouse
深蓝电商API5 天前
亿级数据的存储选型:MongoDB/ES/ClickHouse横评
爬虫·clickhouse·mongodb·elasticsearch
流烟默7 天前
ClickHouse Part 机制与写入优化实践指南
大数据·运维·clickhouse
Sayai14 天前
ClickHouse WITH FILL 实战:监控大屏时间序列补零,附多粒度指标表与物化视图级联设计
大数据·运维·数据仓库·clickhouse·物化视图
l1t18 天前
DeepSeek总结的clickhouse的二进制文件自解压机制
clickhouse
l1t19 天前
DeepSeek总结的pg_clickhouse 与 chdb 更新:编码、嵌套与类型
数据库·clickhouse·postgresql
拔剑纵狂歌21 天前
ClickHouse system.query_log 字段详解与排障实践
后端·clickhouse·1024程序员节