Automate the Installation of Redis Server Using CloudRay

Redis deployments require proper configuration of network binding, memory management, and authentication to prevent unauthorised access. This guide demonstrates how to automate Redis Server installation with CloudRay. This automation with CloudRay would implement secure password authentication, proper daemon configuration, network binding restrictions, and service lifecycle management.

Contents

Adding Servers to CloudRay

Before beginning Redis deployment, ensure your target servers are connected to CloudRay. Follow the servers docs to add and manage servers if not already configure

NOTE

These scripts target Ubuntu/Debian systems. For RHEL-based distributions, replace apt commands with appropriate yum or dnf equivalents. The Redis configuration file path may differ on non-Debian systems.

Create the Automation Script

Two Bash scripts are required for complete Redis deployment:

  1. Redis Installation Script:: This script handles package installation and base configuration
  2. Redis Configuration Script: This script implement security settings and authentication

Let’s begin with the Redis installation script.

Redis Installation Script

This script performs the initial Redis Server deployment with production-ready defaults. Follow these steps to create the script:

Screenshot of adding a new install script
  1. Go to Scripts in your CloudRay project
  2. Click New Script
  3. Name: Redis Installation Script. You can give it any name of your choice
  4. Copy this code:
#!/bin/bash

# Exit on any error
set -e

# Update package list
sudo apt update

# Install Redis server
sudo apt install redis-server -y

# Display installed Redis version
redis-server --version

# Modify redis.conf:
# - Uncomment 'bind 127.0.0.1 -::1'
# - Ensure daemonize is 'yes'
sudo sed -i 's/^# *bind 127.0.0.1 ::1/bind 127.0.0.1 ::1/' /etc/redis/redis.conf
sudo sed -i 's/^# *daemonize no/daemonize yes/' /etc/redis/redis.conf

# Enable Redis service to start on boot
sudo systemctl enable redis-server.service

# Start Redis service
sudo systemctl start redis

# Check Redis service status
sudo systemctl status redis --no-pager

Here is a breakdown of what each command in the Redis Installation Script does:

  • Installs Redis from system packages
  • Configures loopback interface binding
  • Enables daemon mode for service management
  • Verifies successful service start

Redis Configuration Script

This script implements security controls and tests basic functionality.

Screenshot of securing cockpit
  1. Go to Scripts > New Script
  2. Name: Redis Configuration Script
  3. Add code:
#!/bin/bash

# Exit on any error
set -e

# Modify redis.conf:
# - Uncomment and set requirepass to the strong password
sudo sed -i "s/^# *requirepass .*/requirepass {{redis_password}}/" /etc/redis/redis.conf

# Restart Redis service to apply changes
sudo systemctl restart redis

# Connect to Redis CLI and test authentication & set/get commands
redis-cli <<EOF
auth {{redis_password}}
select 1
set testkey "Hello from CloudRay!"
get testkey
EOF

echo "✅ Redis authentication and test command successful."

This is what the Secure Cockpit Script does:

  • Enables password authentication
  • Restarts service to apply security settings
  • Validates configuration with test operations

Create a Variable Group

The configuration script requires a password variable. Create a variable group to store this securely. CloudRay processes all scripts as Liquid templates. This allows you to use variables dynamically across different servers.

Screenshot of adding a new variable group

To ensure that these values are automatically substituted when the script runs, follow these steps to create a variable Group:

  1. Navigate to Variable Group under Scripts
  2. Create a new group named Redis Deployment Variables
  3. Add the following variables:
  • redis_password: The password for Redis authentication

Since the variables are setup, proceed to run the scripts with CloudRay.

Running the Scripts to Install Redis with CloudRay

The Redis deployment consists of two dependent scripts that should execute sequentially. CloudRay’s Script Playlists provide an efficient way to orchestrate this workflow.

Here are the steps to follow:

  1. Navigate to “Script Playlists”: Click on the Scripts tab in the CloudRay interface
Locate the script playlist in CloudRay interface
  1. Click “Add Script Playlist”: This initiates the creation of a new playlist
  2. Provide a Name: Give your playlist a unique name (For example “Automate Redis Server Installation”)
  3. Add Scripts in Order: Select and add the scripts sequentially
Locate the script playlist in CloudRay interface
  1. Save the Playlist: Click “create playlist” to store your new playlist.

Once your script playlist is created, proceed with execution:

  1. Navigate to Runlogs: In your CloudRay project, go to the Runlogs section in the top menu.
  2. Create a New Runlog: Click on New Runlog.
  3. Configure the Runlog: Provide the necessary details:
Screenshot of creating a new runlog
  • Server: Select the server where Redis will be installed
  • Script Playlist: Choose the playlist you created (For example “Automate Redis Server Installation”)
  • Variable Group: Select the variable group you set up earlier
  1. Execute the Script: Click on Run Now to start the execution
Screenshot of the result of all the script from the script playlist

After successful script execution to install Redis Server. Validate the Redis installation by clicking the Runlog of the Configure Redis Script

Screenshot of the result of all the script from the script playlist

As seen in the ouput, Redis is successfully working correctly.

IMPORTANT

For production environments, we recommend running the installation playlist on multi nodes, configuring Redis Sentinel for higher availability, setting up monitoring.

For other database deployments using CloudRay check out our guides on: