正文
基于OpenJDK部署clickhouse-local镜像的快捷方法
摘要
前期搭建了一套基于OpenJDK的Clickhouse的服务端的镜像
可以简单使用dbeaver进行连接与使用.
后来发现需求与自己理解的不一样.
更加需要的是一套使用clickhouse-local 进行文件解析处理的功能.
服务可以不运行.
所以之前的思路需要改善一下.
部署方式
clickhouse 有多种安装方式.
可以使用在线安装, tar包离线安装,rpm包安装等等方式.
本次简单起见还是仿照之前 在线 sh安装的一部分来进行.
获取对应的二进制进行容器内安装,然后清理部分文件.
仅保留clickhouse-local等指令的方式.
说明
只留客户端时不需要 不需要部分配置文件.
不然会在执行命令是报错如下:
会打印出来很多日志.
在同事的提醒下发现删除部分呢配置文件就可以简单实现不打印日志的方法了
root@33dd1af16f9d:/etc/clickhouse-server# clickhouse-local -q "select 1024"
Processing configuration file 'config.xml'.
Merging configuration file 'config.d/data-paths.xml'.
Merging configuration file 'config.d/logger.xml'.
Merging configuration file 'config.d/openssl.xml'.
Merging configuration file 'config.d/user-directories.xml'.
Logging trace to /var/log/clickhouse-server/clickhouse-server.log
Logging errors to /var/log/clickhouse-server/clickhouse-server.err.log
2023.08.31 23:30:25.601851 [ 275 ] {} <Debug> ConfigProcessor: Processing configuration file 'users.xml'.
2023.08.31 23:30:25.602663 [ 275 ] {} <Debug> Access(user directories): Added users.xml access storage 'users.xml', path:
2023.08.31 23:30:25.603207 [ 275 ] {} <Debug> Application: Loading metadata from /var/lib/clickhouse/
2023.08.31 23:30:25.603633 [ 275 ] {} <Information> DatabaseAtomic (system): Metadata processed, database system has 0 tables and 0 dictionaries in total.
2023.08.31 23:30:25.603660 [ 275 ] {} <Information> TablesLoader: Parsed metadata of 0 tables in 1 databases in 0.000103018 sec
2023.08.31 23:30:25.603697 [ 275 ] {} <Information> TablesLoader: Loading 0 tables with 0 dependency level
2023.08.31 23:30:25.614048 [ 275 ] {} <Information> DatabaseAtomic (system): Starting up tables.
2023.08.31 23:30:25.615546 [ 275 ] {} <Information> BackgroundSchedulePool/BgSchPool: Create BackgroundSchedulePool with 128 threads
2023.08.31 23:30:25.621375 [ 275 ] {} <Information> UserDefinedSQLObjectsLoaderFromDisk: Loading user defined objects from /var/lib/clickhouse/user_defined/
2023.08.31 23:30:25.622740 [ 275 ] {} <Debug> UserDefinedSQLObjectsLoaderFromDisk: User defined objects loaded
2023.08.31 23:30:25.622772 [ 275 ] {} <Debug> Application: Loaded metadata.
2023.08.31 23:30:25.631443 [ 275 ] {} <Debug> LOCAL-Session: 47005b6e-b7c6-4f66-94a1-ff92abda4d18 Authenticating user 'default' from 127.0.0.1:0
2023.08.31 23:30:25.631499 [ 275 ] {} <Debug> LOCAL-Session: 47005b6e-b7c6-4f66-94a1-ff92abda4d18 Authenticated with global context as user 94309d50-4f52-5250-31bd-74fecac179db
2023.08.31 23:30:25.631514 [ 275 ] {} <Debug> LOCAL-Session: 47005b6e-b7c6-4f66-94a1-ff92abda4d18 Creating session context with user_id: 94309d50-4f52-5250-31bd-74fecac179db
2023.08.31 23:30:25.631676 [ 275 ] {} <Trace> ContextAccess (default): Settings: readonly=0, allow_ddl=true, allow_introspection_functions=false
2023.08.31 23:30:25.631707 [ 275 ] {} <Trace> ContextAccess (default): List of all grants: GRANT SHOW, SELECT, INSERT, ALTER, CREATE, DROP, TRUNCATE, OPTIMIZE, BACKUP, KILL QUERY, KILL TRANSACTION, MOVE PARTITION BETWEEN SHARDS, SYSTEM, dictGet, INTROSPECTION, SOURCES, CLUSTER ON *.*
2023.08.31 23:30:25.631721 [ 275 ] {} <Trace> ContextAccess (default): List of all grants including implicit: GRANT SHOW, SELECT, INSERT, ALTER, CREATE, DROP, TRUNCATE, OPTIMIZE, BACKUP, KILL QUERY, KILL TRANSACTION, MOVE PARTITION BETWEEN SHARDS, SYSTEM, dictGet, INTROSPECTION, SOURCES, CLUSTER ON *.*
2023.08.31 23:30:25.631845 [ 275 ] {} <Debug> LOCAL-Session: 47005b6e-b7c6-4f66-94a1-ff92abda4d18 Creating query context from session context, user_id: 94309d50-4f52-5250-31bd-74fecac179db, parent context user: default
2023.08.31 23:30:25.631937 [ 275 ] {776f4845-9f41-4ffa-83f3-24f916c2b255} <Debug> executeQuery: (from 0.0.0.0:0, user: ) select 1024 (stage: Complete)
2023.08.31 23:30:25.632271 [ 275 ] {776f4845-9f41-4ffa-83f3-24f916c2b255} <Trace> ContextAccess (default): Access granted: SELECT(dummy) ON system.one
2023.08.31 23:30:25.632373 [ 275 ] {776f4845-9f41-4ffa-83f3-24f916c2b255} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
1024
1024 就是需要查询出来的结构
下载方式
https://mirrors.aliyun.com/clickhouse/tgz/lts/
获取到tar包,解压缩出来一个 clickhouse的文件就可以了.
打包方式
文件主要如下 :
[root@tidb01 clickhouse]# tree -L 1
.
├── clickhouse
└── dockerfile
dockerfile
FROM 192.168.xxx.xx:5000/library/openjdk:8
COPY clickhouse /usr/bin/
WORKDIR /etc/clickhouse-server
RUN /usr/bin/clickhouse install
RUN rm -rf /etc/clickhouse-server/*
生成镜像与验证
docker build . -t clickhouse:v1.0
验证
docker run -it clickhouse:v1.0 bash
执行命令:
root@d5dc9984a419:/etc/clickhouse-server# clickhouse-local -q "select 1"
1