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.
Prerequisites ​
Before starting the ETCD setup:
- Ubuntu 18.04 or higher (for automated script)
- Domain name with SSL certificates
- Docker installed and running
- Sudo permissions for the user
- Open ports for ETCD communication (2379, 2380)
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 ​
Port Forwarding Setup ​
Configure your web server to forward requests:
nginx
# Example Nginx configuration
server {
listen 443 ssl;
server_name your.domain.com;
location /:2379 {
proxy_pass http://localhost:2379;
proxy_set_header Host $host;
}
}Generate Domain Certificates ​
Using Certbot (Let's Encrypt) ​
- Install Certbot:
bash
# Ubuntu/Debian
sudo apt update
sudo apt install certbot
# Or follow instructions at:
# https://certbot.eff.org/instructions?ws=other&os=ubuntufocal- Generate Certificates:
bash
# Standalone mode (requires port 80 to be free)
sudo certbot certonly --standalone -d your.domain.com
# Or using webroot
sudo certbot certonly --webroot -w /var/www/html -d your.domain.com- Locate Certificates:
bash
# View certificate paths
sudo certbot certificates
# Typical paths:
# Certificate: /etc/letsencrypt/live/your.domain.com/fullchain.pem
# Private Key: /etc/letsencrypt/live/your.domain.com/privkey.pem- Enable Auto-renewal:
bash
# Check renewal timer
sudo systemctl status certbot.timer
# Test renewal
sudo certbot renew --dry-runCertificate Parameters for Daemon ​
Use these in your daemon configuration:
json
{
"ssl_cert": "/path/to/fullchain.pem",
"ssl_key": "/path/to/privkey.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