bostjanbozic.redis

Redis

The Redis role allows you to set up different types of Redis systems:

  • Single node
  • A single master node with multiple replicas
  • Redis cluster

Most of this work is based on an existing role: DavidWittman.redis

To-Do List

  • Add Sentinel configuration
  • Add support for other operating systems

Installation

Run the following command to install the role:

ansible-galaxy install BostjanBozic.redis

Getting Started

This role creates different Redis setups and needs to be run with sudo privileges on the remote machines.

Single Redis Node

To deploy a single Redis node, use this role without changing any variables. Here’s an example of a playbook specifying the port for Redis:

---

- hosts: all
  become: yes
  roles:
    - BostjanBozic.redis
  vars:
    - redis_port: 6380

After you have your playbook and inventory files ready (for example, playbook.yml and inventory), you can deploy Redis using the command:

ansible-playbook -i inventory playbook.yml

Single Master Node with Replication

Redis supports a replication setup, where one master node can have one or more replicas. Below is an example that sets up a single Redis master with 2 replicas.

Inventory file:

[master]
redis-master-0.example.io

[replica]
redis-replica-0.example.io master_host=redis-master-0.example.io
redis-replica-1.example.io master_host=redis-master-0.example.io

Playbook file:

---

- hosts: master
  become: yes
  roles:
    - BostjanBozic.redis

- hosts: replica
  become: yes
  roles:
    - BostjanBozic.redis
  vars:
    - redis_replicaof: "{{ master_host }} {{ redis_port }}"

Note: Replication and cluster modes cannot be used at the same time. Do not use the redis_cluster_enabled variable when using the replicaof variable.

Cluster Mode

Redis can also run in cluster mode, distributing data across multiple master nodes, each optionally having replicas. The example below sets up 3 Redis master instances, each with 1 replica.

Inventory file:

[master]
redis-master-[0:2].example.io

[replica]
redis-replica-0.example.io master_host=redis-master-0.example.io
redis-replica-1.example.io master_host=redis-master-1.example.io
redis-replica-2.example.io master_host=redis-master-2.example.io

Playbook file:

---

- hosts: all
  become: yes
  roles:
    - BostjanBozic.redis
  vars:
    - redis_cluster_enabled: "yes"

Note: Replication and cluster modes cannot be used at the same time. Do not use the replicaof variable when using the redis_cluster_enabled variable.

Role Variables

Here are the default variables. For descriptions, please refer to the official documentation.

## Installation
redis_version: 5.0.4
redis_install_dir: /opt/redis
redis_download_url: "http://download.redis.io/releases/redis-{{ redis_version }}.tar.gz"

redis_user: redis
redis_group: redis

redis_nofile_limit: 16384
redis_oom_score_adjust: 0

redis_master_list: "{{ groups['master'] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | arraypermute( [':'] ) | arraypermute( [ redis_port ] ) }}"

## Redis Service
redis_as_service: true
redis_service_name: "redis_{{ redis_port }}"

## Redis Configuration
# Network options
redis_bind: 0.0.0.0
redis_protected_mode: "no"
redis_port: 6379
redis_tcp_backlog: 511
redis_timeout: 0
redis_tcp_keepalive: 300

# General configuration
redis_daemonize: "yes"
redis_supervised: "no"
redis_pidfile: /var/run/redis/{{ redis_port }}.pid
redis_loglevel: notice
redis_logfile: /var/log/redis_{{ redis_port }}.log
redis_databases: 16

# Snapshotting configuration
redis_save:
  - 900 1
  - 300 10
  - 60 10000
redis_stop_writes_on_bgsave_error: "yes"
redis_rdbcompression: "yes"
redis_rdbchecksum: "yes"
redis_dbfilename: dump.rdb
redis_dir: /var/lib/redis/{{ redis_port }}

# Replication configuration
redis_replicaof: false
redis_replica_serve_stale_data: "yes"
redis_replica_read_only: "yes"
redis_repl_diskless_sync: "no"
redis_repl_diskless_sync_delay: 5
redis_repl_disable_tcp_nodelay: "no"
redis_repl_backlog_size: false
redis_replica_priority: 100
redis_min_replicas_to_write: 0
redis_min_replicas_max_lag: 10

# Security configuration
redis_password: false

# Clients configuration
redis_maxclients: 10000

# Memory Management configuration
redis_maxmemory: false
redis_maxmemory_policy: noeviction

# Lazy Freeing configuration
redis_lazyfree_lazy_eviction: "no"
redis_lazyfree_lazy_expire: "no"
redis_lazyfree_lazy_server_del: "no"
redis_replica_lazy_flush: "no"

# Append Only Mode configuration
redis_appendonly: "no"
redis_appendfilename: "appendonly.aof"
redis_appendfsync: everysec
redis_no_appendfsync_on_rewrite: "no"
redis_auto_aof_rewrite_percentage: 100
redis_auto_aof_rewrite_min_size: 64mb
redis_aof_load_truncated: "yes"

# Lua Scripting configuration
redis_lua_time_limit: 5000

# Redis Cluster configuration
redis_cluster_enabled: "no"
redis_cluster_config_file: nodes-{{ redis_port }}.conf
redis_cluster_node_timeout: 15000

# Slow Log configuration
redis_slowlog_log_slower_than: 10000
redis_slowlog_max_len: 128

# Latency Monitor configuration
redis_latency_monitor_threshold: 0

# Event Notification configuration
redis_notify_keyspace_events: '""'

# Advanced Config configuration
redis_client_output_buffer_limit_normal: 0 0 0
redis_client_output_buffer_limit_replica: 256mb 64mb 60
redis_client_output_buffer_limit_pubsub: 32mb 8mb 60

License

This project is licensed under the MIT license.

Informazioni sul progetto

Ansible role to install Redis (standalone or cluster mode) and Redis Sentinel

Installa
ansible-galaxy install bostjanbozic.redis
Licenza
mit
Download
181
Proprietario