1、安装脚本
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、安装文件
https://packages.clickhouse.com/tgz/stable/
- 2安装包
clickhouse-common-static ClickHouse编译的二进制文件。
clickhouse-common-static-dbg 带有调试信息的ClickHouse二进制文件。
clickhouse-server 创建clickhouse-server软连接,并安装默认配置服务
clickhouse-client 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。
- 3、安装方式
解压后执行解压文件中的doinst.sh即可
2、安装
[root@19c01 clickhouse]# ./install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 261M 100 261M 0 0 10.1M 0 0:00:25 0:00:25 --:--:-- 12.0M
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1134M 100 1134M 0 0 7912k 0 0:02:26 0:02:26 --:--:-- 10.5M
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 154k 100 154k 0 0 113k 0 0:00:01 0:00:01 --:--:-- 113k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 129k 100 129k 0 0 78791 0 0:00:01 0:00:01 --:--:-- 78744
clickhouse-common-static-23.12.2.59/
clickhouse-common-static-23.12.2.59/usr/
clickhouse-common-static-23.12.2.59/usr/bin/
clickhouse-common-static-23.12.2.59/usr/bin/clickhouse
clickhouse-common-static-23.12.2.59/usr/bin/clickhouse-diagnostics
clickhouse-common-static-23.12.2.59/usr/bin/clickhouse-library-bridge
clickhouse-common-static-23.12.2.59/usr/bin/clickhouse-odbc-bridge
clickhouse-common-static-23.12.2.59/usr/bin/clickhouse-extract-from-config
clickhouse-common-static-23.12.2.59/usr/share/
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/source_context.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/timestamp.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/type.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/api.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/any.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/wrappers.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/struct.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/descriptor.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/empty.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/duration.proto
clickhouse-common-static-23.12.2.59/usr/share/clickhouse/protos/google/protobuf/field_mask.proto
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/clickhouse
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/clickhouse-benchmark
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/clickhouse-bootstrap
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/clickhouse-local
clickhouse-common-static-23.12.2.59/usr/share/bash-completion/completions/clickhouse-client
clickhouse-common-static-23.12.2.59/usr/share/doc/
clickhouse-common-static-23.12.2.59/usr/share/doc/clickhouse-common-static/
clickhouse-common-static-23.12.2.59/usr/share/doc/clickhouse-common-static/README.md
clickhouse-common-static-23.12.2.59/usr/share/doc/clickhouse-common-static/LICENSE
clickhouse-common-static-23.12.2.59/usr/share/doc/clickhouse-common-static/AUTHORS
clickhouse-common-static-23.12.2.59/usr/share/doc/clickhouse-common-static/CHANGELOG.md
clickhouse-common-static-23.12.2.59/install/
clickhouse-common-static-23.12.2.59/install/doinst.sh
clickhouse-common-static-dbg-23.12.2.59/
clickhouse-common-static-dbg-23.12.2.59/usr/
clickhouse-common-static-dbg-23.12.2.59/usr/share/
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/clickhouse-common-static-dbg/
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/clickhouse-common-static-dbg/README.md
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/clickhouse-common-static-dbg/LICENSE
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/clickhouse-common-static-dbg/AUTHORS
clickhouse-common-static-dbg-23.12.2.59/usr/share/doc/clickhouse-common-static-dbg/CHANGELOG.md
clickhouse-common-static-dbg-23.12.2.59/usr/lib/
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/usr/
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/usr/bin/
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/usr/bin/clickhouse-library-bridge.debug
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/usr/bin/clickhouse-odbc-bridge.debug
clickhouse-common-static-dbg-23.12.2.59/usr/lib/debug/usr/bin/clickhouse.debug
clickhouse-common-static-dbg-23.12.2.59/install/
clickhouse-common-static-dbg-23.12.2.59/install/doinst.sh
clickhouse-server-23.12.2.59/
clickhouse-server-23.12.2.59/usr/
clickhouse-server-23.12.2.59/usr/bin/
clickhouse-server-23.12.2.59/usr/bin/clickhouse-keeper-converter
clickhouse-server-23.12.2.59/usr/bin/clickhouse-copier
clickhouse-server-23.12.2.59/usr/bin/clickhouse-keeper-client
clickhouse-server-23.12.2.59/usr/bin/clickhouse-server
clickhouse-server-23.12.2.59/usr/bin/clickhouse-keeper
clickhouse-server-23.12.2.59/usr/share/
clickhouse-server-23.12.2.59/usr/share/doc/
clickhouse-server-23.12.2.59/usr/share/doc/clickhouse-server/
clickhouse-server-23.12.2.59/usr/share/doc/clickhouse-server/README.md
clickhouse-server-23.12.2.59/usr/share/doc/clickhouse-server/LICENSE
clickhouse-server-23.12.2.59/usr/share/doc/clickhouse-server/AUTHORS
clickhouse-server-23.12.2.59/usr/share/doc/clickhouse-server/CHANGELOG.md
clickhouse-server-23.12.2.59/install/
clickhouse-server-23.12.2.59/install/doinst.sh
clickhouse-server-23.12.2.59/lib/
clickhouse-server-23.12.2.59/lib/systemd/
clickhouse-server-23.12.2.59/lib/systemd/system/
clickhouse-server-23.12.2.59/lib/systemd/system/clickhouse-keeper.service
clickhouse-server-23.12.2.59/lib/systemd/system/clickhouse-server.service
clickhouse-server-23.12.2.59/etc/
clickhouse-server-23.12.2.59/etc/clickhouse-server/
clickhouse-server-23.12.2.59/etc/clickhouse-server/users.xml
clickhouse-server-23.12.2.59/etc/clickhouse-server/config.xml
clickhouse-server-23.12.2.59/etc/clickhouse-keeper/
clickhouse-server-23.12.2.59/etc/clickhouse-keeper/keeper_config.xml
clickhouse-server-23.12.2.59/etc/init.d/
clickhouse-server-23.12.2.59/etc/init.d/clickhouse-server
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper-converter already exists but it points to /clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating symlink /usr/bin/ch to /usr/bin/clickhouse.
Creating symlink /usr/bin/chl to /usr/bin/clickhouse.
Creating symlink /usr/bin/chc to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
groupadd -r clickhouse
Creating clickhouse user if it does not exist.
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
chown clickhouse:clickhouse '/var/lib/clickhouse/'
groupadd -r clickhouse-bridge
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Enter password for default user:
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually.
Allow server to accept connections from the network (default is localhost only), [y/N]: y
The choice is saved in file /etc/clickhouse-server/config.d/listen.xml.
chown -R clickhouse:clickhouse '/etc/clickhouse-server'
ClickHouse has been successfully installed.
Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client --password
Synchronizing state of clickhouse-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable clickhouse-server
Created symlink /etc/systemd/system/multi-user.target.wants/clickhouse-server.service -> /usr/lib/systemd/system/clickhouse-server.service.
chown -R clickhouse: '/var/run/clickhouse-server/'
Will run sudo --preserve-env -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
clickhouse-client-23.12.2.59/
clickhouse-client-23.12.2.59/usr/
clickhouse-client-23.12.2.59/usr/bin/
clickhouse-client-23.12.2.59/usr/bin/clickhouse-compressor
clickhouse-client-23.12.2.59/usr/bin/clickhouse-benchmark
clickhouse-client-23.12.2.59/usr/bin/clickhouse-obfuscator
clickhouse-client-23.12.2.59/usr/bin/clickhouse-local
clickhouse-client-23.12.2.59/usr/bin/clickhouse-client
clickhouse-client-23.12.2.59/usr/bin/clickhouse-format
clickhouse-client-23.12.2.59/usr/share/
clickhouse-client-23.12.2.59/usr/share/doc/
clickhouse-client-23.12.2.59/usr/share/doc/clickhouse-client/
clickhouse-client-23.12.2.59/usr/share/doc/clickhouse-client/README.md
clickhouse-client-23.12.2.59/usr/share/doc/clickhouse-client/LICENSE
clickhouse-client-23.12.2.59/usr/share/doc/clickhouse-client/AUTHORS
clickhouse-client-23.12.2.59/usr/share/doc/clickhouse-client/CHANGELOG.md
clickhouse-client-23.12.2.59/install/
clickhouse-client-23.12.2.59/install/doinst.sh
clickhouse-client-23.12.2.59/etc/
clickhouse-client-23.12.2.59/etc/clickhouse-client/
clickhouse-client-23.12.2.59/etc/clickhouse-client/config.xml
主要两点
Allow server to accept connections from the network (default is localhost only), [y/N]: y
是否允许远程连接
Enter password for default user:
给默认用户一个密码
[root@19c01 clickhouse]# ps -ef|grep clickhouse-
clickho+ 12118 1 0 11:05 ? 00:00:00 clickhouse-watchdog --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
clickho+ 12119 12118 1 11:05 ? 00:00:01 /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
root 15317 2602 0 11:07 pts/0 00:00:00 grep --color=auto clickhouse-
默认安装路径是/var/run
3、检查安装脚本
[root@19c01 install]# cat /clickhouse/clickhouse-common-static-23.12.2.59/install/doinst.sh
#!/bin/sh
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
for filepath in `find $SCRIPTPATH/.. -type f -or -type l | grep -v "\.\./install/"`; do
destpath=${filepath##$SCRIPTPATH/..}
mkdir -p $(dirname "$destpath")
cp -r "$filepath" "$destpath"
done
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )":获取当前脚本所在目录的绝对路径,并将其赋值给变量SCRIPTPATH。
for filepath in find SCRIPTPATH/.. -type f -or -type l | grep -v "\.\./install/"`; do`:遍历SCRIPTPATH/..目录下的所有文件和符号链接,并将结果依次赋值给变量filepath。
destpath=${filepath##$SCRIPTPATH/..}:通过字符串截取,将filepath的部分路径去除,得到相对于上一级目录的路径,并将结果赋值给变量destpath。
mkdir -p $(dirname "$destpath"):创建destpath的上级目录(如果不存在)。
cp -r "$filepath" "$destpath":将filepath复制到destpath中。
看来调整安装路径,只需要修改这里就成
4、建表测试
19c01 :) create table winner(col1 Float64,col2 Float64,col3 Float64,col4 Float64,col5 UInt64,col6 Float64,col7 Float64,col 8 Float64,col9 Float64,col10 Float64,col11 Float64,col12 Float64,col13 UInt64,col14 UInt64) engine=File(CSV);
CREATE TABLE winner
(
`col1` Float64,
`col2` Float64,
`col3` Float64,
`col4` Float64,
`col5` UInt64,
`col6` Float64,
`col7` Float64,
`col8` Float64,
`col9` Float64,
`col10` Float64,
`col11` Float64,
`col12` Float64,
`col13` UInt64,
`col14` UInt64
)
ENGINE = File(CSV)
Query id: 667c0049-f534-46ae-9f11-564ee1735735
Ok.
0 rows in set. Elapsed: 0.002 sec.
[root@19c01 winner]# pwd
/var/lib/clickhouse/data/t1/winner
[root@19c01 winner]# ls
data.CSV
[root@19c01 winner]# cp /clickhouse/wine_data.csv ./
19c01 :) select avg(col1),max(col2),min(col3) from winner;
SELECT
avg(col1),
max(col2),
min(col3)
FROM winner
Query id: d27e33f0-193e-4e7e-8fb6-9d821f6b5021
┌─────────avg(col1)─┬─max(col2)─┬──────────min(col3)─┐
│ 13.00061797752809 │ 5.8 │ 1.3599999999999999 │
└───────────────────┴───────────┴────────────────────┘
1 row in set. Elapsed: 0.004 sec.
19c01 :) select count(*) from winner;
SELECT count(*)
FROM winner
Query id: 3839d9eb-43ff-49c7-b387-36a80e51172f
┌─count()─┐
│ 178 │
└─────────┘
1 row in set. Elapsed: 0.002 sec.
5、查询测试
19c01 :) select count(*) from t1;
SELECT count(*)
FROM t1
Query id: d526fd8d-5bb4-40be-b15b-ce0ae63371b3
┌──count()─┐
│ 46661632 │
└──────────┘
1 row in set. Elapsed: 0.002 sec.
19c01 :) describe t1;
DESCRIBE TABLE t1
Query id: 6c5a79cb-4440-4787-b835-08f024411f46
┌─name──┬─type────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
│ col1 │ Float64 │ │ │ │ │ │
│ col2 │ Float64 │ │ │ │ │ │
│ col3 │ Float64 │ │ │ │ │ │
│ col4 │ Float64 │ │ │ │ │ │
│ col5 │ UInt64 │ │ │ │ │ │
│ col6 │ Float64 │ │ │ │ │ │
│ col7 │ Float64 │ │ │ │ │ │
│ col8 │ Float64 │ │ │ │ │ │
│ col9 │ Float64 │ │ │ │ │ │
│ col10 │ Float64 │ │ │ │ │ │
│ col11 │ Float64 │ │ │ │ │ │
│ col12 │ Float64 │ │ │ │ │ │
│ col13 │ UInt64 │ │ │ │ │ │
│ col14 │ UInt64 │ │ │ │ │ │
└───────┴─────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘
14 rows in set. Elapsed: 0.001 sec.
19c01 :) select avg(col1),max(col1),min(col1),avg(col2),max(col2),min(col2) from t1;
SELECT
avg(col1),
max(col1),
min(col1),
avg(col2),
max(col2),
min(col2)
FROM t1
Query id: f954bed4-2091-4763-b2b5-df0ddbf61074
┌──────────avg(col1)─┬─max(col1)─┬─min(col1)─┬──────────avg(col2)─┬─max(col2)─┬─min(col2)─┐
│ 13.000617977528137 │ 14.83 │ 11.03 │ 2.3363483146067514 │ 5.8 │ 0.74 │
└────────────────────┴───────────┴───────────┴────────────────────┴───────────┴───────────┘
1 row in set. Elapsed: 0.080 sec. Processed 46.66 million rows, 746.59 MB (580.75 million rows/s., 9.29 GB/s.)
Peak memory usage: 353.11 KiB.
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




