注:本文章的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>