存储系统
SirrChat 提供灵活的存储选项,支持从本地文件系统到云对象存储的多种存储后端。
存储类型
本地存储
最简单的存储方式,适合单服务器部署。
toml
[storage]
type = "local"
local_path = "/var/mail"S3 兼容存储
支持 AWS S3 及所有 S3 兼容的对象存储。
toml
[storage]
type = "s3"
[storage.s3]
endpoint = "s3.amazonaws.com"
region = "us-east-1"
bucket = "sirrchat-storage"
access_key = "YOUR_ACCESS_KEY"
secret_key = "YOUR_SECRET_KEY"MinIO
开源 S3 兼容存储。
toml
[storage.s3]
endpoint = "minio.example.com:9000"
bucket = "sirrchat"
access_key = "minioadmin"
secret_key = "minioadmin"
use_ssl = false数据库存储
PostgreSQL
推荐用于生产环境。
toml
[database]
type = "postgres"
dsn = "postgresql://user:password@localhost:5432/sirrchat?sslmode=require"
# 连接池配置
max_open_conns = 25
max_idle_conns = 5
conn_max_lifetime = "5m"MySQL/MariaDB
广泛使用的关系数据库。
toml
[database]
type = "mysql"
dsn = "user:password@tcp(localhost:3306)/sirrchat?parseTime=true&charset=utf8mb4"SQLite
适合开发和小规模部署。
toml
[database]
type = "sqlite"
dsn = "/var/lib/sirrchatd/sirrchat.db"邮件存储格式
Maildir
标准的邮件存储格式,每封邮件一个文件。
/var/mail/[email protected]/
├── cur/ # 已读邮件
├── new/ # 新邮件
└── tmp/ # 临时文件文件命名
1642123456.M123456P12345.hostname,S=1234:2,S- 时间戳
- 唯一 ID
- 大小
- 标志(已读、回复等)
存储优化
压缩
自动压缩旧邮件节省空间。
toml
[storage.compression]
enabled = true
algorithm = "gzip" # gzip, bzip2, zstd
min_age_days = 30 # 30天后压缩去重
自动检测和去除重复邮件。
toml
[storage.deduplication]
enabled = true
hash_algorithm = "sha256"分层存储
根据访问频率自动迁移数据。
toml
[storage.tiering]
enabled = true
# 热存储:频繁访问
[storage.tiering.hot]
type = "local"
path = "/fast/ssd/mail"
max_age_days = 30
# 冷存储:归档
[storage.tiering.cold]
type = "s3"
bucket = "sirrchat-archive"配额管理
用户配额
toml
[storage.quota]
default_quota = "1GB"
max_quota = "10GB"
warning_threshold = 90 # 90% 时警告设置用户配额
bash
sirrchatd quota set --user [email protected] --quota 5GB查看配额使用
bash
sirrchatd quota get --user [email protected]备份和恢复
自动备份
toml
[storage.backup]
enabled = true
schedule = "0 2 * * *" # 每天凌晨2点
retention_days = 30
[storage.backup.destination]
type = "s3"
bucket = "sirrchat-backups"手动备份
bash
# 备份所有数据
sirrchatd backup create --output /backups/sirrchat-$(date +%Y%m%d).tar.gz
# 备份特定用户
sirrchatd backup create --user [email protected]恢复数据
bash
# 恢复所有数据
sirrchatd backup restore --input /backups/sirrchat-20250115.tar.gz
# 恢复特定用户
sirrchatd backup restore --user [email protected] --input backup.tar.gz数据迁移
从其他邮件服务器迁移
从 Postfix/Dovecot
bash
sirrchatd migrate --from maildir --source /var/mail/vhosts从 Exchange
bash
sirrchatd migrate --from pst --source /exports/*.pst存储后端迁移
从本地迁移到 S3:
bash
sirrchatd storage migrate --from local --to s3监控和维护
存储使用统计
bash
sirrchatd storage stats输出:
Total Size: 125.5 GB
Users: 1,234
Average per User: 104.2 MB
Largest User: [email protected] (5.2 GB)清理操作
删除过期邮件
bash
sirrchatd cleanup --older-than 2y清理垃圾箱
bash
sirrchatd cleanup --trash --older-than 30d清理临时文件
bash
sirrchatd cleanup --temp性能优化
缓存配置
toml
[storage.cache]
enabled = true
size_mb = 512
ttl = "1h"索引优化
toml
[storage.indexing]
enabled = true
full_text_search = true并发控制
toml
[storage.concurrency]
max_workers = 10
queue_size = 1000数据安全
加密
传输加密
toml
[storage.encryption]
# S3 传输加密
s3_use_tls = true静态数据加密
toml
[storage.encryption]
enabled = true
algorithm = "AES-256-GCM"
key_file = "/etc/sirrchatd/encryption.key"访问控制
toml
[storage.access]
# 限制访问路径
allow_paths = ["/var/mail"]
deny_paths = ["/etc", "/root"]高可用性
复制
主从复制
toml
[storage.replication]
mode = "master"
slaves = ["slave1.example.com", "slave2.example.com"]多主复制
toml
[storage.replication]
mode = "multi-master"
peers = ["peer1.example.com", "peer2.example.com"]故障转移
toml
[storage.failover]
enabled = true
health_check_interval = "30s"
auto_failover = true故障排除
诊断工具
bash
# 检查存储连接
sirrchatd storage test
# 验证数据完整性
sirrchatd storage verify
# 修复损坏的邮箱
sirrchatd storage repair --user [email protected]常见问题
磁盘空间不足
bash
# 清理旧邮件
sirrchatd cleanup --older-than 1y
# 压缩邮件
sirrchatd storage compressS3 连接失败
bash
# 测试 S3 连接
sirrchatd storage test --type s3
# 查看详细错误
sirrchatd storage test --debug相关文档: