安装

系统要求

ClickHouse可以在任何具有x86_64,AArch64或PowerPC64LE CPU架构的Linux,FreeBSD或Mac OS X上运行。

官方预构建的二进制文件通常针对x86_64进行编译,并利用SSE 4.2指令集,因此,除非另有说明,支持它的CPU使用将成为额外的系统需求。下面是检查当前CPU是否支持SSE 4.2的命令:

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

要在不支持SSE 4.2AArch64PowerPC64LE架构的处理器上运行ClickHouse,您应该通过适当的配置调整从源代码构建ClickHouse

可用安装包

DEB安装包

建议使用Debian或Ubuntu的官方预编译deb软件包。运行以下命令来安装包:

  1. sudo apt-get install -y apt-transport-https ca-certificates dirmngr
  2. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
  3. echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
  4. /etc/apt/sources.list.d/clickhouse.list
  5. sudo apt-get update
  6. sudo apt-get install -y clickhouse-server clickhouse-client
  7. sudo service clickhouse-server start
  8. clickhouse-client # or "clickhouse-client --password" if you've set up a password.
Deprecated Method for installing deb-packages bash 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.

如果您想使用最新的版本,请用testing替代stable(我们只推荐您用于测试环境)。

你也可以从这里手动下载安装包:下载

安装包列表:

  • clickhouse-common-static — ClickHouse编译的二进制文件。
  • clickhouse-server — 创建clickhouse-server软连接,并安装默认配置服务
  • clickhouse-client — 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。
  • clickhouse-common-static-dbg — 带有调试信息的ClickHouse二进制文件。

RPM安装包

推荐使用CentOS、RedHat和所有其他基于rpm的Linux发行版的官方预编译rpm包。

首先,您需要添加官方存储库:

  1. sudo yum install -y yum-utils
  2. sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
  3. sudo yum install -y clickhouse-server clickhouse-client
  4. sudo /etc/init.d/clickhouse-server start
  5. clickhouse-client # or "clickhouse-client --password" if you set up a password.
Deprecated Method for installing rpm-packages bash 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.

如果您想使用最新的版本,请用testing替代stable(我们只推荐您用于测试环境)。prestable有时也可用。

然后运行命令安装:

  1. sudo yum install clickhouse-server clickhouse-client

你也可以从这里手动下载安装包:下载

Tgz安装包

如果您的操作系统不支持安装debrpm包,建议使用官方预编译的tgz软件包。

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

下载后解压缩下载资源文件并使用安装脚本进行安装。以下是一个最新稳定版本的安装示例:

  1. LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
  2. grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
  3. export LATEST_VERSION
  4. case $(uname -m) in
  5. x86_64) ARCH=amd64 ;;
  6. aarch64) ARCH=arm64 ;;
  7. *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
  8. esac
  9. for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
  10. do
  11. curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
  12. || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
  13. done
  14. tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  15. || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
  16. sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"
  17. tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  18. || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
  19. sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
  20. tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  21. || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
  22. sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
  23. sudo /etc/init.d/clickhouse-server start
  24. tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  25. || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
  26. sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
Deprecated Method for installing tgz archives bash 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

对于生产环境,建议使用最新的stable版本。你可以在GitHub页面https://github.com/ClickHouse/ClickHouse/tags找到它,它以后缀`-stable`标志。

Docker安装包

要在Docker中运行ClickHouse,请遵循Docker Hub上的指南。它是官方的deb安装包。

其他环境安装包

对于非linux操作系统和Arch64 CPU架构,ClickHouse将会以master分支的最新提交的进行编译提供(它将会有几小时的延迟)。

  • 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

下载后,您可以使用clickhouse client连接服务,或者使用clickhouse local模式处理数据,不过您必须要额外在GitHub下载serverusers配置文件。

不建议在生产环境中使用这些构建版本,因为它们没有经过充分的测试,但是您可以自行承担这样做的风险。它们只是ClickHouse功能的一个部分。

使用源码安装

要手动编译ClickHouse, 请遵循LinuxMac OS X说明。

您可以编译并安装它们,也可以使用不安装包的程序。通过手动构建,您可以禁用SSE 4.2AArch64 cpu

  1. Client: programs/clickhouse-client
  2. Server: programs/clickhouse-server

您需要创建一个数据和元数据文件夹,并为所需的用户chown授权。它们的路径可以在服务器配置(src/programs/server/config.xml)中改变,默认情况下它们是:

  1. /opt/clickhouse/data/default/
  2. /opt/clickhouse/metadata/default/

在Gentoo上,你可以使用emerge clickhouse从源代码安装ClickHouse。

启动

如果没有service,可以运行如下命令在后台启动服务:

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

日志文件将输出在/var/log/clickhouse-server/文件夹。

如果服务器没有启动,检查/etc/clickhouse-server/config.xml中的配置。

您也可以手动从控制台启动服务器:

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

在这种情况下,日志将被打印到控制台,这在开发过程中很方便。

如果配置文件在当前目录中,则不需要指定——config-file参数。默认情况下,它的路径为./config.xml

ClickHouse支持访问限制设置。它们位于users.xml文件(与config.xml同级目录)。 默认情况下,允许default用户从任何地方访问,不需要密码。可查看user/default/networks。 更多信息,请参见Configuration Files

启动服务后,您可以使用命令行客户端连接到它:

  1. $ clickhouse-client

默认情况下,使用default用户并不携带密码连接到localhost:9000。还可以使用--host参数连接到指定服务器。

终端必须使用UTF-8编码。 更多信息,请参阅Command-line client

示例:

  1. $ ./clickhouse-client
  2. ClickHouse client version 0.0.18749.
  3. Connecting to localhost:9000.
  4. Connected to ClickHouse server version 0.0.18749.
  5. :) SELECT 1
  6. SELECT 1
  7. ┌─1─┐
  8. 1
  9. └───┘
  10. 1 rows in set. Elapsed: 0.003 sec.
  11. :)

恭喜,系统已经工作了!

为了继续进行实验,你可以尝试下载测试数据集或查看教程

原始文章