CentOS7.9离线安装ClickHouse单机版

1.简介

ClickHouse 是一个开源的面向联机分析处理(OLAP, On-Line Analytical Processing)的列式存储数据库管理系统

优点 缺点
写入快、查询快 不支持事务
SQL 支持 不适合典型的 K/V 存储
简单方便,不依赖 Hadoop 技术栈 不适合 Blob/Document 存储
支持线性扩展 不支持完整的 Update/Delete 操作
深度列存储 非跨平台
向量化查询执行 并非查询资源控制不好处理
数据压缩 不支持二级索引
并行和分布式查询
实时数据更新

关于ClickHouse的介绍实在太多,这里不做过多介绍!请自行Google.

2.离线安装

  • ClickHouse 仅支持Linux 操作系统,且机器 CPU 必须支持 SSE 4.2 指令集。

    cat /proc/cpuinfo |grep sse4_2

2.1 国内镜像站

ClickHouse 官方的下载地址在国外,因为众所周知的原因导致下载速度经常都是龟速,这里可以使用国内镜像站进行安装比较快。感谢无私奉献的国内镜像站。。。

2.2 下载所需资源

  • clickhouse-client :包含 ClickHouse 客户端交互工具
  • clickhouse-common:包含 ClickHouse 服务端执行脚本
  • clickhouse-server :包含 ClickHouse 服务端配置文件
mkdir -p /data/soft && cd /data/soft
# 1.clickhouse-client
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-client-21.9.4.35-2.noarch.rpm
# 2.clickhouse-common-static
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-common-static-21.9.4.35-2.x86_64.rpm
# 3.clickhouse-server
wget https://mirrors.tuna.tsinghua.edu.cn/clickhouse/rpm/stable/x86_64/clickhouse-server-21.9.4.35-2.noarch.rpm
# 4.clickhouse-server-common

2.3 安装rpm包

2.3.1 安装

cd /data/soft
rpm -ivh *.rpm
# 安装过程中需要输入默认用户密码,这里先输入123456

2.3.2 目录说明

  1. /etc/clickhouse-server :clickhouse 服务端配置文件目录
  2. /etc/clickhouse-client :clickhouse 客户端配置文件目录
  3. /var/lib/clickhouse :clickhouse 默认数据目录
  4. /var/log/clickhouse-server :clickhouse 默认日志目录
  5. /etc/init.d/clickhouse-server :clickhouse 服务端启动脚本

2.3.3 启动与验证

  1. 查看服务状态systemctl status clickhouse-server

  2. 启动服务systemctl start clickhouse-server

  3. 进入 Clickhouse 客户端交互界面

    clickhouse-client --password=123a456

    ZiqVvu

  4. 查看数据库

    clickhouse-01 :) show databases;

