Skip to content

Commit

Permalink
Add multiple redis per instance scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
aminst committed Mar 4, 2024
1 parent 21ad4ee commit 254a185
Show file tree
Hide file tree
Showing 49 changed files with 70 additions and 63,127 deletions.
26 changes: 18 additions & 8 deletions ansible/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,29 @@
delegate_to: "{{ item.deploy_host }}"
with_items: "{{ redis_endpoints.endpoints }}"

- name: Copy Redis config
ansible.builtin.copy:
src: "{{ experiment_path }}/redis.conf"
dest: "/etc/redis/redis.conf"
mode: '0666'
- name: Copy Redis Config
template:
src: templates/redis.conf.j2
dest: /etc/redis/redis-{{ item.id }}.conf
delegate_to: "{{ item.deploy_host }}"
with_items: "{{ redis_endpoints.endpoints }}"

- name: Create Redis systemd services
template:
src: templates/redis.service.j2
dest: "/lib/systemd/system/redis-{{ item.id }}.service"
delegate_to: "{{ item.deploy_host }}"
with_items: "{{ redis_endpoints.endpoints }}"

# - name: Stop previous Redis services
# ansible.builtin.shell:
# cmd: systemctl stop redis*

- name: Start Redis
ansible.builtin.systemd:
name: redis-server
state: restarted
daemon_reload: true
name: "redis-{{ item.id }}"
state: started # will cause reinitialization of the DB
# daemon_reload: true
delegate_to: "{{ item.deploy_host }}"
with_items: "{{ redis_endpoints.endpoints }}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected-mode no

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
port {{item.port}}

# TCP listen() backlog.
#
Expand Down Expand Up @@ -155,7 +155,7 @@ supervised no
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis/redis-server.pid
pidfile /var/run/redis/redis-server-{{ item.id }}.pid

# Specify the server verbosity level.
# This can be one of:
Expand All @@ -168,7 +168,7 @@ loglevel notice
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/log/redis/redis-server.log
logfile /var/log/redis/redis-server-{{ item.id }}.log

# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
Expand Down Expand Up @@ -215,9 +215,9 @@ always-show-logo yes
#
# save ""

save 900 1
save 300 10
save 60 10000
# save 900 1
# save 300 10
# save 60 10000

# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
Expand Down Expand Up @@ -250,7 +250,7 @@ rdbcompression yes
rdbchecksum yes

# The filename where to dump the DB
dbfilename dump.rdb
dbfilename dump-{{ item.id }}.rdb

# The working directory.
#
Expand Down
45 changes: 45 additions & 0 deletions ansible/templates/redis.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)

[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis-{{ item.id }}.conf
PIDFile=/run/redis/redis-server-{{ item.id }}.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755

UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redis

NoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX

# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis

[Install]
WantedBy=multi-user.target
Alias=redis-{{ item.id }}.service
Loading

0 comments on commit 254a185

Please sign in to comment.