Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------------

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions tasks/configure/sys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions templates/clickhousekeeper-servers.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
{{ ansible_managed | comment('xml') }}
<clickhouse>
<keeper_server>
<tcp_port>{{ clickhouse_keeper_port }}</tcp_port>
<server_id>{{ clickhouse_keeper_id }}</server_id>
<log_storage_path>{{ clickhouse_path_chk_log }}</log_storage_path>
<snapshot_storage_path>{{ clickhouse_path_chk_snap }}</snapshot_storage_path>

<raft_configuration>
{% for server in clickhousekeeper_nodes %}
<server>
{% for key, value in server.items() %}
<{{ key }}>{{ value }}</{{ key }}>
{% endfor %}
</server>
{% endfor %}
</raft_configuration>
</keeper_server>
</clickhouse>
12 changes: 12 additions & 0 deletions templates/zookeeper-config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
{{ ansible_managed | comment('xml') }}
<clickhouse>
<zookeeper>
{% for server in clickhousekeeper_nodes %}
<node index="{{ server.id }}">
<host>{{ server.hostname }}</host>
<port>{{ clickhouse_keeper_port }}</port>
</node>
{% endfor %}
</zookeeper>
</clickhouse>
2 changes: 1 addition & 1 deletion templates/zookeeper-servers.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
</node>
{% endfor %}
</zookeeper>
</clickhouse>
</clickhouse>
7 changes: 5 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'