Skip to content
Chef cookbook for ClickHouse database
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_configs
attributes
libraries
recipes
templates/default
test/integration
.gitignore
.kitchen.yml
.travis.yml
Berksfile
CONTRIBUTING.md
Gemfile
LICENSE
README.md
TESTING.md
chefignore
metadata.rb

README.md

chef-clickhouse

Build Status Cookbook Version

Installs and manages ClickHouse server instances.

Requirements

  • Chef 12.5 or higher
  • Network accessible package repositories
  • Zookeeper (optional) only for distributed mode

Attributes

default['clickhouse']['user'] = 'clickhouse'
default['clickhouse']['group'] = 'clickhouse'

case node['platform']
when 'rhel', 'centos'
  default['clickhouse']['server']['version'] = '18.14.10'
when 'ubuntu', 'debian'
  default['clickhouse']['server']['version'] = '1.1.54343'
end

# Override config.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['configuration']['cookbook'] = 'clickhouse'

# Override users.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['users']['cookbook'] = 'clickhouse'

# Override zookeeper-servers.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['zookeeper']['cookbook'] = 'clickhouse'

# Override macros.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['macros']['cookbook'] = 'clickhouse'

# Override remote_servers.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['remote_servers']['cookbook'] = 'clickhouse'

# Override compression.xml Chef template resource `cookbook` location.
# Useful in wrapping cookbooks.
default['clickhouse']['server']['compression']['cookbook'] = 'clickhouse'

Also:

  • defaults/server.rb
  • defaults/users.rb
  • defaults/packages.rb

Usage

Place a dependency on the mysql cookbook in your cookbook's metadata.rb

depends 'clickhouse'

There are two ways to install ClickHouse.

  1. By including recipe
include_recipe 'clickhouse::server'
  1. By using Chef resources, note service_name here, it must be same per configured ClickHouse service instance.
clickhouse_server_service 'clickhouse server instance' do
  service_name 'clickhouse-server-test'
end

clickhouse_zookeeper_config 'clickhouse server zookeeper config' do
  service_name 'clickhouse-server-test'
  nodes [
    { host: '127.0.0.1', port: 2181 }
  ]
end

clickhouse_macros_config 'clickhouse server macros config' do
  service_name 'clickhouse-server-test'
  config <<-CONF
    <yandex>
      <macros>
      </macros>
    </yandex>
  CONF
end

clickhouse_compression_config 'clickhouse server compression config' do
  service_name 'clickhouse-server-test'
  config <<-CONF
  <yandex>
    <compression>
        <case>
          <min_part_size>10000000000</min_part_size>
          <min_part_size_ratio>0.01</min_part_size_ratio>
          <method>zstd</method>
        </case>
    </compression>
  </yandex>
  CONF
end

clickhouse_remote_servers_config 'clickhouse remote servers config' do
  service_name 'clickhouse-server-test'
  config <<-CONF
  <yandex>
    <remote_servers>
    </remote_servers>
  </yandex>
  CONF
end

Resources Overview

clickhouse_server_service

The clickhouse_server_service resource manages ClickHouse server installation.

The :create action handles package installation, support directories and other operating system level concerns. The internal configuration file contains just enough to get the service up and running.

Example
clickhouse_server_service 'custom instance' do
  version '1.1.54362'
end

Please note that when using notifies or subscribes, the resource to reference is clickhouse_server_service[custom instance], not service[custom instance].

Parameters
  • user - operating system user to run ClickHouse
  • group - operating system group to run ClickHouse
  • config_dir - configuration namespace directory, default is /etc/clickhouse-server/{custom instance}
  • version - specifies ClickHouse package version
  • package_release - package release, usually relevant for RHEL, e.g.: el6, el7
  • bin_dir - where to look for ClickHouse server binary
  • generic_bin - ClickHouse generic bin, default is clickhouse used for config.xml template validation
  • server_bin - ClickHouse server binary name, default is clickhouse-server
  • config - given configuration of config.xml, default is node['clickhouse']['server']['config']
  • users - given configuration of config.xml, users.xml include, default is node['clickhouse']['server']['users']
  • service_name - defaults to clickhouse-server
  • service_unit_after - systemd start unit after, default is 'network.target'
  • service_timeout_sec - systemd timeout sec, default is 5
  • service_restart - systemd restart, default 'on-failure'
  • config_template_cookbook - template cookbook source, defaults to node['clickhouse']['server']['configuration']['cookbook']
  • users_template_cookbook - template cookbook source, defaults to node['clickhouse']['server']['users']['cookbook']
  • config_template_source - template cookbook source, defaults to config.xml.erb
  • users_template_source - template cookbook source, defaults to users.xml.erb
Actions
  • :create - Configures everything from repository, package to service.
  • :delete - Removes everything but the package and directories.

clickhouse_macros_config

