[Getting Started] Installation and Configuration of ClickHouse


Insert image description here

ClickHouse is a columnar database management system (DBMS) for online analytics (OLAP).
Insert image description here

0. Preface

Install ClickHouse: First, you need to choose the installation method suitable for your operating system. ClickHouse provides various installation methods, including binary package installation, Docker container installation and source code compilation installation. You can choose one of the installation methods according to your needs.

ClickHouse installation

The recommended way to install ClickHouse on Unix-like systems (including Linux and Mac OS) is to use the precompiled binary package. Here are the steps to install ClickHouse on Ubuntu:

1. Add ClickHouse warehouse

sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4

echo "deb https://repo.clickhouse.tech/deb/stable/ main/" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update

2. Install ClickHouse

sudo apt-get install -y clickhouse-server clickhouse-client

3. Start the ClickHouse server

sudo service clickhouse-server start

4. Using the ClickHouse client

clickhouse-client

If you are on Windows, you can use Docker. First install Docker, then run the following command to get the ClickHouse image and run it:

docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server

Then you can use the ClickHouse client to connect to the server:

docker run -it --rm --link some-clickhouse-server:clickhouse-server yandex/clickhouse-client --host clickhouse-server

ClickHouse configuration

ClickHouse configuration files are usually in /etc/clickhouse-server/the directory.

The main configuration file is config.xmlwhere you can set various behaviors of the server, such as memory limits, connection limits, authentication, logging, etc.

You can also users.xmlset user-level configurations in the file, such as access permissions, query restrictions, etc.

You can connect directly to the server using clickhouse-client. If you need to connect remotely, you may need to users.xmladd the corresponding network access permissions in .

1. Detailed installation tutorial

1.1. System requirements

ClickHouse runs on any Linux, FreeBSD or Mac OS X with x86_64, AArch64 or PowerPC64LE CPU architecture.

Official prebuilt binaries are usually compiled against x86_64 and take advantage of SSE 4.2the instruction set, so CPU usage that supports it will be an additional system requirement unless otherwise stated. Here is the command to check whether the current CPU supports SSE 4.2:

$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

To run ClickHouse on processors that do not support SSE 4.2the or AArch64, architecture, you should build ClickHouse from sourcePowerPC64LE with the appropriate configuration adjustments .

