Dragonfly Cloud announces new enterprise security features - learn more

Valkey Installation + Setup Guide

August 15, 2024

Valkey Installation + Setup Guide

Valkey is a high-performance, open-source key-value store designed as an alternative to Redis, offering advanced features like clustering, enhanced observability, and multi-threading. Ideal for both small-scale applications and large distributed systems, Valkey is engineered to handle high-throughput workloads, providing an efficient and scalable solution for fast data access. This comprehensive guide will walk you through the installation and setup of Valkey, including integration with Kubernetes, Docker, and Valkey Operators, covering everything from basic configuration to advanced deployment scenarios.

Prerequisites

Before starting, ensure you have the following:

  • A compatible operating system (Linux, macOS, or BSD).
  • Basic knowledge of command-line operations.
  • Access to a server or virtual machine for installation.
  • Docker installed if you plan to use Docker for deployment.
  • A Kubernetes cluster set up if you plan to use Kubernetes for managing Valkey.

Installation Guide

Installing Valkey on Linux

  1. Clone the Valkey Repository

    git clone https://github.com/valkey-io/valkey.git
    cd valkey
    
  2. Build Valkey from Source

    make
    
  3. Run the Valkey Server

    ./src/valkey-server
    

Installing Valkey on macOS

  1. Clone the Repository

    git clone https://github.com/valkey-io/valkey.git
    cd valkey
    
  2. Build Valkey

    make
    
  3. Start the Valkey Server

    ./src/valkey-server
    

Basic Configuration

After installation, you can configure Valkey by editing the valkey.conf file. This file allows you to set parameters such as port numbers, memory limits, and security settings.

Editing the Configuration File

  1. Open the configuration file:

    nano /etc/valkey/valkey.conf
    
  2. Modify the necessary settings:

    • Port: Change the default port if required.
    • Memory: Set memory limits based on your server's capacity.
    • Security: Use requirepass to set a password for accessing Valkey.
  3. Restart the Valkey server to apply the changes.

Valkey Cluster Setup

To utilize Valkey in a distributed environment, you can set up a cluster. This ensures data redundancy and improved performance.

Step-by-Step Cluster Setup

  1. Start multiple Valkey instances on different nodes.
  2. Configure clustering by editing valkey.conf:
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    
  3. Join nodes to form a cluster:
    ./src/valkey-cli --cluster create <node1> <node2> <node3> --cluster-replicas 1
    
  4. Verify cluster status:
    ./src/valkey-cli --cluster check <node1>
    

Valkey Docker Integration

Docker provides a convenient way to deploy Valkey, especially in environments where consistency and portability are crucial.

Deploying Valkey with Docker

  1. Pull the Valkey Docker image:

    docker pull valkey/valkey
    
  2. Run Valkey in a Docker container:

    docker run -d --name valkey -p 6379:6379 valkey/valkey
    
  3. Persistent Storage: Use a Docker volume to persist data:

    docker run -d --name valkey -p 6379:6379 -v /mydata:/data valkey/valkey
    
  4. Scaling with Docker Compose: Create a docker-compose.yml file to manage multiple Valkey instances:

    version: '3'
    services:
    valkey:
    image: valkey/valkey
    ports: - "6379:6379"
    volumes: - /mydata:/data
    deploy:
    replicas: 3
    

    Deploy with:

    docker-compose up -d
    

Using Valkey with Kubernetes

Kubernetes is ideal for managing Valkey in a scalable, resilient environment. You can deploy Valkey using Helm charts or Kubernetes Operators for automated management.

Installing Valkey using Helm

  1. Add the Helm repository:

    helm repo add valkey https://charts.valkey.io
    
  2. Install Valkey:

    helm install my-valkey valkey/valkey
    
  3. Check the deployment:

    kubectl get pods,svc -n valkey
    

Managing Valkey with Kubernetes Operators

Valkey Operators allow you to automate the deployment and management of Valkey clusters in Kubernetes.

  1. Install the Operator:

    helm install valkey-operator valkey/valkey-operator
    
  2. Deploy a Valkey cluster: Create a valkey-cluster.yaml file:

    apiVersion: valkey.io/v1
    kind: ValkeyCluster
    metadata:
    name: my-valkey-cluster
    spec:
    replicas: 3
    

    Apply the configuration:

    kubectl apply -f valkey-cluster.yaml
    
  3. Monitor the deployment:

    kubectl get pods -n valkey
    

Monitoring and Management

To ensure Valkey is running optimally, you should regularly monitor its performance.

Tools for Monitoring

  • Valkey CLI: Use commands like info to get real-time data.
  • Prometheus and Grafana: Integrate for advanced monitoring and visualization.

Conclusion

Valkey offers a robust alternative to Redis, with features tailored for modern, scalable applications. Whether you are deploying Valkey using Docker or managing it with Kubernetes, this guide provides you with the necessary steps to get started efficiently. Ensure to monitor your Valkey instances regularly to maintain optimal performance and reliability.

For more detailed documentation and community support, explore the Valkey GitHub repository and official documentation.

Was this content helpful?

Stay up to date on all things Dragonfly

Join our community for unparalleled support and insights

Join

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost