Overview
The deployment method of ClickHouse
has a detailed tutorial in the official document. Depending on the format of the installation package, it is divided into rpm
deployment, deb
package deployment, and tgz
deployment. All three deployments can be made into services and become resident processes daemon
programs. The most widely used is the rpm
deployment method. The deb package deployment is only different in the installation command, which is similar to the rpm
method.
This article mainly explains how to deploy clickhouse
tgz
---2e44b350c9852706a589d494d5c0e02e---. And demonstrate how to deploy a single node successfully, as for how to build a clickhouse
cluster, as long as a single node can be successfully installed, just modify the configuration, this article will not do more.
Official tgz deployment
The installation package can be downloaded from https://packages.clickhouse.com/tgz/ . It is recommended to download the LTS
version. The version of the installation package demonstrated in this article is 22.3.6.5
, mainly download three packages :
- https://packages.clickhouse.com/tgz/lts/clickhouse-client-22.3.6.5-amd64.tgz
- https://packages.clickhouse.com/tgz/lts/clickhouse-common-static-22.3.6.5-amd64.tgz
- https://packages.clickhouse.com/tgz/lts/clickhouse-server-22.3.6.5-amd64.tgz
The official installation manual is at Installation | ClickHouse Docs , and I summarize the commands from the documentation as follows:
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
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-$LATEST_VERSION-amd64.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION-amd64.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-server-$LATEST_VERSION-amd64.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-client-$LATEST_VERSION-amd64.tgz"
tar -xzvf "clickhouse-common-static-$LATEST_VERSION-amd64.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"
tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-amd64.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
tar -xzvf "clickhouse-server-$LATEST_VERSION-amd64.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh"
sudo /etc/init.d/clickhouse-server start
tar -xzvf "clickhouse-client-$LATEST_VERSION-amd64.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
dbg
The package is a debug version, we don't need it. Next, we follow this step to install.
First, download the installation package and unzip it:
wget https://packages.clickhouse.com/tgz/lts/clickhouse-client-22.3.6.5-amd64.tgz
wget https://packages.clickhouse.com/tgz/lts/clickhouse-common-static-22.3.6.5-amd64.tgz
wget https://packages.clickhouse.com/tgz/lts/clickhouse-server-22.3.6.5-amd64.tgz
tar -xzvf clickhouse-client-22.3.6.5-amd64.tgz
tar -xzvf clickhouse-common-static-22.3.6.5-amd64.tgz
tar -xzvf clickhouse-server-22.3.6.5-amd64.tgz
As follows:
After decompression is installed, according to the official manual, directly execute the script doinst.sh
.
There are two points to note when installing:
-
doinst.sh
Script installation requiresroot
permission, therefore, need to useroot
user or a normal user withsudo
permission. - 注意安装顺序,先安装
common
,server
c5d5486dcde2abc50574127e59140965---和client
,server
和---2f78c3d8c24e85cf18b5f83a6ad68702client
.
The execution command is as follows:
sudo clickhouse-common-static-22.3.6.5/install/doinst.sh
sudo clickhouse-server-22.3.6.5/install/doinst.sh
sudo clickhouse-client-22.3.6.5/install/doinst.sh
common
and client
execute the script directly. server
There are two places where you need to interact with the user during installation:
Here you need to fill in default
the user's password, of course, you can also press Enter directly, do not fill in the password, if you do not set the password, there will be no second interaction, if you enter the password, (as I enter here 123456
), the following interactive interface will appear:
Here is to ask whether to allow remote access. The default is to allow local access only. We choose y
, and the following interface appears, indicating that server
has been installed:
If you do not want to jump out of the interactive page during installation, you can disable this function by setting the environment variable DEBIAN_FRONTEND=noninteractive
, then the default will not be set default
user password:
sudo DEBIAN_FRONTEND=noninteractive clickhouse-server-22.3.6.5/install/doinst.sh
After the installation is complete, you can start the clickhouse
service. Start the command:
sudo clickhouse start
The following prompt appears, indicating that the startup was successful:
It can be viewed through the clickhouse status
command:
We can also verify by client connection server
:
clickhouse-client -m --password=123456
This is installed through the official script. In fact, clickhouse
also provides the install
command, which is placed in the clickhouse-common-static-22.3.6.5/usr/bin
directory. Installed path and user. But you also need root
permission to install correctly.
[eoi@ck14 clickhouse]$ ./clickhouse-common-static-22.3.6.5/usr/bin/clickhouse install -h
Usage: sudo ./clickhouse-common-static-22.3.6.5/usr/bin/clickhouse install [options]
-h [ --help ] produce help message
--prefix arg (=/) prefix for all paths
--binary-path arg (=usr/bin) where to install binaries
--config-path arg (=etc/clickhouse-server)
where to install configs
--log-path arg (=var/log/clickhouse-server)
where to create log directory
--data-path arg (=var/lib/clickhouse) directory for data
--pid-path arg (=var/run/clickhouse-server)
directory for pid file
--user arg (=clickhouse) clickhouse user to create
--group arg (=clickhouse) clickhouse group to create
clickhouse-server-22.3.6.5/lib/systemd/system
下,有clickhouse-server.service
文件,将该文件拷贝到/etc/systemd/system
目录下, clickhouse
Management, you can manage it through systemctl
.
In the clickhouse-server-22.3.6.5/etc/init.d
directory, there is a clickhouse-server
file, copy it to /etc/init.d
, you can realize the self-start of clickhouse-server
boot.
Deploy without root
The official tgz
installation tutorial is simple and easy to operate, but it requires a premise that all installation, startup and other operations must use the root
permission. However, in fact, many online operation and maintenance personnel do not directly hold the root
authority. In many cases, IT allocates a common account, and cannot perform the above operations through sudo
. , how to deploy and install without root
clickhouse
is also one of the issues that operation and maintenance personnel need to consider.
Since there is no root
deployment, the rpm
and deb
packages are not considered directly. For tgz
, although the official installation method also requires sudo
to escalate rights, but the principle is nothing more than executing binary files, so we can directly The decompressed binary file is packaged to a certain extent, so that ordinary users can execute normally without relying on root
permissions.
The idea is roughly as follows:
It is still these three installation packages, we only need the configuration files and executable files. The reason why the official installation requires root
permissions, mainly logs, configuration files, executable files and process lock files are all Distributed under the system directory, it must be accessed by the root
user, and the clickhouse
user needs to be created at the same time.
So here, we need to change the above operations involving the system directory to the directory that ordinary users have permission to operate. For example: the account I am currently using is eoi
, assuming that the account does not have the sudo
permission, we create it under /home/eoi
clickhouse
, the folder ---8976e69503507d8d8d8 As the working directory of clickhouse
run, and make the following divisions:
-
etc
directory: configuration file -
log
directory: log file -
bin
Directory: Executable -
run
Directory: Process lock file -
data
Directory: store data
So we can create the installation script as follows:
#install.sh
CWD=$1
if [ x$CWD = "x" ];then
CWD=$(dirname $(cd "$(dirname "$0")" && pwd))
fi
VERSION=$2
if [ x$VERSION = "x" ]; then
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)
fi
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-$VERSION-amd64.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-server-$VERSION-amd64.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-client-$VERSION-amd64.tgz"
tar -xzf "clickhouse-common-static-$VERSION-amd64.tgz"
tar -xzf "clickhouse-server-$VERSION-amd64.tgz"
tar -xzf "clickhouse-client-$VERSION-amd64.tgz"
mkdir -p $CWD/etc/clickhouse-server/config.d $CWD/etc/clickhouse-server/users.d $CWD/etc/clickhouse-client $CWD/log/clickhouse-server $CWD/bin $CWD/run $CWD/data/clickhouse
cp -rf clickhouse-common-static-$VERSION/usr/bin $CWD
cp -rf clickhouse-server-$VERSION/usr/bin $CWD
cp -rf clickhouse-client-$VERSION/usr/bin $CWD
cp -rf clickhouse-server-$VERSION/etc/clickhouse-server $CWD/etc
cp -rf clickhouse-client-$VERSION/etc/clickhouse-client $CWD/etc
#修改配置文件路径
sed -i "s#/var/log#$PWD/log#g" $PWD/etc/clickhouse-server/config.xml
sed -i "s#/var/lib#$PWD/data#g" $PWD/etc/clickhouse-server/config.xml
The above command can basically be installed in the user's own working directory clickhouse
, and then you can do a start.sh
to start clickhouse-server
:
#start.sh
DIR=$(cd "$(dirname "$0")" && pwd)
#log路径由于已经通过配置文件指定了,因此无需再在命令行指定
$DIR/bin/clickhouse-server --config-file=$DIR/etc/clickhouse-server/config.xml --pid-file=$HDIR/run/clickhouse-server.pid --daemon
The script to stop is also simple:
#stop.sh
DIR=$(cd "$(dirname "$0")" && pwd)
ps -ef|grep $DIR/bin/clickhouse-server |grep -v grep |awk '{print $2}' |xargs kill
tgz
There is no upgrade or uninstall operation for deployment. The upgrade is to reinstall, and the uninstallation can directly delete the working directory.
Practical exercise:
Running ./install.sh . 22.3.6.5
in the /home/eoi/clickhouse
directory will add the following files to the current folder:
Focus on whether the files in these two folders are correct:
config.xml
in log
path and path
path has been modified correctly:
If the above checks are all correct, you can start.
When you see the prompt in the above figure, it means that the installation is successful. You can use the clickhouse status
command to check the running status:
You can also use the client
to directly connect to the database. The default installation does not have a password. If you need a password, you can modify the install
script and pass in a password:
Summarize
本文简单讲述tgz
方式安装clickhouse
服务,并介绍了无root
clickhouse
服务, but once the server is down, this installation method cannot achieve self-starting at boot, although the official installation package includes systemd
clickhouse-server.service
and init.d
scripts , but both depend on root
permissions, so this is still an unsolved problem. Therefore, once the service is down, if there is no root
permission, you can only restart one by one.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。