2.4 修改默认的ClickHouse数据存储目录

  1. 编辑/etc/clickhouse-server/config.xml,修改ClickHouse数据存储目录。

    修改前:

    <path>/var/lib/clickhouse/</path>
    <tmp_path>/var/lib/clickhouse/tmp/</tmp_path>
    <user_files_path>/var/lib/clickhouse/user_files/</user_files_path>

    修改后:

    <path>/data/clickhouse/</path>
    <tmp_path>/data/clickhouse/tmp/</tmp_path>
    <user_files_path>/data/clickhouse/user_files/</user_files_path>
  2. 修改默认的ClickHouse日志存储目录和配置

    根据需要,还可以编辑/etc/clickhouse-server/config.xml,修改默认的ClickHouse日志存储目录和配置。

    修改前:

    <level>trace</level>
    <log>/var/log/clickhouse-server/clickhouse-server.log</log>
    <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
    <!-- Rotation policy
                 See https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/FileChannel.h#L54-L85
              -->
    <size>1000M</size>
    <count>10</count>

    修改后:

    <level>trace</level>
    <log>/data/clickhouse/clickhouse-server.log</log>
    <errorlog>/data/clickhouse/clickhouse-server.err.log</errorlog>
    <!-- Rotation policy
                 See https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/FileChannel.h#L54-L85
              -->
    <size>1000M</size>
    <count>10</count>
    1. 重启服务
    # 复制原数据到新的目录
    cp -R /var/lib/clickhouse/ /data/
    # 授权目录
    chown -R clickhouse.clickhouse /data/clickhouse/
    # 重启服务
    systemctl restart clickhouse-server
    # 查看服务状态
    systemctl status clickhouse-server -l
    1. 修改密码(修改目录后原密码貌似失效了)

      编辑文件:/etc/clickhouse-server/users.xml

      修改为:

      <users>
              <!-- If user name was not specified, 'default' user is used. -->
              <default>
                  <!-- See also the files in users.d directory where the password can be overridden.
      
                       Password could be specified in plaintext or in SHA256 (in hex format).
      
                       If you want to specify password in plaintext (not recommended), place it in 'password' element.
                       Example: <password>qwerty</password>.
                       Password could be empty.
      
                       If you want to specify SHA256, place it in 'password_sha256_hex' element.
                       Example: <password_sha256_hex>65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5</password_sha256_hex>
                       Restrictions of SHA256: impossibility to connect to ClickHouse using MySQL JS client (as of July 2019).
      
                       If you want to specify double SHA1, place it in 'password_double_sha1_hex' element.
                       Example: <password_double_sha1_hex>e395796d6546b1b65db9d665cd43f0e858dd4303</password_double_sha1_hex>
      
                       If you want to specify a previously defined LDAP server (see 'ldap_servers' in the main config) for authentication,
                        place its name in 'server' element inside 'ldap' element.
                       Example: <ldap><server>my_ldap_server</server></ldap>
      
                       If you want to authenticate the user via Kerberos (assuming Kerberos is enabled, see 'kerberos' in the main config),
                        place 'kerberos' element instead of 'password' (and similar) elements.
                       The name part of the canonical principal name of the initiator must match the user name for authentication to succeed.
                       You can also place 'realm' element inside 'kerberos' element to further restrict authentication to only those requests
                        whose initiator's realm matches it.
                       Example: <kerberos />
                       Example: <kerberos><realm>EXAMPLE.COM</realm></kerberos>
      
                       How to generate decent password:
                       Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
                       In first line will be password and in second - corresponding SHA256.
      
                       How to generate double SHA1:
                       Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
                       In first line will be password and in second - corresponding double SHA1.
                  -->
                  <password>123456</password>
      
                  <!-- List of networks with open access.
      
                       To open access from everywhere, specify:
                          <ip>::/0</ip>
      
                       To open access only from localhost, specify:
                          <ip>::1</ip>
                          <ip>127.0.0.1</ip>
      
                       Each element of list has one of the following forms:
                       <ip> IP-address or network mask. Examples: 213.180.204.3 or 10.0.0.1/8 or 10.0.0.1/255.255.255.0
                           2a02:6b8::3 or 2a02:6b8::3/64 or 2a02:6b8::3/ffff:ffff:ffff:ffff::.
                       <host> Hostname. Example: server01.yandex.ru.
                           To check access, DNS query is performed, and all received addresses compared to peer address.
                       <host_regexp> Regular expression for host names. Example, ^server\d\d-\d\d-\d\.yandex\.ru$
                           To check access, DNS PTR query is performed for peer address and then regexp is applied.
                           Then, for result of PTR query, another DNS query is performed and all received addresses compared to peer address.
                           Strongly recommended that regexp is ends with $
                       All results of DNS requests are cached till server restart.
                  -->
                  <networks>
                      <ip>::/0</ip>
                  </networks>
      
                  <!-- Settings profile for user. -->
                  <profile>default</profile>
      
                  <!-- Quota for user. -->
                  <quota>default</quota>
      
                  <!-- User can create other users and grant rights to them. -->
                  <!-- <access_management>1</access_management> -->
              </default>
          </users>
      1. 重启服务

        systemctl restart clickhouse-server

    2.5 设置clickhouse-client的别名

    每次敲clickhouse-client太麻烦,可以设置一个简短的别名,比如ch:

    # 在~/.bash_profile中添加
    alias ch='clickhouse-client'
    
    source ~/.bash_profile

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!