gNode

gNode ValKey Configuration Guide

Overview

gNode uses ValKey as its core data store for:

This document describes the production-ready, security-hardened ValKey configuration specifically designed for gNode.


Table of Contents

  1. Quick Start
  2. Security Features
  3. Performance Tuning
  4. Configuration Reference
  5. Monitoring & Maintenance
  6. Troubleshooting

Quick Start

Automated Setup (Recommended)

# 1. Navigate to gNode project root
cd /path/to/gNode

# 2. Run smart setup script
./scripts/setup-valkey-smart.sh

# 3. Verify installation
./scripts/valkey-cli-secure.sh PING
# Expected output: PONG

The automated setup will:

Manual Setup

# 1. Generate password
sudo mkdir -p /etc/geodineum/credentials
valkey-cli ACL GENPASS | sudo tee /etc/geodineum/credentials/valkey.password > /dev/null
sudo chmod 600 /etc/geodineum/credentials/valkey.password
sudo chown gnode:gnode /etc/geodineum/credentials/valkey.password

# 2. Copy and customize config
sudo cp daemon/config/valkey-gnode.conf /etc/valkey/valkey.conf

# 3. Update password in config
PASS=$(sudo cat /etc/geodineum/credentials/valkey.password)
sudo sed -i "s/requirepass CHANGE_ME_TO_STRONG_PASSWORD/requirepass $PASS/" /etc/valkey/valkey.conf

# 4. Setup directories
sudo mkdir -p /var/lib/valkey /var/log/valkey
sudo chown -R valkey:valkey /var/lib/valkey /var/log/valkey

# 5. Restart service
sudo systemctl restart valkey-gnode

Security Features

Network Isolation

bind 127.0.0.1 ::1
protected-mode yes
port 47445

What this means:

Strong Authentication

requirepass <32-byte-secure-password>

Password Security:

Command Restrictions

rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command CONFIG ""
rename-command SHUTDOWN SHUTDOWN_GNODE_SECURE

Protection against:

Data Privacy

hide-user-data-from-log yes

Performance Tuning

Multi-threaded I/O

io-threads 4
io-threads-do-reads yes

Tuning Guidelines:

Server Cores Recommended io-threads Expected Throughput
2-4 cores 2-3 threads ~500K ops/sec
4-8 cores 4 threads ~800K ops/sec
8-16 cores 6 threads ~1.2M ops/sec
16+ cores 8 threads ~1.5M+ ops/sec

Notes:

Memory Management

maxmemory 2gb
maxmemory-policy volatile-lru

gNode Memory Usage Estimates:

Services Topology Streams Formats Total
1K ~50MB ~100MB ~10MB ~200MB
10K ~500MB ~500MB ~50MB ~1GB
50K ~2.5GB ~1GB ~100MB ~4GB
100K ~5GB ~2GB ~200MB ~8GB

Eviction Strategy:

Persistence Strategy

# RDB: Point-in-time snapshots
save 900 1      # Save if 1+ changes in 15 minutes
save 300 10     # Save if 10+ changes in 5 minutes
save 60 10000   # Save if 10K+ changes in 1 minute

# AOF: Append-only file
appendonly yes
appendfsync everysec
aof-use-rdb-preamble yes

What persists:

Recovery:


Configuration Reference

Full Configuration Sections

1. Network & Security

2. Authentication

3. Data Persistence

4. Memory Management

5. Performance

6. Logging

7. Advanced


Monitoring & Maintenance

Health Checks

# Basic connectivity
./scripts/valkey-cli-secure.sh PING

# Server info
./scripts/valkey-cli-secure.sh INFO

# Memory usage
./scripts/valkey-cli-secure.sh INFO memory

# Replication status (if configured)
./scripts/valkey-cli-secure.sh INFO replication

# Client connections
./scripts/valkey-cli-secure.sh CLIENT LIST

# Slow queries
./scripts/valkey-cli-secure.sh SLOWLOG GET 10

Performance Metrics

# Real-time stats
./scripts/valkey-cli-secure.sh --stat

# Latency doctor
./scripts/valkey-cli-secure.sh --latency
./scripts/valkey-cli-secure.sh LATENCY DOCTOR

# Memory doctor
./scripts/valkey-cli-secure.sh MEMORY DOCTOR

# Benchmark (requires REDISCLI_AUTH for valkey-benchmark)
REDISCLI_AUTH="$(cat /etc/geodineum/credentials/valkey.password)" valkey-benchmark -p 47445 -t get,set -n 100000 -q

Monitoring Key Metrics

Metric Command Healthy Range Alert If
Memory usage INFO memoryused_memory_human <80% of maxmemory >90%
Connected clients INFO clientsconnected_clients <800 (of 1000 max) >900
Ops/sec INFO statsinstantaneous_ops_per_sec <50K Spikes/drops
Evicted keys INFO statsevicted_keys Growing slowly Rapid growth
Rejected connections INFO statsrejected_connections 0 >0
AOF last write status INFO persistenceaof_last_write_status ok error

Log Monitoring

# Follow logs in real-time
sudo journalctl -u valkey-gnode -f

# Recent errors
sudo journalctl -u valkey-gnode -p err -n 50

# Search for specific pattern
sudo journalctl -u valkey-gnode | grep -i "authentication"

# ValKey log file (if configured)
tail -f /var/log/valkey/gnode-valkey.log

Backup Strategy

# Manual backup
sudo systemctl stop valkey-gnode
sudo cp -a /var/lib/valkey /backup/valkey-$(date +%Y%m%d)
sudo systemctl start valkey-gnode

