Appearance
ETCD Setup Guide ​
Overview ​
ETCD is a distributed key-value store used by SingularityNET for payment channel management and service state storage. This guide covers setting up ETCD for your SingularityNET service deployment.
When to Use This Guide ​
For most users, the embedded ETCD (which runs automatically with the daemon) is sufficient. Use this guide only if you need:
- External ETCD access for multiple daemons
- High-availability production deployments
- Separate ETCD infrastructure
If you are using embedded ETCD, skip this guide and proceed to the Full Onboarding Guide.
Prerequisites ​
Before starting the ETCD setup:
- Ubuntu 18.04 or higher
- Sudo permissions for the user
- Open ports for ETCD communication (2379, 2380)
Important: If you plan to use domain-based certificates, your domain must be linked to your server's IP address BEFORE running the setup script. Add an A record in your domain's DNS settings pointing to your VPS IP.
Setup Options ​
Option 1: Single Node Docker Setup (Recommended for Development) ​
This is the simplest setup suitable for development and small-scale deployments.
Option 2: Multi-node Cluster (Production) ​
For high availability and production environments.
Single Node Docker Setup ​
Step 1: Download Installation Script ​
bash
# Download the automated setup script
wget https://raw.githubusercontent.com/singnet/platform-setup/main/docker-etcd-setup.sh
# Make it executable
chmod +x docker-etcd-setup.shStep 2: Configure Network Settings (Optional) ​
If hosting ETCD on a separate network or using a custom domain, modify the configuration:
- Open the
server.jsonfile after running the script - Add your domain to the hosts section:
json
{
"hosts": [
"${public_ip}",
"${private_ip}",
"your.domain.com", // Add your domain here
"127.0.0.1"
]
}Step 3: Run Installation Script ​
bash
# Execute the setup script
sudo bash docker-etcd-setup.shImportant Notes:
- The script will create a data folder in your current directory
- This folder contains your payment channel data - DO NOT DELETE IT
- Back up this folder regularly to prevent loss of funds
Step 4: Follow Script Prompts ​
The script will guide you through:
- Setting certificate validity period (recommended: 365 days or more)
- Configuring network interfaces
- Setting up SSL certificates
- Initializing the ETCD cluster
Step 5: Verify Installation ​
If successful, you'll see: ETCD INSTALLED SUCCESSFULLY
Check the container status:
bash
# Verify container is running
docker ps | grep etcd
# Check container logs
docker logs docker-etcd-node-1SSL Certificate Configuration ​
SSL certificates for your daemon should be generated AFTER the ETCD setup is complete. The recommended approach:
- First: Link domain to your server (A record in DNS)
- Second: Run ETCD setup script (handles ETCD-specific certificates)
- Third: Generate daemon SSL certificates using Certbot
Generate Domain Certificates for Daemon ​
After ETCD is running, generate SSL certificates for your daemon:
- Install Certbot:
bash
sudo apt update
sudo apt install certbot- Generate Certificates:
bash
sudo certbot certonly --standalone -d your-domain.comNote: Port 80 must be temporarily open for Certbot verification.
- Verify Certificates:
bash
sudo certbot certificatesOutput paths:
- Certificate:
/etc/letsencrypt/live/your-domain.com/fullchain.pem - Private Key:
/etc/letsencrypt/live/your-domain.com/privkey.pem
- Verify Auto-renewal:
bash
sudo systemctl show certbot.timerCertificate Parameters for Daemon ​
Use the Certbot-generated certificates in your daemon configuration:
json
{
"ssl_cert": "/etc/letsencrypt/live/your-domain.com/fullchain.pem",
"ssl_key": "/etc/letsencrypt/live/your-domain.com/privkey.pem"
}The ETCD client certificates (generated during ETCD setup) are separate and used for ETCD communication:
json
{
"payment_channel_cert_path": "/var/lib/etcd/cfssl/client.pem",
"payment_channel_ca_path": "/var/lib/etcd/cfssl/ca.pem",
"payment_channel_key_path": "/var/lib/etcd/cfssl/client-key.pem"
}ETCD Certificate Management ​
Initial Certificate Generation ​
Certificates are generated automatically during setup. For manual generation:
bash
# Generate CA certificate
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
# Generate server certificate
cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-profile=server \
server.json | cfssljson -bare server
# Generate peer certificate
cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-profile=peer \
member-1.json | cfssljson -bare member-1
# Generate client certificate
cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-profile=client \
client.json | cfssljson -bare clientCertificate Renewal ​
When ETCD certificates expire:
- Navigate to the certificate directory
- Run the renewal commands above
- Restart the ETCD container:
bash
docker restart docker-etcd-node-1Container Management ​
Common Docker Commands ​
bash
# Start container
docker start docker-etcd-node-1
# Stop container
docker stop docker-etcd-node-1
# Restart container
docker restart docker-etcd-node-1
# View logs
docker logs docker-etcd-node-1
# Follow logs in real-time
docker logs -f docker-etcd-node-1
# Check container status
docker inspect docker-etcd-node-1Troubleshooting ​
Container Won't Start ​
bash
# Check logs for errors
docker logs docker-etcd-node-1
# Common issues:
# - Port already in use
# - Certificate problems
# - Disk space issues
# - Permission problemsPort Conflicts ​
bash
# Check if ports are in use
netstat -tulpn | grep -E '2379|2380'
# Find process using port
lsof -i :2379Data Recovery ​
If container crashes:
- Stop the container
- Backup the data directory
- Check data integrity
- Restart with clean state if needed
Production Best Practices ​
High Availability Setup ​
For production, consider:
- Multi-node cluster (minimum 3 nodes)
- Regular backups of data directory
- Monitoring and alerting
- Automated certificate renewal
- Dedicated storage volume
Backup Strategy ​
bash
# Create backup
tar -czf etcd-backup-$(date +%Y%m%d).tar.gz /path/to/etcd/data
# Automated backup script
#!/bin/bash
BACKUP_DIR="/backup/etcd"
DATA_DIR="/var/lib/etcd"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
tar -czf $BACKUP_DIR/etcd-backup-$DATE.tar.gz $DATA_DIR
# Keep only last 30 days
find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -deleteMonitoring ​
Monitor these metrics:
- Container health status
- Disk usage
- Memory consumption
- Network latency
- Certificate expiration dates
Security Considerations ​
- Firewall Rules: Only allow necessary ports
- SSL/TLS: Always use encrypted connections
- Access Control: Limit client access
- Regular Updates: Keep Docker and ETCD updated
- Audit Logs: Enable and monitor access logs
Integration with SingularityNET ​
Daemon Configuration ​
Add ETCD endpoints to your daemon configuration:
json
{
"payment_channel_storage_type": "etcd",
"payment_channel_storage_client": {
"connection_timeout": "5s",
"request_timeout": "3s",
"endpoints": ["https://your.domain.com:2379"]
}
}Testing Connection ​
bash
# Test ETCD connectivity
etcdctl --endpoints=https://your.domain.com:2379 \
--cert=/path/to/client.pem \
--key=/path/to/client-key.pem \
--cacert=/path/to/ca.pem \
endpoint healthAdditional Resources ​
- ETCD Official Documentation
- Docker ETCD Image
- SingularityNET Daemon Setup
- Certificate Management with CFSSL
Support ​
For issues or questions:
- Check daemon logs for ETCD connection errors
- Verify network connectivity
- Ensure certificates are valid
- Contact SingularityNET support if issues persist