postfix搭建及配置

           

一.     电子邮件系统概述
1.     邮件系统角色
*    MUA (邮件用户代理)、 MTA (邮件传输代理)、 MDA (邮件分发代理
2.     邮件应用协议
*    SMTP ,简单邮件传输协议, TCP 25 端口
*    POP3 ,第 3 版邮局协议, TCP 110 端口
*    IMAP4 ,第 4 版因特网消息访问协议, TCP 143 端口
二.     常用的邮件服务器软件
1.     商业邮件系统
*     Exchange :微软公司的重量级产品,与 Windows 系列软件产品相集成,协作性较好
*     Notes/Domino IBM 公司的商业电子邮件和办公协作软件产品,功能丰富、强大,提供跨平台支持
2.     开源邮件系统
*     Sendmail :资格最古老,运行稳定,但安全性欠佳
*     Qmail :有更好的执行效率,配置、管理也很方便
*     Postfix :兼容 Sendmail ,采用模块化设计,在投递效率、稳定性、服务性能及安全性方面表现优秀
三.     编译安装 Postfix
1.     停用 sendmail 服务,以避免冲突
   [root@mail ~]# service sendmail stop
 chkconfig --level 35 sendmail off
2.     获得源码文件包
Ø  源程序包: postfix-2.4.6.tar.gz
Ø  VDA 补丁包: postfix-2.4.6-vda-ng.patch.gz
3.       添加运行邮件系统的帐号
*          用户帐号 postfix ,组帐号 postfix postdrop
groupadd -g 1200 postdrop
 groupadd -g 1000 postfix
useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
4.     解压释放源码包、合并 VGA 补丁
tar zxvf postfix-2.4.6.tar.gz
gunzip postfix-2.4.6-vda-ng.patch.gz
cd postfix-2.4.6
patch -p1 < ../postfix-2.4.6-vda-ng.patch
    注意: p 后面的数字取决于你补丁包里的设置,跟微软的补丁类似
5. 预配置编译参数
*    注意参考 README_FILES 子目录中的说明文档
*    添加 MySQL 数据库查询、 SASL 认证支持
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 '
6. 编译并完成安装
make && make install
四.     Postfix 的主要目录
1.     配置文件目录: /etc/postfix/
2.     服务程序目录: /usr/libexec/postfix/
3.     邮件队列目录: /var/spool/postfix/*
a)       incoming active deferred
b)      hold corrupt
4.     邮件管理程序目录: /usr/sbin/*
a)       postalias postmap
b)      postconf postfix
c)       postqueue postsuper
注意:
邮件队列子目录:
    1)incoming传入:刚接收到的邮件 2)active活动:正在投递的邮件 3)deferred推迟:以前投递失败的邮件
    4)hold约束:被阻止发送的邮件     5)corrupt错误:不可读或不可分析的邮件
主要的邮件管理程序(/usr/sbin/post*)
    1)postalias:用于构造、修改和查询别名表     2)postmap:用于构造、修改或者查询查询表
    3)postconf:用于显示和编辑main.cf配置文件     4)postfix:用于启动、停止postix,要求root用户权限
5)postqueue:用于管理邮件队列,一般用户使用     6)postsuper:用于管理邮件队列,要求有root用户权限
 
五.       Postfix 的配置文件
1.     /etc/postfix/master.cf
master 主程序的配置文件
2.     /etc/postfix/main.cf
a)   postfix 服务的配置文件
3.     辅助配置工具 postconf
a)   执行 postconf ,查看当前的有效配置
b)  执行 postconf -n ,查看非默认配置
c)   执行 postconf -d ,查看默认配置
4.     Postfix 的日志文件
1)  /var/log/maillog
*    记录了 postfix 服务的邮件传递等过程信息
2)  常用分析方法
*    动态跟踪日志变化
 tail -f /var/log/maillog
*    关键词搜索
 egrep '(reject|warning|error|fatal|panic):' /var/log/maillog
5.     Postfix 的控制启动
1)  Postfix 服务控制
*    使用 /usr/sbin/postfix 程序
*    常见控制参数: start stop reload check
 如:postfix start/reload/check
                 构建简单电子邮件系统
一.           案例环境:
*    IP 地址: 173.17.17.11/24
*    主机名 : mail.benet.com
*    邮件域: @benet.com
*    邮件帐号:使用本地系统用户
*    使用 dovecot 提供收信服务
二.           域名设置
*    需要在 benet.com 域的 DNS 服务器中注册,设置相应的 A 记录和 MX 记录
    @          IN      MX      5       mail.benet.com.
mail        IN      A       173.17.17.11
三.           构建 postfix 服务器
1.       修改 main.cf 配置文件,调整运行参数
编辑 /etc/postfix/main.cf
inet_interfaces = 173.17.17.11, 127.0.0.1      
myhostname = mail.benet.com            
mydomain = benet.com                  
myorigin = $mydomain  外发邮件时发件人地址中的邮件域名
mydestination = $mydomain, $myhostname 允许投递到本地的邮件域名
home_mailbox = Maildir/ (Mailbox 已淘汰 ) 邮件存储位置和格式
2.     重新加载配置: postfix reload
3.     建立邮件帐号: xiaoqi lisi
4.     SMTP 发信测试: telnet localhost 25
telnet localhost 25
HELO localhost                                        
250 mail.benet.com
MAIL FROM: [email protected]            
250 2.1.0 Ok
RCPT TO: [email protected]                     
250 2.1.5 Ok
……
DATA                                                       
354 End data with <CR><LF>.<CR><LF>
Subject: A Test Mail                               
HELLO!                                              
This is a test mail!
.
250 2.0.0 Ok: queued as 6F24D148440
QUIT                                                        
221 2.0.0 Bye
Connection closed by foreign host.
四.           构建 dovecot 服务器
1. 编译安装 dovecot 软件
*    下载源码包 dovecot-1.1.4.tar.gz
p 官方站点: http://www.dovecot.org
*    添加 dovecot 运行用户
*    解包、配置、编译及安装
#useradd -M -s /sbin/nologin dovecot
#tar zxvf dovecot-1.1.4.tar.gz
#cd dovecot-1.1.4
#./configure --sysconfdir=/etc --with-mysql
#make && make install
2. 建立 dovecot.conf 配置文件
cp /etc/dovecot-example.conf /etc/dovecot.conf
[root@mail ~]# vi /etc/dovecot.conf
……
ssl_disable = yes 禁用 SSL 机制
……
protocols = pop3 imap 支持的邮局协议
……
disable_plaintext_auth = no 允许明文密码认证
……
mail_location = maildir:~/Maildir 邮件存储格式及位置
3. 创建 PAM 认证文件
vi /etc/pam.d/dovecot
auth       required     pam_nologin.so
auth       include      system-auth
account    include      system-auth
session    include      system-auth
4. 启动 dovecot 服务
# /usr/local/sbin/dovecot -c /etc/dovecot.conf
5. POP3 收信测试: telnet localhost 110
[root@mail ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to mail.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
USER lisi
+OK
PASS 123456
+OK Logged in.
……
LIST
+OK 1 messages:
1 451
.
RETR 1
+OK 451 octets
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from mail.benet.com (mail.benet.com [127.0.0.1])
        by mail.benet.com (Postfix) with SMTP id 6F24D148440
 
五.           使用 Outlook Express 邮件客户端
设置电子邮件帐号,并进行收发信测试
*    设置邮件帐号为 xiaoqi (不带 @benet.com 后缀)
*    SMTP POP3 服务器: mail.benet.com
六.           扩展 Postfix 邮件系统的功能
1.     添加 Webmail 邮件界面 : 编译安装 squirrelmail 程序套件
    tar jxvf squirrelmail-1.4.13.tar.bz2 -C /usr/local/apache2/htdocs/
cd /usr/local/apache2/htdocs/
mv squirrelmail-1.4.13 webmail
解压 all_locales-1.5.1-20060219.tar ,然后拷贝 locale 目录里面的所有内容到 /usr/local/apache2/htdocs/webmail/locale/ 里面。
2.     创建及调整数据目录、附件目录
cd   /usr/local/apache2/htdocs/webmail
mkdir -p attach data
chown -R daemon:daemon attach/ data/
[root@mail webmail]# chmod 730 attach/
3.     建立并调整 config.php 配置文件
cp config/config_default.php  config/config.php
vi  config/config.php
$squirrelmail_default_language = 'zh_CN';
$default_charset = 'zh_CN.UTF-8';
$domain = 'benet.com';
$smtpServerAddress = 'localhost';
$smtpPort = 25;
$imap_server_type = 'dovecot';
$imapPort = 143;
$data_dir = '/usr/local/apache2/htdocs/webmail/data/';
$attachment_dir = '/usr/local/apache2/htdocs/webmail/attach/';
4.     确认启动 httpd 服务程序
5.     在浏览器中访问 Webmail 界面 http://mail.benet.com/webmail/
七.           添加 SMTP 用户认证
1. 配置并启动 saslauthd 服务
*    建立配置文件: /usr/lib/sasl2/smtpd.conf
*    启动 saslauthd 服务
cd /usr/lib/sasl2/
[root@mail sasl2]# cp Sendmail.conf smtpd.conf
[root@mail sasl2]# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
[root@mail sasl2]# service saslauthd start
2. 调整 main.cf 文件,以便支持认证
*    修改后要重载 postfix 服务: postfix reload
 vi /etc/postfix/main.cf
……
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.1
smtpd_recipient_restrictions = permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination 若收件人地址未在授权网络内,则拒绝发送
八.           用户别名与邮件群组
aliases 别名机制
*    一般使用 /etc/aliases 文件
*    aliases 文件的记录格式
p 别名: 地址1, 地址2, 地址3, ……
*    执行 newaliases 命令,以更新别名设置
九.           设置邮件大小、邮箱空间限制
1.     邮件大小限制
*    message_size_limit
2.     邮箱空间大小限制
*    mailbox_size_limit
针对Mailbox邮箱、系统用户,缺省值为50MB
*    virtual_mailbox_limit
针对使用虚拟用户的情况,缺省值为50MB
*    quota 磁盘配额功能
针对使用Linux系统用户作为邮件账号的情况
 

你可能感兴趣的:(postfix搭建及配置)