Linux操作系统邮件服务器的搭建过程解析

摘自: linux.ccidnet.com  被阅读次数: 87


yangyi 于 2008-05-02 21:08:49 提供


1. 用以下命令查看系统是否安装了sendmail:

[root@mail /root]# rpm –qa |grep sendmail

sendmail-8.11.0-8

2. 卸载sendmail:

[root@mail /root]# rpm -e sendmail –nodeps

3. 用以下命令杀死运行中的sendmail进程:

[root@mail /root]# killall sendmail

如果系统提示:

sendmail: no process killed

则说明当前系统中没有sendmail进程。

4. 安装postfix:

[root@mail /root]# rpm -ivh postfix-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 |grep cyurs

如果您看到以下提示,则说明已经安装了cyrus-sasl

[root@test bye2000]# rpm -qa |grep sasl

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 [编辑后,只修改蓝色部分就可以了]

即:修改用户的Home directory和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_destination reject

broken_sasl_auth_clients = yes

smtpd_sasl_security_options = noanonymous

说明如下:

smtpd_sasl_auth_enable:告诉SMTP客户,该SMTP服务器需要进行用户认证。

smtpd_recipient_restrictions = permit_sasl_authenticated

permit_auth_destination reject

仅仅中继通过SMTP认证的客户端邮件,以及接收本postfix为最后一站的邮件。

broken_sasl_auth_clients = yes

有一些Microsoft 的SMTP客户端,比如Outlook Express 4.X采用的是非标准的SMTP认证协议,将该选项设置为yes可以解决这类不兼容问题。

smtpd_sasl_security_options = noanonymous

控制本地SMTP认证所采用的机制,这里是允许任何非匿名认证方法。

9.配置SASL

进入/usr/lib/sasl/目录,用touch新建这样一个文件:

[root@test sasl]# touch smtpd.conf

在该文件中加入以下内容:

[root@test sasl]# more smtpd.conf

pwcheck_method:pam

也就是指定通过PAM来进行用户认证。

10.配置PAM

进入/etc/pam.d/目录,用touch新建这样一个文件:

[root@test pam.d]# touch smtp

在该文件中加入如下内容:

[root@test pam.d]# more smtp

#%PAM-1.0

auth required /lib/security/pam_stack.so service=system-auth

account required /lib/security/pam_stack.so service=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]# chmod 640 /etc/shadow

然后再将postfix用户加入root组,采用以下命令:

[root@test /etc]# usermod -G root postfix

12.编辑postfix的主要配置文件/etc/postfix/master.cf

# ======================================== 
# service type private unpriv chroot wakeup maxproc command + args 
# (yes) (yes) (yes) (never) (100) 
# ======================================== 
smtp inet n - n - - smtpd

这里开始

#smtps inet n - n - - smtpd 
# -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes 
#submission inet n - n - - smtpd 
# -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes

这里结束

#628 inet n - n - - qmqpd

把我标的注释部分去掉即可。

13.配置pop3

RedHat7.0已经使用xinetd代替了以前的inetd,为了使pop3服务启动,我们编辑

/etc/xinetd.d/ipop3文件,将其中的disable = yes改为disable = no 以便启动pop3

服务。

为了使改动生效,执行以下命令:

/etc/rc.d/init.d/xinetd reload

14.启动postfix

执行以下命令启动postfix:

/etc/rc.d/init.d/postfix start

这样,一个支持SMTP认证的postfix邮件服务器就配好了。

原文链接: http://tech.ccidnet.com/art/302/...