Postfix实用维护技术Author:HzqbbcExtMailDevTeam2007-06-14Postfix简介作者:WietseVenema(荷兰人)发起时间:1998起源:1998年12月,IBM将SecureMailer开源,并逐步演变为今天的Postfix目标:比Sendmail快三倍,更易配置,以安全为首要任务目前发展情况有逐步取代sendmail,qmail的趋势,国内外大型ISP份份转向postfix,如sina,163,sohu等。Postfix开发从未间断,不断有新特性研发Postfix基本结构程序查询表Postfix支持的查询表类型:hash,gdbm,btree,cidr,pcre,regexp,unix,tcp_table,mysql,ldap等Postfix基本特性DKIM/Domainkey/SPF(2.3+)SASL插件机制(Cyrus或dovecot,2.3+)TLS(2.2+),SASL(1.0+)内容过滤器(contentfilter,1.1+)SendmailMilter(2.3+)Policy控制(2.0+)Access访问控制(2.1+)频率控制(2.2+)Maildir/mbox支持地址重写(rewrite,2.2+)Postfix邮件流程–收信Pickup:监视maildrop队列,将新投进来的邮件转交给cleanupSmtpd:监听25端口,接受来自网络的邮件,并转交给cleanupCleanup:进行地址转换,邮件规范化,并转到incoming队列中Postfix邮件流程–投信Qmgr:队列管理核心,将邮件按配置转交给local或smtp,pipe等Bounce:维护每封信的记录信息,并维护退信用Telnet测试SMTP会话[root@cnc-mx~]#telnetmail.example.com25Trying1.2.3.4...Connectedtomail.example.com(1.2.3.4).Escapecharacteris'^]'.220example.comESMTPPostfixhelotest.com250mail.example.commailfrom:foo@test.com2502.1.0Okrcptto:bar@example.com2502.1.5Okdata354EnddatawithCRLF.CRLFFrom:foo@test.comTo:bar@example.comSubject:Helloman!Sayhellotoyou!.2502.0.0Ok:queuedas592D2AB63quit2212.0.0ByeConnectionclosedbyforeignhost.4514.3.0bar@example.com:Temporarylookupfailure检查配置文件是否填写正确,比如ldap的host填写错误。或者mysql失去响应等CONNECTHELOMAILFROMRCPTDATAQUIT日志图表分析邮件日志:/var/log/maillog最详尽的邮件系统各组件记录(重点)系统日志:/var/log/syslog操作系统级别的告警,报错图表:extman或mailgraph,mrtg网络流量,邮件进出,webmail登陆等文字报表:pflogsumm各种收发、邮件大小、域名、IP的统计Maillog日志格式Jun1523:55:10cnc-mxpostfix/pipe[14638]:7A6E1AB63:to=hzqbbc@hzqbbc.com,relay=maildrop,delay=1.8,delays=1.6/0.1/0/0.1,dsn=2.0.0,status=sent(deliveredviamaildropservice)Jun1600:05:33cnc-mxpostfix/smtpd[17192]:NOQUEUE:reject:CONNECTfromunknown[123.199.27.245]:5545.7.1Serviceunavailable;Clienthost[123.199.27.245]blockedusingsbl-xbl.spamhaus.org;=123.199.27.245;proto=SMTP日期主机名程序名队列ID投递状态处理时延SMTP阶段不存在队列中Mailq信息格式A77A89E78D1193TueJun1216:26:13foo@test.com(lostconnectionwithmxh.hostedservice.com[81.3.85.3]whilesendingMAILFROM)nii@freenet.co.uk队列ID邮件大小时间来信人停留队列原因收件人常见报错信息1C9074A07546282MonJun1102:14:14service@oray.cn(hostmta-v1.mail.vip.cnb.yahoo.com[202.43.216.28]said:451Resourcestemporarilynotavailable-Pleasetryagainlater[#4.16.5].(inreplytoendofDATAcommand))xmxsw@yahoo.com.cn2C7C39E7814228FriJun1508:31:29service@oray.cn(Hostordomainnamenotfound.Nameserviceerrorforname=ysbj.comtype=MX:Hostnotfound,tryagain)ysbj@ysbj.comC5B1B9E7763449WedJun1321:45:12MAILER-DAEMON(connecttongunor.impetrated.com[67.19.55.28]:Connectionrefused)VanBurnette@ngunor.impetrated.com常见报错信息24B04F9E7791236FriJun1502:10:43MAILER-DAEMON(connecttomail.americantitlenld.com[72.36.143.218]:Connectiontimedout)sales@americantitlenld.comMay1304:35:46srv01postfix/smtp[24438]:7C0349E7F1:to=33224692@qq.com,relay=none,delay=50338,dsn=4.4.0,status=deferred(connecttomx0-3t.qq.com[219.133.40.163]:serverdroppedconnectionwithoutsendingtheinitialSMTPgreeting)Jun1613:47:05devpostfix/smtp[5780]:connectto127.0.0.1[127.0.0.1]:Connectionrefused(port10024)Jun1613:47:05devpostfix/smtp[5780]:B055F7D50:to=test@foo.com,relay=none,delay=1,dsn=4.4.1,status=deferred(connectto127.0.0.1[127.0.0.1]:Connectionrefused)常见报错信息3May1304:19:04srv01postfix/smtp[24194]:AD52B9E7B7:to=admin@hxqg.com,relay=none,delay=67710,dsn=4.4.1,status=deferred(connectto61.152.105.238[61.152.105.238]:Noroutetohost)May1304:19:05srv01postfix/smtp[24184]:CA74E9E7F0:to=xmxsw@yahoo.com.cn,relay=mta-v1.mail.vip.cnb.yahoo.com[202.43.216.28],delay=154163,dsn=4.0.0,status=deferred(hostmta-v1.mail.vip.cnb.yahoo.com[202.43.216.28]said:451mta120.mail.cnb.yahoo.comResourcestemporarilyunavailable.Pleasetryagainlater[#4.16.1].(inreplytoendofDATAcommand))May1304:19:09srv01postfix/smtp[24188]:EF42F9E7F3:to=33224797@qq.com,relay=mx0-3t.qq.com[219.133.40.163],delay=49341,dsn=4.4.2,status=deferred(lostconnectionwithmx0-3t.qq.com[219.133.40.163]whilesendingRCPTTO)利用图表分析左图中16:00前后有大量邮件弹回,可有针对性检查邮件日志,快速地定位故障的原因从左图中9:00和下午16:00前后有大量登陆失败的用户,可以有针对性的检查系统的情况日常运维系统日志:是否被攻击,资源不足等邮件日志:收发是否正常,有无异常提示常规手段df–h看存储分区、日志分区是否满了free看内存及交换区情况,是否被吃光top看cpu,内存使用情况,进程繁忙程度vmstat看系统的I/O吞吐情况uptime看系统负载,运行时间ps看进程数,是否有defunt进程,数据库是否正常内存使用情况查看工具free(linux),systat(freebsd),top重点信息used,free的比例,以及Swap使用率进程表中内存大户(amavisd,mysqld等)磁盘空间查看工具:df命令,如df-h重点注意:邮件存储分区,如/home等日志分区,如/var/log数据库分区,如/var/lib正常情况异常:/var用光Postfix主要内建工具postfix(1)–服务控制与配置检查postconf(5)–维护main.cf与查看配置postmap(5)–查询表维护工具postsuper(1)–队列操作工具postqueue(1)–队列控制,如显示、刷新postkick(1)–打开关闭某个Postfix服务postlog(1)–日志记录工具,用于命令行postalias(1)–维护postfix别名数据库Postfix常用命令集锦1postfix(1)重启动postfix,重读配置:postfixreload重置文件权限:postfixset-permissions(2.1+)postconf(1)更改某个参数:postconf–emynetworks=127.0.0.1显示简化的配置:postconf–n显示当前支持的表类型:postconf-mPostfix常用命令集锦2postmap(1)重建hash表:postmaphash:/etc/postfix/access查询某个表:postmap–qfoo@bar.commysql:/etc/postfix/mysql_mailbox.cf删除某个键:(对mysql/ldap无效)postmap–dfoo@bar.comhash:/etc/postfix/access增加一个键:(对mysql/ldap无效)echo“foo@bar.comREJECT”|postmap-i/etc/postfix/access(在/etc/postf