14.Linux Postfix 邮件服务器
发布: (2026年3月15日 GMT+8 22:19)
3 分钟阅读
原文: Dev.to
Source: Dev.to
实验信息
xFusionCorp Industries 计划在 Stork DC 部署一台通用邮件服务器。经过多次会议和建议后,他们决定使用 Postfix 作为邮件传输代理,使用 Dovecot 作为 IMAP/POP3 服务器。任务如下:
- 在 Stork DC 邮件服务器上安装并配置 Postfix。
- 创建邮箱账户
anita@stratos.xfusioncorp.com,密码为LQfKeWWxWD。 - 将其邮件目录设置为
/home/anita/Maildir。 - 在同一台服务器上安装并配置 Dovecot。
实验解答
第 1 部分:实验逐步指南
目标
在邮件服务器 (stmail01) 上:
- 安装 Postfix
- 创建邮件用户 anita
- 配置邮箱位置
- 安装并配置 Dovecot
服务器访问
# 1️⃣ 登录跳转主机
ssh thor@jump_host.stratos.xfusioncorp.com
# Password: mjolnir123
# 2️⃣ 连接邮件服务器
ssh groot@stmail01
# Password: Gr00T123
# 3️⃣ 切换到 root
sudo -i安装 Postfix
yum install -y postfix
systemctl start postfix
systemctl enable postfix创建用户 anita
useradd anita
passwd anita
# Enter password: LQfKeWWxWD创建邮件目录
mkdir -p /home/anita/Maildir
chown -R anita:anita /home/anita/Maildir配置 Postfix 邮箱位置
编辑 /etc/postfix/main.cf 并添加以下行:
home_mailbox = Maildir/保存并退出,然后重启 Postfix:
systemctl restart postfix安装 Dovecot
yum install -y dovecot配置 Dovecot 邮件位置
编辑 /etc/dovecot/conf.d/10-mail.conf 并设置:
mail_location = maildir:~/Maildir保存并退出。
启动并启用 Dovecot
systemctl start dovecot
systemctl enable dovecot验证服务
systemctl status postfix
systemctl status dovecot两者都应显示 active (running)。
第 2 部分:简明说明(适合初学者)
本实验构建的内容
你正在搭建一个基本的 Linux 邮件服务器,包含两个主要组件:
| 组件 | 用途 |
|---|---|
| Postfix | 邮件传输代理(接收并投递邮件) |
| Dovecot | IMAP/POP3 服务器(让用户读取邮件) |
邮件流示例
用户发送邮件 → Postfix 投递到邮箱 → Dovecot 通过 IMAP/POP3 提供访问。
邮件存储格式
| 格式 | 描述 |
|---|---|
| Maildir | 首选,因为它更快、更安全,且更适合并发访问 |
用户 anita 的邮箱位于:
/home/anita/MaildirPostfix 将收到的邮件存放在 Maildir/ 文件夹中(例如 /home/anita/Maildir/new),Dovecot 则从该位置读取邮件,为用户提供服务。