本文总结如何在CentOS系统中通过RPM包的方式安装不同版本的ClickHouse服务。
一、背景
之前在一台CentOS机器上通过RPM包安装了ClickHouse 22.2版本的服务,近期由于环境的原因需要再搭一套ClickHouse服务,打算在相同的节点上再安装更新一些的ClickHouse 22.8版本。但是旧的22.2版本的还需要保留,直接默认安装更新版本的RPM包是无法完成的,会显示和安装的旧版本冲突。
[root@clickhouse]# rpm -ivh clickhouse-common-static-22.8.21.38.x86_64.rpm
Preparing... ################################# [100%]
package clickhouse-common-static-0:22.8.21.38-1.x86_64 is already installed
file /usr/bin/clickhouse from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
file /usr/bin/clickhouse-library-bridge from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
file /usr/bin/clickhouse-odbc-bridge from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
file /usr/share/bash-completion/completions/clickhouse-bootstrap from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
file /usr/share/doc/clickhouse-common-static/AUTHORS from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
file /usr/share/doc/clickhouse-common-static/README.md from install of clickhouse-common-static-0:22.8.21.38-1.x86_64 conflicts with file from package clickhouse-common-static-22.2.2.1-2.x86_64
因此,不能将新的版本安装至默认路径了,rpm命令支持--prefix安装至指定路径,执行一下发现也不行。
[root@clickhouse]# rpm -ivh --prefix=/opt/clickhouse clickhouse-common-static-22.8.21.38.x86_64.rpm
error: package clickhouse-common-static is not relocatable
通过rpm -qpi命令查询rpm包信息发现为“not relocatable”
[root@clickhouse]# rpm -qpi clickhouse-common-static-22.8.21.38.x86_64.rpm
Name : clickhouse-common-static
Epoch : 0
Version : 22.8.21.38
Release : 1
Architecture: x86_64
Install Date: (not installed)
Group :
Size : 753805368
License : Apache
Signature : (none)
Source RPM : clickhouse-common-static-22.8.21.38-1.src.rpm
Build Date : Mon 28 Aug 2023 04:59:17 PM CST
Build Host : ip-172-31-64-217
Relocations : (not relocatable)
Packager : ClickHouse Dev Team <packages+linux@clickhouse.com>
Vendor : ClickHouse Inc.
URL : clickhouse.com
Summary : Common files for ClickHouse
Description :
Common files for ClickHouse
ClickHouse is a column-oriented database management system
that allows generating analytical data reports in real time.
This package provides common files for both clickhouse server and client
通过 查看[rpm命令的手册]发现,--badreloc参数与--relocate一起使用是可以对RPM包中的所有文件进行重定位的。
这样应该是可以将RPM包安装至指定路径的。
二、RPM重定位安装方法
2.1 安装common
首先,查询出common rpm包中所有要安装的文件信息。
[root@clickhouse]# rpm -qpl clickhouse-common-static-22.8.21.38.x86_64.rpm
/usr/bin/clickhouse
/usr/bin/clickhouse-diagnostics
/usr/bin/clickhouse-extract-from-config
/usr/bin/clickhouse-library-bridge
/usr/bin/clickhouse-odbc-bridge
/usr/share/bash-completion/completions/clickhouse
/usr/share/bash-completion/completions/clickhouse-benchmark
/usr/share/bash-completion/completions/clickhouse-bootstrap
/usr/share/bash-completion/completions/clickhouse-client
/usr/share/bash-completion/completions/clickhouse-local
/usr/share/doc/clickhouse-common-static/AUTHORS
/usr/share/doc/clickhouse-common-static/CHANGELOG.md
/usr/share/doc/clickhouse-common-static/LICENSE
/usr/share/doc/clickhouse-common-static/README.md
然后,对安装文件进行重定位。
rpm -ivh --badreloc --relocate /usr=/opt/clickhouse clickhouse-common-static-22.8.21.38.x86_64.rpm
2.2 安装server
首先,查询出server rpm包中所有要安装的文件信息。
[root@clickhouse]# rpm -qpl clickhouse-server-22.8.21.38.x86_64.rpm
/etc/clickhouse-server/config.xml
/etc/clickhouse-server/users.xml
/etc/init.d/clickhouse-server
/lib/systemd/system/clickhouse-server.service
/usr/bin/clickhouse-copier
/usr/bin/clickhouse-keeper
/usr/bin/clickhouse-report
/usr/bin/clickhouse-server
/usr/share/doc/clickhouse-server/AUTHORS
/usr/share/doc/clickhouse-server/CHANGELOG.md
/usr/share/doc/clickhouse-server/LICENSE
/usr/share/doc/clickhouse-server/README.md
然后,对安装文件进行重定位。
rpm -ivh --badreloc --relocate /usr=/opt/clickhouse --relocate /etc=/opt/clickhouse/etc --relocate /lib/systemd/system/clickhouse-server.service=/lib/systemd/system/clickhouse-server2.service clickhouse-server-22.8.21.38.x86_64.rpm
2.3 安装client
首先,查询出client rpm包中所有要安装的文件信息。
[root@clickhouse]# rpm -qpl clickhouse-client-22.8.21.38.x86_64.rpm
/etc/clickhouse-client/config.xml
/usr/bin/clickhouse-benchmark
/usr/bin/clickhouse-client
/usr/bin/clickhouse-compressor
/usr/bin/clickhouse-format
/usr/bin/clickhouse-local
/usr/bin/clickhouse-obfuscator
/usr/share/doc/clickhouse-client/AUTHORS
/usr/share/doc/clickhouse-client/CHANGELOG.md
/usr/share/doc/clickhouse-client/LICENSE
/usr/share/doc/clickhouse-client/README.md
然后,对安装文件进行重定位。
rpm -ivh --badreloc --relocate /usr=/opt/clickhouse --relocate /etc=/opt/clickhouse clickhouse-client-22.8.21.38.x86_64.rpm
三、其他配置
修改/lib/systemd/system/clickhouse-server2.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=simple
User=clickhouse
Group=clickhouse
Restart=always
RestartSec=30
RuntimeDirectory=clickhouse-server
ExecStart=/opt/clickhouse/bin/clickhouse-server --config=/opt/clickhouse/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse/clickhouse-server2.pid
# Minus means that this file is optional.
EnvironmentFile=-/etc/default/clickhouse
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=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-server2服务
[root@clickhouse]# systemctl start clickhouse-server2
[root@clickhouse]# systemctl status clickhouse-server2
● clickhouse-server2.service - ClickHouse Server (analytic DBMS for big data)
Loaded: loaded (/usr/lib/systemd/system/clickhouse-server2.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2024-08-09 11:45:12 CST; 5h 7min ago
Main PID: 727 (clckhouse-watch)
Tasks: 264
Memory: 1.6G
CGroup: /system.slice/clickhouse-server2.service
├─727 clickhouse-watchdog --config=/opt/clickhouse/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse/clickhouse-server2.pid
└─735 /opt/clickhouse/bin/clickhouse-server --config=/opt/clickhouse/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse/clickhouse-server2.pid
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Including configuration file '/opt/clickhouse/etc/clickhouse-server/config.d/vaas_viid_cluster.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Logging trace to /data2/clickhouse2/logs/clickhouse-server.log
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Logging errors to /data2/clickhouse2/logs/clickhouse-server.err.log
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Processing configuration file '/opt/clickhouse/etc/clickhouse-server/config.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Merging configuration file '/opt/clickhouse/etc/clickhouse-server/config.d/vaas_viid_cluster.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Merging configuration file '/opt/clickhouse/etc/clickhouse-server/config.d/vaas_viid_macros.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Including configuration file '/opt/clickhouse/etc/clickhouse-server/config.d/vaas_viid_cluster.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Saved preprocessed configuration to '/data2/clickhouse2/preprocessed_configs/config.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Processing configuration file '/opt/clickhouse/etc/clickhouse-server/users.xml'.
Aug 09 11:45:12 clickhouse clickhouse-server[727]: Saved preprocessed configuration to '/data2/clickhouse2/preprocessed_configs/users.xml'.