迁移 Debian 上的邮件服务(如 Postfix、Exim、Dovecot 等)是一项需要谨慎操作的任务,核心目标是保证邮件不丢失、服务不中断(或中断时间最短)。下面我按通用流程 + 常见组件给你一个可落地的迁移方案。
先确认你用的组件:
dpkg -l | grep -E 'postfix|exim|dovecot|sendmail'
常见组合:
| 类型 | 示例 |
|---|---|
| 配置文件 | /etc/postfix, /etc/dovecot |
| 用户数据 | /var/mail, /home/*/Maildir |
| 邮箱数据库 | MySQL / PostgreSQL / LDAP |
| 认证信息 | /etc/passwd, PAM, SQL |
| 证书 | Let’s Encrypt /etc/letsencrypt |
| 队列邮件 | /var/spool/postfix |
适合小用户量或可接受停机。
tar czf mail-config.tar.gz /etc/postfix /etc/dovecot
apt install postfix dovecot-core dovecot-imapd
tar xzf mail-config.tar.gz -C /
⚠ 注意:
rsync -avz --delete /var/vmail/ root@newserver:/var/vmail/
或用户目录:
rsync -avz /home/ user@new:/home/
rsync -avz /var/mail/ root@new:/var/mail/
imapsync \
--host1 old.example.com --user1 user --password1 pass \
--host2 new.example.com --user2 user --password2 pass
mysqldump maildb > maildb.sql
新服务器导入:
mysql maildb < maildb.sql
getent passwd | grep mail > users.txt
rsync -avz /etc/letsencrypt root@new:/etc/
或新服务器重新签发:
certbot renew --force-renewal
修改 MX 记录:
example.com. MX 10 mail.new.example.com.
TTL 提前调小(如 300 秒)
echo test | mail -s test user@example.com
tail -f /var/log/mail.log
postqueue -p
/var/spool/postfix 可能导致队列损坏如果你愿意,可以告诉我:
我可以给你一份专用迁移命令清单。