diff --git a/README.md b/README.md index 8cf552b..3bf93da 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ F: You can manage listen ports clickhouse_http_port: 8123 clickhouse_tcp_port: 9000 clickhouse_interserver_http: 9009 +clickhouse_keeper_port: 9181 ``` F: You can add listen ips on top of defaults: ```yaml @@ -225,6 +226,26 @@ clickhouse_merge_tree_config: parts_to_throw_insert: 600 ``` +F: You can configure ClickHouse Keeper, as an alternative to Zookeeper. For a list of available parameters, see [Configuring ClickHouse Keeper](https://clickhouse.com/docs/en/guides/sre/keeper/clickhouse-keeper). The items in the following variable will end up in the `raft_configuration`. Mutually exclusive with `clickhouse_zookeeper_nodes`. +```yaml +clickhouse_keeper_id: 1 # This machine's ID +clickhousekeeper_nodes: + - id: 1 + hostname: "host1" + port: 9234 # use Raft Port here + - id: 2 + hostname: "host2" + port: 9234 +``` + +The following vars for ClickHouse Keeper have sane defaults, but are adjustable: +```yaml +clickhouse_keeper_port: 9181 +clickhouse_path_chk: /var/lib/clickhouse/coordination +clickhouse_path_chk_log: /var/lib/clickhouse/coordination/log +clickhouse_path_chk_snap: /var/lib/clickhouse/coordination/snapshots +``` + Example Playbook ---------------- @@ -314,6 +335,31 @@ clickhouse_macros: replica: "db_host_1" ``` +To automate detection of `shard` macro value based on `clickhouse_clusters` dict +(given that `ansible_hostname` resolves to `db-host-?`): +```yaml +- hosts: clickhouse_cluster + remote_user: root + vars: + 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_macros: + shard: "{{ this_shard }}" + replica: "{{ ansible_hostname }}" + tasks: + - name: get shard of host + set_fact: + this_shard: "{{ item.0.key }}" + loop: "{{ clickhouse_clusters.your_cluster_name | dict2items | subelements('value') }}" + when: item.1.host == ansible_hostname +``` + Security harden the cluster. You can configure the cluster with extra settings which enables - HTTPS port @@ -386,7 +432,7 @@ Tag | Action install | Only installation of packages config_sys | Only configuration system configs(users.xml and config.xml) config_db | Only add&remove databases -config_sys / Only regenerate dicts +config_sys | Only regenerate dicts config | config_sys+config_db License diff --git a/defaults/main.yml b/defaults/main.yml index dab6945..fb67a00 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -35,6 +35,7 @@ clickhouse_listen_host: "{{ clickhouse_listen_host_default + clickhouse_listen_h clickhouse_http_port: 8123 clickhouse_tcp_port: 9000 +clickhouse_keeper_port: 9181 # clickhouse_https_port: 8443 # clickhouse_tcp_secure_port: 9440 diff --git a/tasks/configure/sys.yml b/tasks/configure/sys.yml index 7bc2735..78f21ad 100644 --- a/tasks/configure/sys.yml +++ b/tasks/configure/sys.yml @@ -11,6 +11,9 @@ - "{{ clickhouse_path_configdir }}" - "{{ clickhouse_path_tmp }}" - "{{ clickhouse_path_data }}" + - "{{ clickhouse_path_chk }}" + - "{{ clickhouse_path_chk_snap }}" + - "{{ clickhouse_path_chk_log }}" notify: restart-ch become: true @@ -84,6 +87,28 @@ become: true when: clickhouse_zookeeper_nodes is defined +- name: Config | Generate zookeeper config for all nodes + template: + src: zookeeper-config.j2 + dest: "{{ clickhouse_path_configdir }}/config.d/zookeeper-config.xml" + owner: "{{ clickhouse_user | default('clickhouse') }}" + group: "{{ clickhouse_group | default('clickhouse') }}" + mode: "u=rw,og=r" + notify: restart-ch + become: true + when: clickhousekeeper_nodes is defined + +- name: Config | Generate Clickhouse Keeper servers config + template: + src: clickhousekeeper-servers.j2 + dest: "{{ clickhouse_path_configdir }}/config.d/clickhousekeeper-servers.xml" + owner: "{{ clickhouse_user | default('clickhouse') }}" + group: "{{ clickhouse_group | default('clickhouse') }}" + mode: "u=rw,og=r" + notify: restart-ch + become: true + when: (clickhousekeeper_nodes is defined) and (clickhousekeeper_nodes | selectattr('id', '==', clickhouse_keeper_id)) + - name: Config | Fix interserver_http_port and intersever_https_port collision lineinfile: path: "{{ clickhouse_path_configdir }}/config.xml" diff --git a/templates/clickhousekeeper-servers.j2 b/templates/clickhousekeeper-servers.j2 new file mode 100644 index 0000000..211d36c --- /dev/null +++ b/templates/clickhousekeeper-servers.j2 @@ -0,0 +1,20 @@ + +{{ ansible_managed | comment('xml') }} + + + {{ clickhouse_keeper_port }} + {{ clickhouse_keeper_id }} + {{ clickhouse_path_chk_log }} + {{ clickhouse_path_chk_snap }} + + +{% for server in clickhousekeeper_nodes %} + +{% for key, value in server.items() %} + <{{ key }}>{{ value }} +{% endfor %} + +{% endfor %} + + + diff --git a/templates/zookeeper-config.j2 b/templates/zookeeper-config.j2 new file mode 100644 index 0000000..76db324 --- /dev/null +++ b/templates/zookeeper-config.j2 @@ -0,0 +1,12 @@ + +{{ ansible_managed | comment('xml') }} + + +{% for server in clickhousekeeper_nodes %} + + {{ server.hostname }} + {{ clickhouse_keeper_port }} + +{% endfor %} + + \ No newline at end of file diff --git a/templates/zookeeper-servers.j2 b/templates/zookeeper-servers.j2 index 2f2839c..babf441 100644 --- a/templates/zookeeper-servers.j2 +++ b/templates/zookeeper-servers.j2 @@ -13,4 +13,4 @@ {% endfor %} - + \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index e842bbf..4bed358 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -8,6 +8,9 @@ clickhouse_package: clickhouse_path_configdir: "/etc/clickhouse-server" clickhouse_path_logdir: "/var/log/clickhouse-server" -clickhouse_path_data: "{{ clickhouse_path_base }}/clickhouse/" -clickhouse_path_tmp: "{{ clickhouse_path_base }}/clickhouse/tmp/" +clickhouse_path_data: "{{ clickhouse_path_base }}/clickhouse" +clickhouse_path_tmp: "{{ clickhouse_path_base }}/clickhouse/tmp" +clickhouse_path_chk: "{{ clickhouse_path_data }}/coordination" +clickhouse_path_chk_snap: "{{ clickhouse_path_chk }}/snapshots" +clickhouse_path_chk_log: "{{ clickhouse_path_chk }}/log" clickhouse_service: 'clickhouse-server.service'