日期:2014-05-16  浏览次数:20593 次

Linux系统邮件服务器的搭建过程解析
1.用以下命令查看系统是否安装了sendmail:
 
[root@mail/root]#rpm–qa|grepsendmail
 
sendmail-8.11.0-8
 
2.卸载sendmail:
 
[root@mail/root]#rpm-esendmail–nodeps
 
3.用以下命令杀死运行中的sendmail进程:
 
[root@mail/root]#killallsendmail
 
如果系统提示:
 
sendmail:noprocesskilled
 
则说明当前系统中没有sendmail进程。
 
4.安装postfix:
 
[root@mail/root]#rpm-ivhpostfix-20010228release-2.i386.rpm
 
若已经安装,则此步可以省略。(注:安装时最好用rpm包,会自动创建postfix用户和postfix组)
 
5.安装imap
 
rpm–ivh/mnt/cdrom/RedHat/RPMS/imap-4.7c2-12.rpm
 
imap使pop3有效,即打开110端口。(注:安装时最好用rpm包)
 
若已经安装,则此步可以省略。
 
6.检查系统中是否安装了cyrus-sasl
 
执行以下命令查看系统中是否安装了cyrus-sasl:
 
rpm–qa|grepcyurs
 
如果您看到以下提示,则说明已经安装了cyrus-sasl
 
[root@testbye2000]#rpm-qa|grepsasl
 
cyrus-sasl-devel-1.5.24-17
 
cyrus-sasl-1.5.24-17
 
否则,请用rpm–ivh命令先安装所需sasl-cyrus包。
 
7.修改postfix用户
 
同时应该让该用户不能登录到系统,也即不为该用户指定可执行的登录外壳程序和可用
 
的用户宿主目录。
 
编辑/etc/passwd文件中的相关条目如下所示:
 
postfix:x:89:89::/no/where:/no/shell[编辑后,只修改蓝色部分就可以了]
 
即:修改用户的Homedirectory和Shell参照/etc/passwd文件
 
8.编辑postfix的主要配置文件/etc/postfix/main.cf,根据需求只需修改以下几个参数:
 
1)mydomain
 
指明你的域名,在这里我们指定:
 
mydomain=xx.com
 
2)myorigin
 
myorigin参数指明发件人所在的域名。如果你的用户的邮件地址为user@domain.com,则该参数指定@后面的域名。在这里我们指定:
 
myorigin=$mydomain
 
3)inet_interfaces
 
inet_interfaces=all监听所有端口
 
4)mydestination
 
mydestination参数指定postfix接收邮件时收件人的域名,换句话说,也就是你的postfix
 
系统要接收什么样的邮件。通常与myorigin一样:
 
mydestination=$mydomain
 
5)mynetworks_style
 
设置网络类型,我们指定:
 
mynetworks_style=subnet
 
6)ynetworks
 
定义可以使用的此smtp服务器发信的客户ip地址,因为公司的ip范围已知,所以我们
 
指定:
 
mynetworks=192.168.1.0/24
 
注:此项可根据情况而定,主要是指定ip范围,假如公司的ip划分是按照网段来的,例如:10.10.1.0~10.10.1.9,10.10.3.0~10.10.3.9等等更细。根据需要,该项可以不设置。
 
7)SMTP的配置
 
为了告诉postfix采用sasl来进行SMTP的用户认证,我们必须在/etc/postfix/main.cf文件的最后添加以下几行:
 
smtpd_sasl_auth_enable=yes
 
smtpd_recipient_restrictions=permit_sasl_authenticated
 
permit_auth_destinationreject
 
broken_sasl_auth_clients=yes
 
smtpd_sasl_security_options=noanonymous
 
说明如下:
 
smtpd_sasl_auth_enable:告诉SMTP客户,该SMTP服务器需要进行用户认证。
 
smtpd_recipient_restrictions=permit_sasl_authenticated
 
permit_auth_destinationreject
仅仅中继通过SMTP认证的客户端邮件,以及接收本postfix为最后一站的邮件。
 
broken_sasl_auth_clients=yes
 
有一些Microsoft的SMTP客户端,比如OutlookExpress4.X采用的是非标准的SMTP认证协议,将该选项设置为yes可以解决这类不兼容问题。
 
smtpd_sasl_security_options=noanonymous
 
控制本地SMTP认证所采用的机制,这里是允许任何非匿名认证方法。
 
9.配置SASL
 
进入/usr/lib/sasl/目录,用touch新建这样一个文件:
 
[root@testsasl]#touchsmtpd.conf
 
在该文件中加入以下内容:
 
[root@testsasl]#moresmtpd.conf
 
pwcheck_method:pam
 
也就是指定通过PAM来进行用户认证。
 
10.配置PAM
 
进入/etc/pam.d/目录,用touch新建这样一个文件:
 
[root@testpam.d]#touchsmtp
 
在该文件中加入如下内容:
 
[root@testpam.d]#moresmtp
 
#%PAM-1.0
 
authrequired/lib/security/pam_stack.soservice=system-auth
 
accountrequired/lib/security/pam_stack.soservice=system-auth
 
也即和/etc/pam.d/pop文件的内容是一致的。
 
11.修改/etc/shadow文件权限
 
因为PAM最终要去读取/etc/shadow文件的内容来进行用户认证,但是/etc/shadow文件
 
权限是设置为只有root用户可以读写,而我们的postfix是运行在postfix用户权限之下,所以我们要合理的设置/etc/shadow文件权限,以便让pam可以读取其内容。
 
执行以下命令,让root组也可以读取shadow:
 
[root@test/etc]#chmod640/etc/shadow
 
然后再将postfix用户加入root组,采用以下命令:
 
[root@test/etc]#usermod-Grootpostfix
 
12.编辑postfix的主要配置文件/etc/postfix/master.cf
 
#================