# Automated backup (add to cron)
#!/bin/bash
BACKUP_DIR="/backup/valkey"
DATE=$(date +%Y%m%d-%H%M%S)
REDISCLI_AUTH="$(cat /etc/geodineum/credentials/valkey.password)" valkey-cli -p 47445 BGSAVE
sleep 5  # Wait for BGSAVE to complete
cp /var/lib/valkey/gnode-dump.rdb "$BACKUP_DIR/dump-$DATE.rdb"
cp /var/lib/valkey/gnode-appendonly.aof "$BACKUP_DIR/aof-$DATE.aof"
find "$BACKUP_DIR" -name "*.rdb" -mtime +7 -delete  # Keep 7 days

Troubleshooting

Common Issues

1. "Connection refused"

Symptoms:

Error: Connection refused

Diagnosis:

# Check if ValKey is running
sudo systemctl status valkey-gnode

# Check port binding
sudo netstat -tlnp | grep 47445

# Check logs
sudo journalctl -u valkey-gnode -n 50

Solutions:


2. "Authentication required" / "NOAUTH"

Symptoms:

(error) NOAUTH Authentication required

Diagnosis:

# Check if password is set
sudo grep requirepass /etc/valkey/valkey.conf

# Verify password file
cat /etc/geodineum/credentials/valkey.password

Solutions:


3. Out of Memory

Symptoms:

(error) OOM command not allowed when used memory > 'maxmemory'

Diagnosis:

# Check memory usage
./scripts/valkey-cli-secure.sh INFO memory | grep used_memory_human
./scripts/valkey-cli-secure.sh INFO memory | grep maxmemory_human

# Check eviction stats
./scripts/valkey-cli-secure.sh INFO stats | grep evicted_keys

Solutions:


4. High Latency

Symptoms:

Diagnosis:

# Latency monitoring
./scripts/valkey-cli-secure.sh --latency
./scripts/valkey-cli-secure.sh LATENCY DOCTOR

# Slow queries
./scripts/valkey-cli-secure.sh SLOWLOG GET 10

# Check CPU usage
top -p $(pgrep valkey-server)

Solutions:


5. Service Won't Start

Symptoms:

valkey.service: Main process exited, code=exited, status=1/FAILURE

Diagnosis:

# Get detailed logs
sudo journalctl -u valkey-gnode -xe

# Try manual start to see error
sudo -u valkey /usr/local/bin/valkey-server /etc/valkey/valkey.conf

# Check config syntax
valkey-server /etc/valkey/valkey.conf --test-memory 0

Common Causes:


Advanced Topics

Password Rotation

# 1. Generate new password
NEW_PASS=$(valkey-cli ACL GENPASS)

# 2. Set new password (hot reload)
./scripts/valkey-cli-secure.sh CONFIG SET requirepass "$NEW_PASS"

# 3. Update password file
echo -n "$NEW_PASS" | sudo tee /etc/geodineum/credentials/valkey.password > /dev/null

# 4. Update config file permanently
sudo sed -i "s/^requirepass .*/requirepass $NEW_PASS/" /etc/valkey/valkey.conf

# 5. Restart gNode daemon with new password
sudo systemctl restart gnode-daemon

Multi-Instance Setup

To run multiple ValKey instances (e.g., production + development):

# Copy config
sudo cp /etc/valkey/valkey.conf /etc/valkey/valkey-dev.conf

# Modify port and directories
sudo sed -i 's/port 47445/port 6380/' /etc/valkey/valkey-dev.conf
sudo sed -i 's|dir /var/lib/valkey|dir /var/lib/valkey-dev|' /etc/valkey/valkey-dev.conf

# Create systemd service
sudo cp /etc/systemd/system/valkey.service /etc/systemd/system/valkey-dev.service
sudo sed -i 's|valkey.conf|valkey-dev.conf|' /etc/systemd/system/valkey-dev.service

# Start
sudo systemctl daemon-reload
sudo systemctl start valkey-gnode-dev

Replication Setup (High Availability)

# On replica server: /etc/valkey/valkey.conf
replicaof <master-ip> 47445
masterauth <master-password>
# Check replication status
./scripts/valkey-cli-secure.sh INFO replication

References


Quick Reference

Essential Commands

# Connection test
./scripts/valkey-cli-secure.sh PING

# Server info
./scripts/valkey-cli-secure.sh INFO

# Memory usage
./scripts/valkey-cli-secure.sh INFO memory | grep used_memory_human

# Client count
./scripts/valkey-cli-secure.sh CLIENT LIST | wc -l

# Stream lengths (gNode)
./scripts/valkey-cli-secure.sh XLEN "default:gnode:unified:default"
./scripts/valkey-cli-secure.sh XLEN "default:gnode:broadcast:global"

# Loaded functions (gNode)
./scripts/valkey-cli-secure.sh FUNCTION LIST

# Restart service
sudo systemctl restart valkey-gnode

# View logs
sudo journalctl -u valkey-gnode -f

Configuration Files

File Purpose Permissions
/etc/valkey/valkey.conf Main config 640 (valkey:valkey)
/etc/geodineum/credentials/valkey.password Authentication password 600 (gnode:gnode)
/var/lib/valkey/ Data directory 755 (valkey:valkey)
/var/log/valkey/ Log directory 755 (valkey:valkey)
/etc/geodineum/components/gnode-daemon/daemon.env Daemon tuning 640 (gnode:gnode)

Last Updated: 2025-10-24 gNode Version: All versions ValKey Version: 8.0+