AlexeySetevoi.clickhouse
ansible-clickhouse
シンプルなClickHouseサーバーのデプロイと管理のための役割です。 問題やプルリクエストは歓迎します。
役割の変数
F: 特定のバージョンを指定することができます(最新には * を使用)。ダウングレードはサポートされていないことに注意してください。
clickhouse_version: "19.11.3.11"
F: リスニングポートを管理できます。
clickhouse_http_port: 8123
clickhouse_tcp_port: 9000
clickhouse_interserver_http: 9009
F: デフォルトに加えてリスニングIPを追加できます。
clickhouse_listen_host_custom:
- "192.168.0.1"
F: TTLのクエリログを管理できます。
clickhouse_query_log_ttl: 'event_date + INTERVAL 7 DAY DELETE'
F: TTLのクエリスレッドログを管理できます。
clickhouse_query_thread_log_ttl: 'event_date + INTERVAL 7 DAY DELETE'
F: 直接IPを指定してすべてのIPv4およびIPv6アドレスをリッスンできます。
clickhouse_listen_host:
- "::"
F: カスタムプロファイルを作成できます。
clickhouse_profiles_custom:
my_custom_profile:
max_memory_usage: 10000000000
use_uncompressed_cache: 0
load_balancing: random
my_super_param: 9000
XMLに変換できる通常のk-vを許可します。
<profiles>
<!-- 設定のプロファイル -->
<!-- デフォルトプロファイル -->
<default>
<max_memory_usage>10000000000</max_memory_usage>
<load_balancing>random</load_balancing>
<use_uncompressed_cache>0</use_uncompressed_cache>
</default>
<readonly>
<readonly>1</readonly>
</readonly>
<!-- デフォルトプロファイル終了 -->
<!-- カスタムプロファイル -->
<my_custom_profile>
<max_memory_usage>10000000000</max_memory_usage>
<load_balancing>random</load_balancing>
<use_uncompressed_cache>0</use_uncompressed_cache>
<my_super_param>9000</my_super_param>
</my_custom_profile>
<!-- カスタムプロファイル終了 -->
</profiles>
F: カスタムユーザーを作成できます:
clickhouse_users_custom:
- { name: "testuser",
password_sha256_hex: "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2",
networks: "{{ clickhouse_networks_default }}",
profile: "default",
quota: "default",
dbs: [ testu1 ] ,
comment: "通常のパスワードを持つユーザー"}
- { name: "testuser2",
password: "testplpassword",
networks: "{{ clickhouse_networks_default }}",
profile: "default",
quota: "default",
dbs: [ testu2 ] ,
comment: "ハッシュパスワードを持つユーザー"}
- { name: "testuser3",
password: "testplpassword",
networks: { 192.168.0.0/24, 10.0.0.0/8 },
profile: "default",
quota: "default",
dbs: [ testu1,testu2,testu3 ] ,
comment: "複数のデータベースとカスタムネットワークを持つユーザー"}
- { name: "testuser4",
ldap_server: "example_ldap_server",
networks: { 192.168.0.0/24, 10.0.0.0/8 },
profile: "default",
quota: "default",
dbs: [ testu1,testu2,testu3 ] ,
comment: "LDAPサーバーを使用した外部認証"}
F: 独自のクォータを管理できます。
clickhouse_quotas_custom:
- { name: "my_custom_quota", intervals: "{{ clickhouse_quotas_intervals_default }}", comment: "デフォルトのクォータ - カウントのみ" }
クォータオブジェクトはシンプルな辞書です:
- { duration: 3600, queries: 0, errors: 0, result_rows: 0, read_rows: 0, execution_time: 0 }
F: 任意のデータベースを作成できます。 デフォルトのDB状態 - 存在する
clickhouse_dbs_custom:
- { name: testu1 }
- { name: testu2 }
- { name: testu3 }
- { name: testu4, state: absent }
- { name: testu5, state: present }
- { name: testu6, state: absent, cluster: testu6 }
- { name: testu7, state: present, cluster: testu7 }
- { name: testu8, state: absent, cluster: testu8, engine: Lazy(3600) }
- { name: testu9, state: present, cluster: testu9, engine: Lazy(3600) }
F: ODBCを介して辞書を作成できます。
clickhouse_dicts:
test1:
name: test_dict
odbc_source:
connection_string: "DSN=testdb"
source_table: "dict_source"
lifetime:
min: 300
max: 360
layout: hashed
structure:
key: "testIntKey"
attributes:
- { name: testAttrName, type: UInt32, null_value: 0 }
test2:
name: test_dict
odbc_source:
connection_string: "DSN=testdb"
source_table: "dict_source"
lifetime:
min: 300
max: 360
layout: complex_key_hashed
structure:
key:
attributes:
- { name: testAttrComplexName, type: String }
attributes:
- { name: testAttrName, type: String, null_value: "" }
F: ホストからClickHouseを削除するためのフラグ(デフォルトでは無効)。
clickhouse_remove: no
F: Kafkaの設定を管理できます。
# グローバル設定
clickhouse_kafka_config:
auto_offset_reset: smallest
debug: cgrp
# トピックレベルの設定
clickhouse_kafka_topics_config:
topic1:
retry_backoff_ms: 250
fetch_min_bytes: 100000
topic2:
retry_backoff_ms: 300
fetch_min_bytes: 120000
F: LDAPサーバーの設定を管理できます。
clickhouse_ldap_servers:
# ldapwhoami -H '<host>' -D '<bind_dn>' -w <password>でデバッグ
example_ldap_server:
host: "ldaps.example.com"
port: "636"
bind_dn: "EXAMPLENET\\{user_name}"
verification_cooldown: "300"
enable_tls: "yes"
tls_require_cert: "demand"
F: LDAP外部ユーザーディレクトリを管理できます。
# https://altinity.com/blog/integrating-clickhouse-with-ldap-part-twoのガイド
clickhouse_ldap_user_directories:
- server: "example_ldap_server"
roles:
- "ldap_user"
role_mapping:
base_dn: "ou=groups,dc=example,dc=com"
attribute: "CN"
scope: "subtree"
search_filter: "(&(objectClass=group)(member={user_dn}))"
prefix: "clickhouse_"
F: マージツリーの設定を管理できます。使用可能なパラメータのリストはMergeTreeのテーブル設定で確認できます。
clickhouse_merge_tree_config:
max_suspicious_broken_parts: 5
parts_to_throw_insert: 600
例プレイブック
変数をパラメータとして渡す方法の例を含めるのはユーザーにとって便利です:
- hosts: clickhouse_cluster
remote_user: root
vars:
clickhouse_users_custom:
- { name: "testuser",
password_sha256_hex: "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2",
networks: "{{ clickhouse_networks_default }}",
profile: "default",
quota: "default",
dbs: [ testu1 ] ,
comment: "通常のパスワードを持つユーザー"}
- { name: "testuser2",
password: "testplpassword",
networks: "{{ clickhouse_networks_default }}",
profile: "default",
quota: "default",
dbs: [ testu2 ] ,
comment: "ハッシュパスワードを持つユーザー"}
- { name: "testuser3",
password: "testplpassword",
networks: { 192.168.0.0/24, 10.0.0.0/8 },
profile: "default",
quota: "default",
dbs: [ testu1,testu2,testu3 ] ,
comment: "複数のデータベースとカスタムネットワークを持つユーザー"}
clickhouse_query_log_ttl: 'event_date + INTERVAL 7 DAY DELETE'
clickhouse_query_thread_log_ttl: 'event_date + INTERVAL 7 DAY DELETE'
clickhouse_dicts:
test1:
name: test_dict
odbc_source:
connection_string: "DSN=testdb"
source_table: "dict_source"
lifetime:
min: 300
max: 360
layout: hashed
structure:
key: "testIntKey"
attributes:
- { name: testAttrName, type: UInt32, null_value: 0 }
test2:
name: test_dict
odbc_source:
connection_string: "DSN=testdb"
source_table: "dict_source"
lifetime:
min: 300
max: 360
layout: complex_key_hashed
structure:
key:
attributes:
- { name: testAttrComplexName, type: String }
attributes:
- { name: testAttrName, type: String, null_value: "" }
clickhouse_dbs_custom:
- { name: testu1 }
- { name: testu2, state:present }
- { name: testu3, state:absent }
clickhouse_clusters:
your_cluster_name:
shard_1:
- { host: "db_host_1", port: 9000 }
- { host: "db_host_2", port: 9000 }
shard_2:
- { host: "db_host_3", port: 9000 }
- { host: "db_host_4", port: 9000 }
clickhouse_zookeeper_nodes:
- { host: "zoo_host_1", port: 2181 }
- { host: "zoo_host_2", port: 2181 }
- { host: "zoo_host_3", port: 2181 }
roles:
- ansible-clickhouse
マクロを生成するには、ファイルhost_vars\db_host_1.ymlに以下を記述します。
clickhouse_macros:
layer: 01
shard: "your_shard_name"
replica: "db_host_1"
クラスタのセキュリティを強化します。以下の設定を追加することでクラスタを構成できます。
- HTTPSポート
- TLS暗号化されたTCPポート
- データ複製用のHTTPS
- データ複製用の認証情報
- 分散クエリの秘密検証
- ZooKeeper ACL
- hosts: clickhouse_cluster
become: true
roles:
- ansible-clickhouse
vars:
# 通常のHTTPの代わりにHTTPSを使用
clickhouse_https_port: 8443
# ネイティブTCPプロトコルのTLS暗号化(`clickhouse-client --secure`が必要)
clickhouse_tcp_secure_port: 9440
# クラスタ内のノード間のTLS暗号化
clickhouse_interserver_https: 9010
# データ複製中にノードを認証するために使用される認証情報
clickhouse_interserver_http_credentials:
user: "internal"
password: "supersecretstring"
# 分散クエリのためにクラスタ内のノードを検証するための秘密
clickhouse_distributed_secret: "supersecretstring2"
# ClickHouseによって使用されるZookeeperパスを保護するためのパスワード
clickhouse_zookeeper_identity:
user: "zoo_user"
password: "secretzoostring"
# OpenSSL設定
clickhouse_ssl_server:
certificate_file: "/etc/clickhouse-server/server.crt"
private_key_file: "/etc/clickhouse-server/server.key"
dh_params_file: "/etc/clickhouse-server/dhparam.pem"
verification_mode: "none"
load_default_ca_file: "true"
cache_sessions: "true"
disable_protocols: "sslv2,sslv3"
prefer_server_ciphers: "true"
clickhouse_clusters:
your_cluster_name:
shard_1:
- host: "db_host_1"
port: 9440
secure: true
- host: "db_host_2"
port: 9440
secure: true
shard_2:
- host: "db_host_3"
port: 9440
secure: true
- host: "db_host_4"
port: 9440
secure: true
clickhouse_zookeeper_nodes:
- host: "zoo_host_1"
port: 2181
- host: "zoo_host_2"
port: 2181
- host: "zoo_host_3"
port: 2181
F: プレイブック、外部役割などから別々のステージを呼び出すことができます:
| タグ | アクション |
|---|---|
| install | パッケージのインストールのみ |
| config_sys | システム設定の構成(users.xmlとconfig.xmlのみ) |
| config_db | データベースの追加と削除のみ |
| config_sys | 辞書の再生成のみ |
| config | config_sys + config_db |
ライセンス
BSD
著者情報
ClickHouse by ClickHouse, Inc..
役割提供者: AlexeySetevoi.
寄稿者の皆様、ありがとうございます。
ansible-galaxy install AlexeySetevoi.clickhouse