The clickhouse_macros_config resource manages ClickHouse server macros for ClickHouse server.

The :create action macros file installation.

Example
clickhouse_macros_config 'custom instance' do
  service_name 'clickhouse-server-your-service'
  config '<macros></macros>'
end

Please note that when using notifies or subscribes, the resource to reference is clickhouse_macros_config[custom instance], not service[custom instance].

Parameters
  • user - operating system user to run ClickHouse
  • group - operating system group to run ClickHouse
  • config_dir - configuration namespace directory, default is /etc/clickhouse-server/{custom instance}
  • service_name - defaults to clickhouse-server
  • config_name - defaults to node['clickhouse']['server']['config']['macros']['incl']
  • config - whatever is passed here is reflected in 'macros.xml'
  • template_cookbook - template cookbook source, defaults to node['clickhouse']['server']['macros']['cookbook']
  • template_source - template cookbook source, defaults to macros.xml.erb
Actions
  • :create - Installs macros.xml configuration file
  • :delete - Removes macros.xml configuration file

clickhouse_zookeeper_config

The clickhouse_zookeeper_config resource manages ClickHouse server Zookeeper servers for ClickHouse server instance.

The :create action zookeeper file installation.

Example
clickhouse_zookeeper_config 'custom instance' do
  service_name 'clickhouse-server-custom'
  nodes [
    { host: '127.0.0.1', port: 2181 }
  ]
end

Please note that when using notifies or subscribes, the resource to reference is clickhouse_zookeeper_config[custom instance], not service[custom instance].

Parameters
  • user - operating system user to run ClickHouse
  • group - operating system group to run ClickHouse
  • config_dir - configuration namespace directory, default is /etc/clickhouse-server/{custom instance}
  • service_name - defaults to clickhouse-server
  • config_name - defaults to node['clickhouse']['server']['config']['macros']['incl']
  • nodes - expects Array of Hash 'es, e.g.: [{index: 1, host: 'localhost', port: 2181}]
  • template_cookbook - template cookbook source, defaults to node['clickhouse']['server']['zookeeper']['cookbook']
  • template_source - template cookbook source, defaults to zookeeper.xml.erb
Actions
  • :create - Installs zookeeper-servers.xml configuration file
  • :delete - Removes zookeeper-servers.xml configuration file

clickhouse_remote_servers_config

The clickhouse_remote_servers_config resource manages ClickHouse server macros for ClickHouse server.

The :create action macros file installation.

Example
clickhouse_remote_servers_config 'custom instance' do
  service_name 'clickhouse-server-your-service'
  config '<remote_servers></remote_servers>'
end

Please note that when using notifies or subscribes, the resource to reference is clickhouse_remote_servers_config[custom instance], not service[custom instance].

Parameters
  • user - operating system user to run ClickHouse
  • group - operating system group to run ClickHouse
  • config_dir - configuration namespace directory, default is /etc/clickhouse-server/{custom instance}
  • service_name - defaults to clickhouse-server
  • config_name - defaults to node['clickhouse']['server']['config']['macros']['incl']
  • config - whatever is passed here is reflected in 'clickhouse_remote_servers.xml'
  • template_cookbook - template cookbook, defaults to node['clickhouse']['server']['remote_servers']['cookbook']
  • template_source - template cookbook source, defaults to remote_servers.xml.erb
Actions
  • :create - Installs clickhouse_remote_servers.xml configuration file
  • :delete - Removes clickhouse_remote_servers.xml configuration file

clickhouse_custom_config

The clickhouse_custom_config resource manages ClickHouse server custom xml or any other file configuration for ClickHouse server.

The :create action macros file installation.

Example
clickhouse_custom_config 'custom instance' do
  service_name 'clickhouse-server-your-service'
  config 'your value'
  config_name 'test-custom.xml'
end

Please note that when using notifies or subscribes, the resource to reference is clickhouse_custom_config[custom instance], not service[custom instance].

Parameters
  • user - operating system user to run ClickHouse
  • group - operating system group to run ClickHouse
  • config_dir - configuration namespace directory, default is /etc/clickhouse-server/{custom instance}
  • service_name - defaults to clickhouse-server
  • config_name - defaults to custom.xml
  • config - whatever is passed here is reflected in 'custom.xml' or whatever what is provided in config_name
  • template_cookbook - template cookbook, defaults to clickhouse
  • template_source - template cookbook source, defaults to custom.xml.erb
Actions
  • :create - Installs custom.xml configuration file
  • :delete - Removes custom.xml configuration file

Manual tuning

CPU frequency tunning

sudo echo 'performance' | tee /sys/devices/system/cpu/cpu\*/cpufreq/scaling_governor

Disable huge pages

echo 'never' | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

Production architecture

https://github.com/yandex/ClickHouse/issues/1272

License

MIT License

Copyright (c) 2018 Ernestas Poskus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You can’t perform that action at this time.