12.【clickhouse】ClickHouse从入门到放弃-环境搭建

简介: 【clickhouse】ClickHouse从入门到放弃-环境搭建

前文如下:


11.【clickhouse】ClickHouse从入门到放弃-概述


书接上回,今天学习如何搭建clickhouse

2 环境搭建

2.1 版本选择

ClickHouse: 22.4.5.9
CentOS: Linux release 7.9.2009
MySQL:MySQL-5.7

2.2 下载安装

采用官方预编译的tgz软件包方式安装。

参考文档:

clickhouse.com/docs/zh/get…

所需的版本可以通过curlwget从存储库https://packages.clickhouse.com/tgz/下载。

# 查看最新版本 22.4.5.9
[root@localhost anchu]# curl -s https://packages.clickhouse.com/tgz/stable/ |grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sort -V -r | head -n 1
22.4.5.9
# 设置临时环境变量并下载
[anchu@localhost ~]$ 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)
[anchu@localhost ~]$ export LATEST_VERSION
[anchu@localhost ~]$ echo $LATEST_VERSION
22.4.5.9
[anchu@localhost ~]$ cd software/
[anchu@localhost software]$ mkdir clickhouse
[anchu@localhost software]$ cd clickhouse/
# 根据最新版本下载
[anchu@localhost clickhouse]$ curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-server-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-client-$LATEST_VERSION-amd64.tgz"
# 查看并解压
[anchu@localhost clickhouse]$ ll -h
total 1011M
-rw-rw-r--. 1 anchu anchu 35K May 11 11:03 clickhouse-client-22.4.5.9-amd64.tgz
-rw-rw-r--. 1 anchu anchu 226M May 11 10:54 clickhouse-common-static-22.4.5.9-amd64.tgz
-rw-rw-r--. 1 anchu anchu 785M May 11 11:01 clickhouse-common-static-dbg-22.4.5.9-amd64.tgz
-rw-rw-r--. 1 anchu anchu 55K May 11 11:03 clickhouse-server-22.4.5.9-amd64.tgz
#解压安装
[anchu@localhost clickhouse]$ tar -xzvf "clickhouse-common-static-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$ tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$ tar -xzvf "clickhouse-server-$LATEST_VERSION-amd64.tgz"
[anchu@localhost clickhouse]$ tar -xzvf "clickhouse-client-$LATEST_VERSION-amd64.tgz"

官网操作(需要注意要加操作系统类型,最新版本加入了操作系统名称amd64,原来的url无法下载数据):

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
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.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh"
sudo /etc/init.d/clickhouse-server start
tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

#注意 :下面这个因为下载的时候没带amd64,导致下载的文件不对

网络异常,图片无法展示
|

正常的下载如下:

网络异常,图片无法展示
|

对于生产环境,建议使用最新的stable版本。你可以在GitHub页面github.com/ClickHouse/…

网络异常,图片无法展示
|


2.3 配置启动

首先,需要当前用户有sudo权限,配置如下

[root@localhost clickhouse]# su root
[root@localhost clickhouse]# chmod u+w /etc/sudoers
[root@localhost clickhouse]# vi /etc/sudoers
anchu   ALL=(ALL)       ALL

初始化

[anchu@localhost clickhouse]$ su anchu
Password:
[anchu@localhost clickhouse]$ pwd
/home/anchu/software/clickhouse
[anchu@localhost clickhouse]$ sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"
[anchu@localhost clickhouse]$sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
[anchu@localhost clickhouse] sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh"
# 安装clickhouse-server
[anchu@localhost clickhouse]$ sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh"
ClickHouse binary is already located at /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.
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 /home/anchu/software/clickhouse/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter 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.
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.
Data path configuration override is saved to file /etc/clickhouse-server/config.d/data-paths.xml.
Log path configuration override is saved to file /etc/clickhouse-server/config.d/logger.xml.
User directory path configuration override is saved to file /etc/clickhouse-server/config.d/user-directories.xml.
OpenSSL path configuration override is saved to file /etc/clickhouse-server/config.d/openssl.xml.
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]:
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
#默认用户 default 密码 clickhouse
# 安装clickhouse-client
[anchu@localhost clickhouse]$  sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

网络异常,图片无法展示
|

启动clickhouse-server

[anchu@localhost clickhouse]$  sudo clickhouse start
chown -R clickhouse: '/var/run/clickhouse-server/'
Will run su -s /bin/sh 'clickhouse' -c '/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
Server started

启动clickhouse-client,并连接clickhouse-server  (--multiline等同于-m,支持sql换行)

[anchu@localhost clickhouse]$ clickhouse-client --user=default --password=clickhouse --host=127.0.0.1 --multiline
ClickHouse client version 22.4.5.9 (official build).
Connecting to 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 22.4.5 revision 54455.
Warnings:
* Linux transparent hugepage are set to "always".
* Linux threads max count is too low.
* Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
localhost :) show tables;
SHOW TABLES
0 rows in set. Elapsed: 0.002 sec.
localhost :) quit;
Bye.