1.1. Available installation packages {#install-from-deb-packages}

1.1.1.Installation DEBpackage

It is recommended to use official precompiled debpackages from Debian or Ubuntu. Run the following command to install the package:

sudo apt-get install -y apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754

echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update

sudo apt-get install -y clickhouse-server clickhouse-client

sudo service clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you've set up a password.
Deprecated Method for installing deb-packages
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4

echo "deb https://repo.clickhouse.com/deb/stable/ main/" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update

sudo apt-get install -y clickhouse-server clickhouse-client

sudo service clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.

If you want to use the latest version, please use testinginstead stable(we only recommend this for testing environments).

You can also download the installation package manually from here: Download .

Installation package list:

  • clickhouse-common-static— ClickHouse compiled binaries.
  • clickhouse-server— Create clickhouse-servera soft connection and install the default configuration service
  • clickhouse-client—Create clickhouse-clienta soft connection to the client tool and install the client configuration file.
  • clickhouse-common-static-dbg— ClickHouse binaries with debugging information.

1.1.1. RPMInstallation package {#from-rpm-packages}

It is recommended to use the official precompiled rpmpackages of CentOS, RedHat and all other rpm-based Linux distributions.

First, you need to add the official repository:

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
sudo yum install -y clickhouse-server clickhouse-client

sudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.

For systems with zypper package manager (openSUSE, SLES):

sudo zypper addrepo -r https://packages.clickhouse.com/rpm/clickhouse.repo -g
sudo zypper --gpg-auto-import-keys refresh clickhouse-stable
sudo zypper install -y clickhouse-server clickhouse-client

sudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
Deprecated Method for installing rpm-packages
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.com/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.com/rpm/clickhouse.repo
sudo yum install clickhouse-server clickhouse-client

sudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.

If you want to use the latest version, please use testinginstead stable(we only recommend this for testing environments). prestableAlso available sometimes.

Then run the command to install:

sudo yum install clickhouse-server clickhouse-client

You can also download the installation package manually from here: Download .

1.1.1.Installation Tgzpackage {#from-tgz-archives}

If your operating system does not support installation debor rpmpackages, it is recommended to use official precompiled tgzpackages.

The required version can be downloaded via curlor wgetfrom the repository https://packages.clickhouse.com/tgz/.

After downloading, unzip the downloaded resource file and install it using the installation script. Here is an example installation of the latest stable version:

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"
Deprecated Method for installing tgz archives
export LATEST_VERSION=$(curl -s https://repo.clickhouse.com/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-common-static-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-server-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-client-$LATEST_VERSION.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.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

For production environments, it is recommended to use the latest stableversion. You can find it on the GitHub page https://github.com/ClickHouse/ClickHouse/tags, where it is -stablemarked with the suffix suffix.

1.1.1.Installation Dockerpackage {#from-docker-image}

To run ClickHouse in Docker, follow the guide on Docker Hub . It is the official debinstallation package.

1.1.1. Other environment installation packages {#from-other}

For non-linux operating systems and Arch64 CPU architectures, ClickHouse will be mastercompiled and provided from the latest commit of the branch (it will be delayed by a few hours).

  • macOScurl -O 'https://builds.clickhouse.com/master/macos/clickhouse' && chmod a+x ./clickhouse
  • FreeBSDcurl -O 'https://builds.clickhouse.com/master/freebsd/clickhouse' && chmod a+x ./clickhouse
  • AArch64curl -O 'https://builds.clickhouse.com/master/aarch64/clickhouse' && chmod a+x ./clickhouse

After downloading, you can use clickhouse clientthe connection service or use clickhouse localthe pattern to process the data, but you must additionally download the server and users configuration files from GitHub.

It is not recommended to use these builds in production environments as they are not fully tested, but you can do so at your own risk. They are just a part of ClickHouse functionality.

1.1.1. Install from source {#from-sources}

To compile ClickHouse manually, follow the Linux or Mac OS X instructions.

You can compile and install them, or use a program that doesn't install the package. With a manual build you can disable SSE 4.2or AArch64 cpu.

  Client: programs/clickhouse-client
  Server: programs/clickhouse-server

You need to create a data and metadata folder and chownauthorize the required users. Their paths can src/programs/server/config.xmlbe changed in the server configuration ( ), by default they are:

  /opt/clickhouse/data/default/
  /opt/clickhouse/metadata/default/

On Gentoo, you can emerge clickhouseinstall ClickHouse from source using .

1.1. Start {#qi-dong}

If not service, you can run the following command to start the service in the background:

$ sudo /etc/init.d/clickhouse-server start

Log files will be output in /var/log/clickhouse-server/the folder.

If the server does not start, check /etc/clickhouse-server/config.xmlthe configuration.

You can also start the server manually from the console:

$ clickhouse-server --config-file=/etc/clickhouse-server/config.xml

In this case, the log will be printed to the console, which is convenient during development.

If the configuration file is in the current directory, no ——config-fileparameters need to be specified. By default, its path is ./config.xml.

ClickHouse supports access restriction settings. They are located in users.xmlfiles ( config.xmlsibling directories).
By default, defaultusers are allowed access from anywhere, no password is required. Available for viewing user/default/networks.
See Configuration Files for more information .

After starting the service, you can connect to it using a command line client:

$ clickhouse-client

By default, defaultthe user is connected to without a password localhost:9000. You can also use --hostparameters to connect to a specified server.

The terminal must use UTF-8 encoding.
See Command-line client for more information .

Example:

$ ./clickhouse-client
ClickHouse client version 0.0.18749.
Connecting to localhost:9000.
Connected to ClickHouse server version 0.0.18749.

:) SELECT 1

SELECT 1

┌─1─┐
│ 1 │
└───┘

1 rows in set. Elapsed: 0.003 sec.

:)

Congratulations, the system is working!

In order to continue the experiment, you can try downloading the test dataset or check out the tutorial .

Guess you like

Origin blog.csdn.net/wangshuai6707/article/details/132920695