Database Guide

    Self-Hosted Couchbase Server

    Deploy Couchbase Server, a distributed NoSQL document database with N1QL, on RamNode VPS. Memory-first architecture for sub-millisecond latency.

    Ubuntu 22.04/24.04
    Couchbase 7.6
    ⏱️ 20-30 minutes

    Key Features of Couchbase

    Memory-first architecture for sub-millisecond latency
    Flexible JSON document model with ACID transactions
    N1QL query language for SQL-like querying
    Built-in full-text search and analytics
    Cross-datacenter replication for disaster recovery
    Integrated mobile sync via Couchbase Lite

    System Requirements

    ⚠️ Important: Couchbase is memory-intensive. It requires at least 4 GB of RAM for the data service alone. For clusters running multiple services, allocate additional memory accordingly.

    Resource Requirements

    WorkloadRAMCPUStorageRamNode Plan
    Development/Testing4 GB2 vCPUs40 GB SSDPremium 4GB
    Light Production8 GB4 vCPUs80 GB SSDPremium 8GB
    Standard Production16 GB6 vCPUs160 GB SSDPremium 16GB
    High Performance32 GB+8+ vCPUs320 GB+ SSDPremium 32GB+

    Network Ports

    PortServiceDescription
    8091Web ConsoleCluster management UI and REST API
    8093QueryN1QL query service
    8094SearchFull-text search service
    11210DataClient data operations (memcached)
    18091-18096SSL ServicesEncrypted versions of services

    Development

    • • 4GB RAM, 2 vCPU
    • • 40GB SSD storage
    • • Single-node setup

    Production

    • • 8GB+ RAM, 4+ vCPU
    • • 80GB+ SSD storage
    • • Multi-node cluster
    2

    Installation

    Update System Packages
    sudo apt update && sudo apt upgrade -y
    Install Dependencies
    sudo apt install -y wget curl apt-transport-https gnupg2

    Download and Install Couchbase Server

    Download the latest Couchbase Server package (Community Edition 7.6):

    Download and Install Couchbase
    # Download Couchbase Server
    wget https://packages.couchbase.com/releases/7.6.0/couchbase-server-community_7.6.0-linux_amd64.deb
    
    # Install the package
    sudo dpkg -i couchbase-server-community_7.6.0-linux_amd64.deb
    
    # Fix any dependency issues
    sudo apt --fix-broken install -y

    💡 Tip: For Enterprise Edition, replace 'community' with 'enterprise' in the download URL. Enterprise Edition requires a valid license.

    Verify Installation
    # Check service status
    sudo systemctl status couchbase-server
    
    # Enable Couchbase to start on boot
    sudo systemctl enable couchbase-server
    
    # Start if not running
    sudo systemctl start couchbase-server
    3

    Initial Configuration

    Web Console Setup

    Access the Couchbase Web Console at:

    Web Console URL
    http://YOUR_SERVER_IP:8091

    Click 'Setup New Cluster' and configure:

    • Cluster Name: A descriptive name (e.g., 'ramnode-production')
    • Admin Username: Strong username (avoid 'admin')
    • Admin Password: Complex password with 12+ characters

    Service Memory Allocation (8 GB VPS)

    ServiceMemoryPurpose
    Data Service4096 MBDocument storage and retrieval
    Index Service1024 MBSecondary index management
    Search Service512 MBFull-text search operations
    Query Service512 MBN1QL query execution
    Analytics512 MBReal-time analytics
    OS/System~1200 MBReserved for system

    Command-Line Configuration

    For automation, use the CLI to initialize the cluster:

    Initialize Cluster via CLI
    /opt/couchbase/bin/couchbase-cli cluster-init \
      --cluster localhost \
      --cluster-username admin \
      --cluster-password YOUR_SECURE_PASSWORD \
      --cluster-name ramnode-cluster \
      --cluster-ramsize 4096 \
      --cluster-index-ramsize 1024 \
      --cluster-fts-ramsize 512 \
      --cluster-eventing-ramsize 256 \
      --cluster-analytics-ramsize 512 \
      --services data,index,query,search
    Create a Bucket
    /opt/couchbase/bin/couchbase-cli bucket-create \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --bucket myapp \
      --bucket-type couchbase \
      --bucket-ramsize 1024 \
      --bucket-replica 1 \
      --enable-flush 0
    Create Application User
    /opt/couchbase/bin/couchbase-cli user-manage \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --set \
      --rbac-username appuser \
      --rbac-password APP_USER_PASSWORD \
      --rbac-name "Application User" \
      --roles bucket_full_access[myapp] \
      --auth-domain local
    4

    Security Hardening

    Firewall Configuration

    Configure UFW Firewall
    # Enable UFW if not already enabled
    sudo ufw enable
    
    # Allow SSH
    sudo ufw allow 22/tcp
    
    # Allow Couchbase Web Console (restrict to your IP)
    sudo ufw allow from YOUR_IP_ADDRESS to any port 8091
    
    # Allow Couchbase services from application servers
    sudo ufw allow from APP_SERVER_IP to any port 11210
    sudo ufw allow from APP_SERVER_IP to any port 8093
    
    # For cluster nodes (internal network only)
    sudo ufw allow from 10.0.0.0/8 to any port 8091:8096
    sudo ufw allow from 10.0.0.0/8 to any port 11210
    
    # Verify rules
    sudo ufw status verbose

    Enable TLS/SSL

    Generate Self-Signed Certificate
    # Generate self-signed certificate (for testing)
    openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
      -keyout /opt/couchbase/var/lib/couchbase/inbox/pkey.key \
      -out /opt/couchbase/var/lib/couchbase/inbox/chain.pem \
      -subj "/CN=couchbase.yourdomain.com"
    
    # Set proper permissions
    sudo chown couchbase:couchbase /opt/couchbase/var/lib/couchbase/inbox/*
    sudo chmod 600 /opt/couchbase/var/lib/couchbase/inbox/pkey.key
    
    # Reload certificates
    /opt/couchbase/bin/couchbase-cli ssl-manage \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --reload-cert /opt/couchbase/var/lib/couchbase/inbox

    💡 Production Tip: Use certificates from a trusted Certificate Authority. Let's Encrypt certificates work well with Couchbase.

    Enable Audit Logging

    Configure Audit Logging
    /opt/couchbase/bin/couchbase-cli setting-audit \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --set \
      --audit-enabled 1 \
      --audit-log-path /opt/couchbase/var/lib/couchbase/logs \
      --audit-log-rotate-interval 86400
    5

    Multi-Node Cluster Setup

    For high availability and increased performance, deploy Couchbase across multiple VPS nodes.

    Add Nodes to Cluster
    # From the primary node, add a new server
    /opt/couchbase/bin/couchbase-cli server-add \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --server-add NODE2_IP:8091 \
      --server-add-username admin \
      --server-add-password YOUR_SECURE_PASSWORD \
      --services data,index,query
    Rebalance the Cluster
    /opt/couchbase/bin/couchbase-cli rebalance \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD

    Node Placement Strategy

    NodeServicesRAM Allocation
    Node 1 (Primary)Data, QueryData: 6GB, Query: 1GB
    Node 2Data, IndexData: 5GB, Index: 2GB
    Node 3Data, Search, AnalyticsData: 4GB, Search: 1GB, Analytics: 2GB
    6

    Backup and Recovery

    Create Backup Repository
    # Create backup repository
    /opt/couchbase/bin/cbbackupmgr config \
      --archive /backup/couchbase \
      --repo couchbase-backup
    
    # Perform a full backup
    /opt/couchbase/bin/cbbackupmgr backup \
      --archive /backup/couchbase \
      --repo couchbase-backup \
      --cluster couchbase://localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD

    Automated Backup Script

    /opt/scripts/couchbase-backup.sh
    #!/bin/bash
    BACKUP_DIR="/backup/couchbase"
    REPO_NAME="daily-backup"
    CB_HOST="localhost"
    CB_USER="admin"
    CB_PASS="YOUR_SECURE_PASSWORD"
    DATE=$(date +%Y%m%d_%H%M%S)
    LOG_FILE="/var/log/couchbase-backup.log"
    
    echo "[$DATE] Starting backup..." >> $LOG_FILE
    
    /opt/couchbase/bin/cbbackupmgr backup \
      --archive $BACKUP_DIR \
      --repo $REPO_NAME \
      --cluster couchbase://$CB_HOST \
      --username $CB_USER \
      --password $CB_PASS >> $LOG_FILE 2>&1
    
    if [ $? -eq 0 ]; then
      echo "[$DATE] Backup completed successfully" >> $LOG_FILE
    else
      echo "[$DATE] Backup failed!" >> $LOG_FILE
    fi
    
    # Remove backups older than 7 days
    find $BACKUP_DIR -type d -mtime +7 -exec rm -rf {} \; 2>/dev/null
    Schedule Daily Backup (2 AM)
    sudo crontab -e
    
    # Add this line:
    0 2 * * * /opt/scripts/couchbase-backup.sh
    Restore from Backup
    /opt/couchbase/bin/cbbackupmgr restore \
      --archive /backup/couchbase \
      --repo couchbase-backup \
      --cluster couchbase://localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --start oldest \
      --end latest
    7

    Monitoring and Maintenance

    Key Metrics to Monitor

    • Operations per second (ops/sec)
    • RAM and disk usage percentage
    • Cache miss ratio
    • Replication queue length
    • Query service response times

    Prometheus Integration

    Prometheus Scrape Configuration
    # Couchbase exposes Prometheus metrics at:
    # http://localhost:8091/_prometheus
    
    scrape_configs:
      - job_name: 'couchbase'
        static_configs:
          - targets: ['localhost:8091']
        basic_auth:
          username: admin
          password: YOUR_SECURE_PASSWORD
        metrics_path: /_prometheus

    Log Files

    Located at /opt/couchbase/var/lib/couchbase/logs/

    Log FileDescription
    couchbase.logMain server log
    error.logError messages
    audit.logSecurity audit events
    query.logN1QL query service logs
    Configure Log Rotation
    /opt/couchbase/bin/couchbase-cli setting-log \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --log-rotation-size 50 \
      --log-rotation-period 7
    8

    Troubleshooting

    Service Won't Start

    Check Service Status and Logs
    # Check service status
    sudo systemctl status couchbase-server
    
    # View logs
    sudo journalctl -u couchbase-server -n 100
    
    # Verify available memory
    free -h

    High Memory Usage

    Adjust Memory Quotas
    /opt/couchbase/bin/couchbase-cli setting-cluster \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD \
      --cluster-ramsize 3072

    Cluster Node Unreachable

    Test Connectivity
    # Test connectivity
    nc -zv NODE_IP 8091
    nc -zv NODE_IP 11210
    
    # Check cluster status
    /opt/couchbase/bin/couchbase-cli server-list \
      --cluster localhost \
      --username admin \
      --password YOUR_SECURE_PASSWORD

    Useful Commands Reference

    CommandPurpose
    couchbase-cli cluster-infoDisplay cluster information
    couchbase-cli server-listList all cluster nodes
    couchbase-cli bucket-listList all buckets
    couchbase-cli failoverFailover a node
    couchbase-cli recoveryRecover a failed node
    couchbase-cli rebalanceRebalance cluster data

    Deployment Complete!

    You've successfully deployed Couchbase Server on your RamNode VPS. This setup provides a solid foundation for building high-performance applications with flexible JSON data modeling and powerful N1QL querying.

    Additional Resources