查看进程

[anchu@localhost ~]$ ps -ef|grep clickhouse
clickho+  29606      1  0 11:30 ?        00:00:00 clickhouse-watchdog        --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
clickho+  29607  29606  1 11:30 ?        00:00:11 /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
anchu     29991  29295  0 11:40 pts/2    00:00:00 clickhouse-client --user=default --password=           -h 127.0.0.1 --port 9000 -m
anchu     30036  29855  0 11:45 pts/1    00:00:00 grep --color=auto clickhouse

登录数据库执行的每条SQL,ClickHouse都会自动记录到当前用户根路径的.clickhouse-client-history

[anchu@localhost ~]$ cat ~/.clickhouse-client-history
### 2022-05-11 11:34:31.179
show tables;
### 2022-05-11 11:37:23.508
quit;
### 2022-05-11 11:41:50.100
select 1;
### 2022-05-11 11:42:22.323
quit;
[anchu@localhost ~]$

2.4 测试数据

修改默认配置文件/etc/clickhouse-server/config.xml,支持远程访问

[anchu@localhost ~]$ su root
Password:
[root@localhost anchu]# vi /etc/clickhouse-server/config.xml
[root@localhost anchu]# chmod u+w /etc/clickhouse-server/config.xml
[root@localhost anchu]# vi /etc/clickhouse-server/config.xml
#去掉注释
<listen_host>::</listen_host>
#或者 <listen_host>0.0.0.0</listen_host>
#重启
[anchu@localhost ~]$ su anchu
#注意启动方式
[anchu@localhost ~]$
sudo clickhouse start

连接测试 (dbeaver或者clickhouse客户端均可)

网络异常,图片无法展示
|

#默认用户 default 密码 clickhouse 默认库default
[anchu@localhost clickhouse]$ clickhouse-client --user=default --password=clickhouse -h 192.168.120.110 --port 9000 -m
ClickHouse client version 22.4.5.9 (official build).
Connecting to 192.168.120.110:9000 as user default.
Connected to ClickHouse server version 22.4.5 revision 54455.
localhost :)



相关文章
|
存储 SQL 大数据
大数据技术之ClickHouse---入门篇---介绍
大数据技术之ClickHouse---入门篇---介绍
|
7月前
|
SQL 数据可视化 Linux
ClickHouse【环境搭建 03】Linux环境离线安装 clickhouse-22.3.3.44 配置参数说明+可视化界面使用(离线安装文件分享百度云盘)
ClickHouse【环境搭建 03】Linux环境离线安装 clickhouse-22.3.3.44 配置参数说明+可视化界面使用(离线安装文件分享百度云盘)
500 0
|
安全 大数据 Linux
大数据技术之Clickhouse---入门篇---安装
大数据技术之Clickhouse---入门篇---安装
|
存储 SQL 大数据
大数据技术之Clickhouse---入门篇---数据类型、表引擎
大数据技术之Clickhouse---入门篇---数据类型、表引擎
|
1月前
|
存储 SQL Docker
ClickHouse入门指南:快速搭建与使用
【10月更文挑战第26天】在大数据时代,如何高效地处理海量数据成为了许多企业和开发者的关注点。ClickHouse 是一个开源的列式数据库管理系统(Column-Oriented DBMS),以其出色的查询性能和高并发能力,在数据分析领域迅速崛起。本文将从一个初学者的角度出发,详细介绍如何快速上手 ClickHouse,涵盖从环境搭建到基础操作的全过程。
58 3
|
SQL 缓存 大数据
大数据技术之Clickhouse---入门篇---SQL操作、副本
大数据技术之Clickhouse---入门篇---SQL操作、副本
|
7月前
|
数据安全/隐私保护
ClickHouse【环境搭建 02】设置用户密码的两种方式(明文+SHA256)及新用户添加及只读模式 Cannot execute query in readonly mode 问题解决
ClickHouse【环境搭建 02】设置用户密码的两种方式(明文+SHA256)及新用户添加及只读模式 Cannot execute query in readonly mode 问题解决
484 0
|
7月前
|
Unix Linux 程序员
ClickHouse【环境搭建 01】Linux环境单机版在线安装 Code:210.DB::NetException + Init script is already running 问题处理
ClickHouse【环境搭建 01】Linux环境单机版在线安装 Code:210.DB::NetException + Init script is already running 问题处理
233 0
|
存储 安全 中间件
ClickHouse环境搭建
ClickHouse环境搭建
113 0
|
存储 索引
67.【clickhouse】ClickHouse从入门到放弃-对于分区、索引、标记和压缩数据的协同总结
【clickhouse】ClickHouse从入门到放弃-对于分区、索引、标记和压缩数据的协同总结
67.【clickhouse】ClickHouse从入门到放弃-对于分区、索引、标记和压缩数据的协同总结