Skip to content

1.Clickhouse部署

官当

1.1下载

官方安装脚本

bash
LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSION

case $(uname -m) in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
  *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esac

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
do
  curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
    || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSION

case $(uname -m) in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
  *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esac

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
do
  curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
    || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

1.2 版本选择

版本命名规则 Year.Major.Minor.patch

1)Year.Major.1.patch 1 表示测试版,大于1表示稳定版本。

2)有重大的更新和新特性主要在Minor为2的版本。

3)体验最新的测试功能 可以选择prestable或者testing版本。

4)对于企业来说可以选择LTS的稳定版本,差不多6个月发布一个LTS版本,一年发布两个。维护的周期要比stable版本长。

比如:

版本号"22.7.1.2484"的每个部分都有其特定含义:

"22": 主要版本号。这表示该版本属于ClickHouse的第22个主要版本。主要版本号通常在有重大功能改变或不兼容性变化时递增。

"7": 次要版本号。此数字表示该版本在主要版本之间的次要更新中发布的第7个版本。次要版本号通常包含新功能、改进和修复。

"1": 修订版本号。该数字表示对次要版本进行的修订或错误修复的数量。

"2484": 内部构建号或修订号。这个数字通常用于识别特定的构建,每次构建增加一个数字。

1.3部署

bash
#检测是否开启了SSE 4.2指令集
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

sh clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
sh clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh

sh clickhouse-server-$LATEST_VERSION/install/doinst.sh configure
sh clickhouse-client-$LATEST_VERSION/install/doinst.sh
#检测是否开启了SSE 4.2指令集
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

sh clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
sh clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh

sh clickhouse-server-$LATEST_VERSION/install/doinst.sh configure
sh clickhouse-client-$LATEST_VERSION/install/doinst.sh
  • 启动
bash
systemctl status|start|stop|restart clickhouse-server.service

或者
clickhouse-server start|stop|restart
systemctl status|start|stop|restart clickhouse-server.service

或者
clickhouse-server start|stop|restart

1.4访问

bash
[root@kubeadm-master01 clickhouse]# clickhouse-client
ClickHouse client version 23.12.6.19 (official build).
Connecting to localhost:9000 as user default.
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 23.12.6.

Warnings:
 * Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
 * Delay accounting is not enabled, OSIOWaitMicroseconds will not be gathered. Check /proc/sys/kernel/task_delayacct
 * Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.

kubeadm-master01 :) show databases;

SHOW DATABASES

Query id: b1133daf-1d68-4f7f-8353-f3b2acd20b02

┌─name───────────────┐
 INFORMATION_SCHEMA 
 default            
 information_schema 
 system             
└────────────────────┘

4 rows in set. Elapsed: 0.002 sec.
[root@kubeadm-master01 clickhouse]# clickhouse-client
ClickHouse client version 23.12.6.19 (official build).
Connecting to localhost:9000 as user default.
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 23.12.6.

Warnings:
 * Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
 * Delay accounting is not enabled, OSIOWaitMicroseconds will not be gathered. Check /proc/sys/kernel/task_delayacct
 * Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.

kubeadm-master01 :) show databases;

SHOW DATABASES

Query id: b1133daf-1d68-4f7f-8353-f3b2acd20b02

┌─name───────────────┐
 INFORMATION_SCHEMA 
 default            
 information_schema 
 system             
└────────────────────┘

4 rows in set. Elapsed: 0.002 sec.

或者

bash
[root@kubeadm-master01 clickhouse-server]# clickhouse-client --password="123456" --query "select version();"
23.12.6.19
[root@kubeadm-master01 clickhouse-server]# clickhouse-client --password="123456" --query "select version();"
23.12.6.19

或者play

http://IP:8123/play

image-20241109115146795

样本案例

https://clickhouse.com/docs/en/getting-started/example-datasets/cell-towers