Database Guide

    Deploying Valkey on RamNode VPS

    Valkey is a high-performance, open-source key-value data store that emerged as a Redis fork, offering excellent compatibility while maintaining independence from Redis' licensing changes. Combined with RamNode's reliable VPS hosting, you can deploy a powerful caching and data storage solution in minutes.

    Ubuntu 22.04 LTS
    Valkey 7.2+
    ⏱️ 10-15 minutes

    Why Choose Valkey and RamNode?

    Valkey Benefits:

    • • Lightning-fast performance and Redis compatibility
    • • Truly open-source under BSD license
    • • Perfect for caching and session storage
    • • Real-time analytics and message queuing

    RamNode Advantages:

    • • High-performance SSD VPS instances
    • • Excellent network connectivity
    • • Competitive pricing for databases
    • • Reliable infrastructure for production workloads

    Prerequisites

    Before starting, ensure you have:

    Server Requirements

    • • RamNode VPS (Ubuntu 22.04 LTS recommended)
    • • SSH access to your server
    • • Sudo privileges on your VPS
    • • At least 1GB RAM (2GB+ recommended)

    Knowledge Requirements

    • • Basic familiarity with Linux command line
    • • Understanding of key-value databases
    • • SSH connection skills
    2

    Initial Server Setup

    Connect to your RamNode VPS and prepare the system:

    Connect via SSH
    ssh root@your-server-ip
    Update System Packages
    apt update && apt upgrade -y
    Install Essential Tools
    apt install curl wget gnupg lsb-release software-properties-common -y

    💡 Tip: Replace "your-server-ip" with your actual RamNode VPS IP address.

    3

    Install Valkey

    Install Valkey using the official installation method:

    Add Valkey Repository
    curl -fsSL https://download.valkey.io/valkey-official.gpg | sudo gpg --dearmor -o /usr/share/keyrings/valkey-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/valkey-archive-keyring.gpg] https://download.valkey.io/deb stable main" | sudo tee /etc/apt/sources.list.d/valkey.list
    Update Package List and Install Valkey
    apt update apt install valkey -y
    Create Valkey User and Directories
    useradd --system --home /var/lib/valkey --shell /bin/false valkey
    mkdir -p /var/lib/valkey /var/log/valkey /etc/valkey
    chown valkey:valkey /var/lib/valkey /var/log/valkey
    chmod 750 /var/lib/valkey /var/log/valkey

    ✅ Valkey is now installed with proper user and directory setup.

    4

    Configure Valkey

    Create and configure the Valkey configuration file:

    Create Configuration File
    nano /etc/valkey/valkey.conf

    Add the following basic configuration:

    Basic Valkey Configuration
    # Network Configuration
    bind 127.0.0.1 ::1
    port 6379
    timeout 300
    
    # General Configuration
    daemonize yes
    pidfile /var/run/valkey/valkey-server.pid
    loglevel notice
    logfile /var/log/valkey/valkey-server.log
    
    # Data Persistence
    dir /var/lib/valkey
    dbfilename dump.rdb
    save 900 1
    save 300 10
    save 60 10000
    
    # Memory Management
    maxmemory 512mb
    maxmemory-policy allkeys-lru
    
    # Security
    protected-mode yes
    # requirepass yourpasswordhere
    
    # Performance
    tcp-keepalive 300
    tcp-backlog 511

    ⚠️ Important: Uncomment and set the "requirepass" directive with a strong password for production use.

    5

    Security Configuration

    Secure your Valkey installation:

    Set Strong Password
    # Generate a strong password
    openssl rand -base64 32
    
    # Add to configuration file
    echo "requirepass YOUR_STRONG_PASSWORD_HERE" >> /etc/valkey/valkey.conf
    Rename Dangerous Commands
    cat >> /etc/valkey/valkey.conf << EOF
    
    # Rename dangerous commands
    rename-command FLUSHALL FLUSHALL_RENAME_TO_SOMETHING_HARD_TO_GUESS
    rename-command FLUSHDB FLUSHDB_RENAME_TO_SOMETHING_HARD_TO_GUESS
    rename-command CONFIG CONFIG_RENAME_TO_SOMETHING_HARD_TO_GUESS
    rename-command DEBUG DEBUG_RENAME_TO_SOMETHING_HARD_TO_GUESS
    rename-command EVAL ""
    EOF
    Set Proper File Permissions
    chmod 640 /etc/valkey/valkey.conf
    chown root:valkey /etc/valkey/valkey.conf
    6

    Configure Firewall

    Configure UFW firewall for Valkey (if accessing remotely):

    Local Access Only (Recommended)
    # No firewall changes needed for local-only access systemctl status ufw
    Remote Access (Advanced Users)
    # Only if you need remote access
    ufw allow from trusted_ip_address to any port 6379
    ufw reload

    🔒 Security: Valkey should generally only accept local connections. Only allow remote access from trusted IP addresses.

    7

    Create Systemd Service

    Create and configure the systemd service:

    Create Service File
    nano /etc/systemd/system/valkey.service
    Systemd Service Configuration
    [Unit]
    Description=Valkey In-Memory Data Store
    After=network.target
    
    [Service]
    User=valkey
    Group=valkey
    ExecStart=/usr/bin/valkey-server /etc/valkey/valkey.conf
    ExecStop=/usr/bin/valkey-cli shutdown
    Restart=always
    RestartSec=3
    LimitNOFILE=65535
    
    [Install]
    WantedBy=multi-user.target
    Enable and Start Service
    systemctl daemon-reload
    systemctl enable valkey
    systemctl start valkey
    Check Service Status
    systemctl status valkey
    8

    Test Valkey Connection

    Verify that Valkey is running correctly:

    Test Basic Connection
    valkey-cli ping
    Expected Output
    PONG
    Test with Authentication (if password set)
    valkey-cli -a yourpassword ping
    Test Basic Operations
    valkey-cli -a yourpassword
    # In the Valkey CLI:
    SET test_key "Hello Valkey"
    GET test_key
    DEL test_key
    EXIT

    🎉 Success: Your Valkey server is now running and accepting connections!

    9

    Performance Tuning

    Optimize Valkey performance for your workload:

    System-level Optimizations
    # Increase system limits
    echo "valkey soft nofile 65535" >> /etc/security/limits.conf
    echo "valkey hard nofile 65535" >> /etc/security/limits.conf
    
    # Disable Transparent Huge Pages
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
    
    # Optimize kernel parameters
    sysctl -w vm.overcommit_memory=1
    echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
    Monitor Valkey Performance
    # Check memory usage
    valkey-cli -a yourpassword info memory
    
    # Monitor active connections
    valkey-cli -a yourpassword info clients
    
    # Check slow queries
    valkey-cli -a yourpassword slowlog get 10
    10

    Setup Monitoring

    Set up basic monitoring for your Valkey instance:

    Create Monitoring Script
    cat > /usr/local/bin/valkey-monitor.sh << 'EOF'
    #!/bin/bash
    VALKEY_CLI="valkey-cli -a yourpassword"
    LOG_FILE="/var/log/valkey/monitor.log"
    
    echo "$(date): Valkey Status Check" >> $LOG_FILE
    $VALKEY_CLI ping >> $LOG_FILE 2>&1
    $VALKEY_CLI info server | grep uptime >> $LOG_FILE
    $VALKEY_CLI info memory | grep used_memory_human >> $LOG_FILE
    echo "---" >> $LOG_FILE
    EOF
    
    chmod +x /usr/local/bin/valkey-monitor.sh
    Setup Cron Job for Monitoring
    # Add to crontab for regular monitoring
    echo "*/5 * * * * /usr/local/bin/valkey-monitor.sh" | crontab -
    11

    Backup Configuration

    Configure automated backups for your Valkey data:

    Create Backup Script
    cat > /usr/local/bin/valkey-backup.sh << 'EOF'
    #!/bin/bash
    BACKUP_DIR="/var/backups/valkey"
    DATE=$(date +%Y%m%d_%H%M%S)
    VALKEY_CLI="valkey-cli -a yourpassword"
    
    mkdir -p $BACKUP_DIR
    $VALKEY_CLI --rdb $BACKUP_DIR/valkey_backup_$DATE.rdb
    find $BACKUP_DIR -name "*.rdb" -mtime +7 -delete
    EOF
    
    chmod +x /usr/local/bin/valkey-backup.sh
    Schedule Daily Backups
    echo "0 2 * * * /usr/local/bin/valkey-backup.sh" | crontab -

    Troubleshooting

    Next Steps & Integration

    Application Integration

    Connect your applications to Valkey using these connection parameters:

    Host: 127.0.0.1
    Port: 6379
    Password: [your-configured-password]

    Popular Use Cases

    • Caching: Speed up web applications with data caching
    • Session Storage: Store user sessions for web applications
    • Message Queues: Implement pub/sub messaging systems
    • Real-time Analytics: Store and process streaming data