-
Notifications
You must be signed in to change notification settings - Fork 2
PMM-14170: Add Valkey setup and configuration scripts #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f723f28
PMM-14170: Add Valkey setup and configuration scripts
travagliad d96568d
PMM-14170 Fixes peter review
travagliad 757685a
PMM-14170 Fix peter comments
travagliad 19f6607
PMM-14170 Fix comments
travagliad 7f93196
PMM-14170 Fix loop for pmm client
travagliad ad93b34
PMM-14170 Variables setup
travagliad e7d79f8
PMM-14170 Fix OL-10 Password
travagliad b977b23
PMM-14170 fix loop
travagliad ab8d42a
test
travagliad a88c3d1
test loop
travagliad 1f6ade2
test loop
travagliad 978dd01
PMM-14170 Review of Peter
travagliad fc575ee
PMM-14170 Update cleanup.sh
travagliad 9717f22
PMM-14170 Review from Vasyl
travagliad dd27c33
PMM-14170 Fix random number
travagliad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| docker exec -it pmm-server pmm-admin remove valkey valkey-primary-svc || : | ||
| docker exec -it pmm-server pmm-admin remove valkey valkey-replica1-svc || : | ||
| docker exec -it pmm-server pmm-admin remove valkey valkey-replica2-svc || : | ||
| docker exec -it pmm-server pmm-admin remove valkey sentinel1-svc || : | ||
| docker exec -it pmm-server pmm-admin remove valkey sentinel2-svc || : | ||
| docker exec -it pmm-server pmm-admin remove valkey sentinel3-svc || : | ||
|
|
||
| docker rm -vf valkey-primary valkey-replica-1 valkey-replica-2 || : | ||
| docker rm -vf sentinel-1 sentinel-2 sentinel-3 || : | ||
|
|
||
| docker volume rm -f valkey-primary-data valkey-replica-1-data valkey-replica-2-data || : | ||
|
|
||
| rm -rf "$HOME/valkey" | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # sentinel.conf | ||
| bind 0.0.0.0 | ||
|
|
||
| port 26379 | ||
|
|
||
| # Monitor the master | ||
| sentinel monitor valkey-primary valkey-primary 6379 {{ sentinel_quorum }} | ||
| sentinel auth-user valkey-primary default | ||
| sentinel auth-pass valkey-primary "{{ valkey_password }}" | ||
| sentinel resolve-hostnames yes | ||
|
|
||
| # Failover timeouts | ||
| sentinel down-after-milliseconds valkey-primary 5000 | ||
| sentinel failover-timeout valkey-primary 10000 | ||
| sentinel parallel-syncs valkey-primary 1 | ||
|
|
||
| # Security | ||
| protected-mode no | ||
|
|
||
| # Logging | ||
| loglevel notice | ||
| logfile "" | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Basic Valkey configuration for primary | ||
| bind 0.0.0.0 | ||
| port 6379 | ||
|
|
||
| requirepass "{{ valkey_password }}" | ||
| masterauth "{{ valkey_password }}" | ||
|
|
||
| # Persistence | ||
| save 900 1 | ||
| save 300 10 | ||
| save 60 10000 | ||
|
|
||
| # Replication | ||
| replica-serve-stale-data yes | ||
| replica-read-only yes | ||
| repl-diskless-sync no | ||
| repl-diskless-sync-delay 5 | ||
|
|
||
| # Security | ||
| protected-mode no | ||
|
|
||
| # Logging | ||
| loglevel notice | ||
| logfile "" | ||
|
|
||
| # Memory management | ||
| maxmemory-policy allkeys-lru | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Basic Valkey configuration for replica | ||
| bind 0.0.0.0 | ||
| port 6379 | ||
|
|
||
| requirepass "{{ valkey_password }}" | ||
| masterauth "{{ valkey_password }}" | ||
|
|
||
| # Replication | ||
| replicaof valkey-primary 6379 | ||
| replica-serve-stale-data yes | ||
| replica-read-only yes | ||
| repl-diskless-sync no | ||
| repl-diskless-sync-delay 5 | ||
|
|
||
| # Persistence | ||
| save 900 1 | ||
| save 300 10 | ||
| save 60 10000 | ||
|
|
||
| # Security | ||
| protected-mode no | ||
|
|
||
| # Logging | ||
| loglevel notice | ||
| logfile "" | ||
|
|
||
| # Memory management | ||
| maxmemory-policy allkeys-lru | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| --- | ||
| - name: Deploy Valkey Cluster with Sentinel | ||
| hosts: localhost | ||
| gather_facts: false | ||
| vars: | ||
| valkey_version: "{{ lookup('env', 'VALKEY_VERSION') | default('7-alpine', true) }}" | ||
| valkey_image: "valkey/valkey:{{ valkey_version }}" | ||
| valkey_network_name: "pmm-qa" | ||
| valkey_password: "" | ||
| valkey_data_dir: "{{ lookup('env', 'HOME') }}/valkey/data" | ||
| valkey_config_dir: "{{ lookup('env', 'HOME') }}/valkey/config" | ||
| valkey_primary_port: 6379 | ||
| valkey_replica_count: 2 | ||
| valkey_replica_start_port: 6380 | ||
| sentinel_count: 3 | ||
| sentinel_start_port: 26379 | ||
| sentinel_quorum: 2 | ||
|
|
||
| pmm_server_name: "pmm-server" | ||
|
|
||
| tasks: | ||
| - name: Create Docker network | ||
| community.docker.docker_network: | ||
| name: "{{ valkey_network_name }}" | ||
| driver: bridge | ||
| state: present | ||
|
|
||
| - name: Create config directory | ||
| file: | ||
| path: "{{ valkey_config_dir }}" | ||
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: Create a config directory per Sentinel | ||
| file: | ||
| path: "{{ valkey_config_dir }}/sentinel-{{ item }}" | ||
| state: directory | ||
| mode: '0755' | ||
| loop: "{{ range(1, sentinel_count + 1) | list }}" | ||
|
|
||
| - name: Create data directory | ||
| file: | ||
| path: "{{ valkey_data_dir }}" | ||
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: Generate Valkey primary configuration | ||
| template: | ||
| src: valkey-primary.conf.j2 | ||
| dest: "{{ valkey_config_dir }}/valkey-primary.conf" | ||
| mode: '0644' | ||
|
|
||
| - name: Generate Valkey replica configurations | ||
| template: | ||
| src: valkey-replica.conf.j2 | ||
| dest: "{{ valkey_config_dir }}/valkey-replica-{{ item }}.conf" | ||
| mode: '0644' | ||
| loop: "{{ range(1, valkey_replica_count + 1) | list }}" | ||
|
|
||
| - name: Generate Sentinel configurations | ||
| template: | ||
| src: sentinel.conf.j2 | ||
| dest: "{{ valkey_config_dir }}/sentinel-{{ item }}/sentinel.conf" | ||
| mode: '0664' | ||
| loop: "{{ range(1, sentinel_count + 1) | list }}" | ||
|
|
||
| - name: Generate a password if not provided | ||
| when: valkey_password == "" | ||
| set_fact: | ||
| valkey_password: "{{ lookup('community.general.random_string', length=20, min_special=5, min_upper=2, override_special='!?()[]{}:;/|@#$%&^*<>=_+-') }}" | ||
|
|
||
| - name: Display generated Valkey password | ||
| debug: | ||
| msg: "Generated Valkey password: {{ valkey_password }}" | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Create Docker volume for primary data | ||
| community.docker.docker_volume: | ||
| name: "valkey-primary-data" | ||
| state: present | ||
|
|
||
| - name: Create Docker volumes for replica data | ||
| community.docker.docker_volume: | ||
| name: "valkey-replica-{{ item }}-data" | ||
| state: present | ||
| loop: "{{ range(1, valkey_replica_count + 1) | list }}" | ||
|
|
||
| - name: Start Valkey primary container | ||
| community.docker.docker_container: | ||
| name: "valkey-primary" | ||
| image: "{{ valkey_image }}" | ||
| state: started | ||
| restart_policy: unless-stopped | ||
| networks: | ||
| - name: "{{ valkey_network_name }}" | ||
| ports: | ||
| - "{{ valkey_primary_port }}:6379" | ||
| volumes: | ||
| - "valkey-primary-data:/data" | ||
| - "{{ valkey_config_dir }}/valkey-primary.conf:/usr/local/etc/valkey/valkey.conf:ro" | ||
| command: ["valkey-server", "/usr/local/etc/valkey/valkey.conf"] | ||
| healthcheck: | ||
| test: ["CMD", "valkey-cli", "-a", "{{ valkey_password }}", "ping"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| - name: Wait for the primary to be ready | ||
| wait_for: | ||
| host: localhost | ||
| port: "{{ valkey_primary_port }}" | ||
| timeout: 30 | ||
| delay: 1 | ||
|
|
||
| - name: Start Valkey replica containers | ||
| community.docker.docker_container: | ||
| name: "valkey-replica-{{ item }}" | ||
| image: "{{ valkey_image }}" | ||
| state: started | ||
| restart_policy: unless-stopped | ||
| networks: | ||
| - name: "{{ valkey_network_name }}" | ||
| ports: | ||
| - "{{ valkey_replica_start_port + item - 1 }}:6379" | ||
| volumes: | ||
| - "valkey-replica-{{ item }}-data:/data" | ||
| - "{{ valkey_config_dir }}/valkey-replica-{{ item }}.conf:/usr/local/etc/valkey/valkey.conf:ro" | ||
| command: ["valkey-server", "/usr/local/etc/valkey/valkey.conf"] | ||
| healthcheck: | ||
| test: ["CMD", "valkey-cli", "-a", "{{ valkey_password }}", "ping"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| loop: "{{ range(1, valkey_replica_count + 1) | list }}" | ||
|
|
||
| - name: Wait for replicas to be ready | ||
| wait_for: | ||
| host: localhost | ||
| port: "{{ valkey_replica_start_port + item - 1 }}" | ||
| timeout: 30 | ||
| delay: 1 | ||
| loop: "{{ range(1, valkey_replica_count + 1) | list }}" | ||
|
|
||
| - name: Start Sentinel containers | ||
| community.docker.docker_container: | ||
| name: "sentinel-{{ item }}" | ||
| image: "{{ valkey_image }}" | ||
| state: started | ||
| restart_policy: unless-stopped | ||
| networks: | ||
| - name: "{{ valkey_network_name }}" | ||
| ports: | ||
| - "{{ sentinel_start_port + item - 1 }}:26379" | ||
| volumes: | ||
| - "{{ valkey_config_dir }}/sentinel-{{ item }}:/usr/local/etc/valkey" | ||
| command: ["valkey-sentinel", "/usr/local/etc/valkey/sentinel.conf"] | ||
| healthcheck: | ||
| test: ["CMD", "valkey-cli", "-p", "{{ sentinel_start_port }}", "ping"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| loop: "{{ range(1, sentinel_count + 1) | list }}" | ||
|
|
||
| - name: Wait for Sentinels to be ready | ||
| wait_for: | ||
| host: localhost | ||
| port: "{{ sentinel_start_port + item - 1 }}" | ||
| timeout: 30 | ||
| delay: 1 | ||
| loop: "{{ range(1, sentinel_count + 1) | list }}" | ||
|
|
||
| - name: Verify cluster status | ||
| community.docker.docker_container_exec: | ||
| container: "valkey-primary" | ||
| command: valkey-cli -a "{{ valkey_password }}" info replication | ||
| register: cluster_status | ||
|
|
||
| - name: Display cluster status | ||
| debug: | ||
| msg: "{{ cluster_status.stdout_lines }}" | ||
|
|
||
| - name: Run Sentinel status command | ||
| community.docker.docker_container_exec: | ||
| container: "sentinel-1" | ||
| command: valkey-cli -p {{ sentinel_start_port }} sentinel masters | ||
| register: sentinel_status | ||
|
|
||
| - name: Display Sentinel status | ||
| debug: | ||
| msg: "{{ sentinel_status.stdout_lines }}" | ||
|
|
||
| - name: Add the primary to monitoring | ||
| community.docker.docker_container_exec: | ||
| container: "{{ pmm_server_name }}" | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| command: pmm-admin add valkey --cluster=valkey-cluster --replication-set=valkey-repl --environment=valkey-test --username=default --password="{{ valkey_password }}" --service-name=valkey-primary-svc --host=valkey-primary --port=6379 --custom-labels='role=primary' | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ignore_errors: yes | ||
|
|
||
| - name: Add the replicas to monitoring | ||
| community.docker.docker_container_exec: | ||
| container: "{{ pmm_server_name }}" | ||
| command: pmm-admin add valkey --cluster=valkey-cluster --replication-set=valkey-repl --environment=valkey-test --username=default --password="{{ valkey_password }}" --service-name=valkey-replica{{ item }}-svc --host=valkey-replica-{{ item }} --port=6379 --custom-labels='role=replica' | ||
| loop: "{{ range(1, valkey_replica_count + 1) | list }}" | ||
| ignore_errors: yes | ||
|
|
||
| - name: Add Sentinels to monitoring | ||
| community.docker.docker_container_exec: | ||
| container: "{{ pmm_server_name }}" | ||
| command: pmm-admin add valkey --cluster=valkey-cluster --environment=valkey-test --username=default --password="{{ valkey_password }}" --service-name=sentinel{{ item }}-svc --host=sentinel-{{ item }} --port={{ sentinel_start_port }} --custom-labels='role=sentinel' | ||
| loop: "{{ range(1, sentinel_count + 1) | list }}" | ||
| ignore_errors: yes | ||
travagliad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.