且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CentOS5.4+postfix+dovecot+sasl+openwebmail配置手记

更新时间:2022-06-07 22:34:44

最近接触了一套新的邮件系统,使用的是Postfix的。
以前不太熟悉,照着单位的文档和网上的教程,加上一些自己的修改就形成了这个文档。
2010年7月7日---在新的机器上重新部署的时候发现MailScanner进程CPU占用率很高,重启依旧,而且还会报错。
照着第四个参考链接修改了一下MailScanner和virus.scanners的配置文件就没事了。
抽空还要研究一下让邮件改用nod32.
真的很复杂啊。
 
过程基本都用yum的方式,需要用到rpmforge和openwebmail的源。

http://bbs.chinaunix.net/viewthread.php?tid=1033019

 
 
具体步骤如下:
1. 修改主机名
#vi /etc/sysconfig/network
HOSTNAME=mail.ywtest.com
#hostname mail.ywtest.com
 
2. 安装配置DNS
#yum install bind bind-chroot caching-nameserver
DNS具体配置方法参考:
http://linux.chinaitlab.com/administer/774651.html
#chkconfig named on
#service named restart
#vi /etc/resolv.conf

3. 安装Postfix、dovecot、openwebmail
#cd /etc/yum.repos.d
#lftpget http://openwebmail.org/openwebmail/download/redhat/rpm/release/openwebmail.repo
#yum install postfix dovecot openwebmail

4. 配置dovecot
#vi /etc/dovecot.conf
dovecot具体配置方法参考:
http://linux.chinaitlab.com/administer/774651_4.html
#chkconfig dovecot on
#service dovecot restart

5. 配置Postfix
#service sendmail stop
#chkconfig sendmail off
#chkconfig postfix on
#service postfix start
#alternatives --config mta
#vi /etc/postfix/main.cf
修改或添加下列内容:(这些都是基本配置,其他关于sasl、收信发信过滤的配置以后还要多学习。)
myhostname = mail.ywtest.com
mydomain = ywtest.com
myorigin = $mydomain  (= $myhostname也可以)
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain, www.$mydomainftp.$mydomain
mail_spool_directory = /var/spool/mail
mailbox_command = /usr/bin/procmail  (修改procmail的权限,g+s。在/etc/procmailrc中加入LOGFILE=/var/log/mail/procmail.log,修改mail目录的权限。很多教程里都没有关于procmail的配置;Postfix默认没有指定邮件投递程序,所以这个不做的话邮件能传递,不能被投递。procmail.log文件664权限,root.mail所有。)
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)  (自愿添加)
#vi /etc/postfix/access  写入mail.ywtest.com  OK、ywtest.com  OK、192.168.10  OK
#postmap /etc/postfix/access
#smtpd_client_restrictions = permit_sasl_authenticated
#smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

6. 测试postfix、dovecot端口
#netstat -altpn|grep 25
#netstat -altpn|grep 110
#netstat -altpn|grep 143
#netstat -altpn|grep 993
#netstat -altpn|grep 995
PS:有必要修改iptables的配置,/etc/sysconfig/iptables。

7. 测试命令行方式的邮件收发
#echo "mail test"|mail -v -s "from root@ywtest.com at 20.30" user1@ywtest.com
#mutt -f pop://user1@ywtest.com  (mutt可以收发邮件,具体用法不做解释。)

8. 配置sasl
#vi /etc/sysconfig/saslauthd
修改或添加下列内容:
MECH=shadow
#chkconfig saslauthd on
#service saslauthd start

9. 配置openwebmail  (个人不推荐使用,还是知名软件例如horde、squirrelmail、roundcube比较靠谱。对比连接http://www.extmail.org/forum/thread-440-1-1.html  --老了点,呵呵。)
先要有httpd,不过默认的安装就可以了,所以不多说了。
openwebmail具体配置方法参考:
http://linux.chinaitlab.com/administer/774651_4.html
#vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
修改或添加下列内容:
domainnames    ywtest.com
default_language    zh_CN.GB2312
default_timeoffset    +0800
default_iconset    Cool3D.Chinese.Simplified
#vi /var/www/cgi-bin/openwebmail/etc/defaults/openwebmail.conf
修改或添加下列内容:
smtpserver    192.168.10.202
authpop3_server    192.168.10.202
#cd /var/www/cgi-bin/openwebmail
#./openwebmail-tool.pl --init

10.测试openwebmail
因为是rpm装的ScriptAlias的配置已经自动添加了,装了openwebmail之后记得重启httpd。
浏览http://mail.ywtest.com/webmail即可。
 
11.安装Mail-SpamAssassin
本来想和别人一样用rpmbuild的方法安装,但是提示找不到/var/tmp/下的一个文件,那个文件命名存在。
后来改用yum的方法了,不知道后面会有什么问题。
#yum -y install spamassassin
#chkconfig spamassassin on
#service spamassassin start
 
12.安装MailScanner和install-Clam-SA
#tar zxf MailScanner-4.51.5-1.rpm.tar.gz
#tar zxf install-Clam-SA.tar.gz
#cd MailScanner-4.51.5-1
#./install.sh
#cd ../install-Clam-SA
#./install.sh
时间真的很长。
具体参考:
http://ciscolj.blog.51cto.com/330452/167427
 
13.配置
#vi /etc/mail/spamassassin/init.pre
取消下面插件的注释,如果有的话:
loadplugin Mail::SpamAssassin::Plugin::Razor2
#vi /etc/MailScanner/MailScanner.conf
修改或添加下列内容:
%org-name% = ywtest
%org-long-name% = ywtest
%web-site% = www.ywtest.com
Run As User = postfix
Run As Group = postfix
Incoming Work User = postfix
Incoming Work Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
Quarantine User = postfix
Quarantine Group = postfix
MTA = postfix
Virus Scanning = yes
Virus Scanners = clamav
参考链接:http://bbs.chinaunix.net/viewthread.php?tid=1033019
 
调整下列目录权限:
#chown postfix.postfix mqueue -R
#chown postfix.postfix mqueue.in/ -R
#chown postfix.postfix MailScanner/ -R
#chown postfix.postfix postfix/ -R

*.ywtest.com是我自己常用的测试用域名,不是真正能解析的。
 
其他:
访问mail.ywtest.com直接看到openwebmail登陆界面:
创建opwebmail的虚拟主机:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin root@localhost
    ServerName mail.ywtest.com
    DocumentRoot "/usr/local/apache/htdocs/openwebmail"
    Alias /data /usr/local/apache/data
    ErrorLog "logs/mail.ywtest.com-error_log"
    CustomLog "logs/mail.ywtest.com-access_log" combined
</VirtualHost>
#vi index.html  创建index.html页面,内容如下:
<html>
<body onload=
"window.open('http://mail.ywtest.com/cgi-bin/openwebmail/openwebmail.pl','_top')">
</body>
</html>









本文转自 sharkyan 51CTO博客,原文链接:http://blog.51cto.com/sharkyan/313095,如需转载请自行联系原作者