Mail Server - Postfix 安装

参考资源

程式下载

Postfix 为一套比 sendmail 更容易安装、调整的邮件系统,选择 Postfix 的原因是因为容易设定和了解,而且内建也已有邮件过泸的功能,更重要的是,它被设计和 sendmail 相容!很多在 sendmail 的系统指令,在 postfix 都可以使用!

当初我选了择 postfix 套件除了容易设定和了解之外,还有一个原因是在小弟读完了传说中 sendmail 的两本天书 (sendmail 基础篇sendmail 安装管理) 之后,发现除了 mail 邮件传递原理及理论有所吸收外,sendmail 的设定档简直不是人看的了!因此才会选择 postfix 来做为 mail system。

当然,这里的范例是以 Redhat 来做说明,而且也相信在不同的套件系统安装也是大同小异,所以就不在做其它系统的示范了。安装之前,在您的主机上必需要有 GCC 编译器,和 postfix 的原始码,postfix 的下载点在 http://www.postfix.org/download.html 有完全的列表,台湾也有 mirror 站台,应该可以下载较快!

关闭 sendmail

看看 sendmail 有无启动

[root@rhel200 root]# netstat -nutlp | grep :25
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1566/sendmail: acce
[root@rhel200 root]#

若有,则关闭之,并在开机始也不启动 sendmail

[root@rhel200 root]# service sendmail stop
Shutting down sendmail: [ OK ]
Shutting down sm-client: [ OK ]
[root@rhel200 root]# chkconfig sendmail off
[root@rhel200 root]# chkconfig sendmail --list
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@rhel200 root]#

再次查和 sendmail 有无被关闭

[root@rhel200 root]# netstat -nutlp | grep :25
[root@rhel200 root]#

下载 postfix 原始档

[root@rhel200 root]# wget ftp://postfix.cdpa.nsysu.edu.tw/postfix/postfix-release/official/postfix-2.1.5.tar.gz
--14:58:05-- ftp://postfix.cdpa.nsysu.edu.tw/postfix/postfix-release/official/postfix-2.1.5.tar.gz
=> `postfix-2.1.5.tar.gz'
Resolving postfix.cdpa.nsysu.edu.tw... done.
Connecting to postfix.cdpa.nsysu.edu.tw[140.117.205.30]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /postfix/postfix-release/official ... done.
==> PASV ... done. ==> RETR postfix-2.1.5.tar.gz ... done.

[ <=> ] 1,971,931 210.41K/s

14:58:14 (210.41 KB/s) - `postfix-2.1.5.tar.gz' saved [1971931]

[root@rhel200 root]#

解开 postfix

[root@rhel200 root]# tar -zxf postfix-2.1.5.tar.gz
[root@rhel200 root]#

建立 postfix 使用者和群组

[root@rhel200 postfix-2.1.5]# groupadd postdrop
[root@rhel200 postfix-2.1.5]# useradd postfix -s /bin/false
[root@rhel200 postfix-2.1.5]#

删除之前编译过后的档案

[root@rhel200 root]# cd postfix-2.1.5
[root@rhel200 postfix-2.1.5]# make clean
~ 略 ~
[root@rhel200 postfix-2.1.5]#

开始编译

[root@rhel200 postfix-2.1.5]# make
~ 略 ~
[root@rhel200 postfix-2.1.5]#

开始安装

[root@rhel200 postfix-2.1.5]# make install
Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to other
machines.
install_root: [/]
这一段是在寻问安装的根目录是在那里。如果您有使用 chroot 则请另外设定。

Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/root/postfix-2.1.5]
安装时的暂存资料夹,这不用担心,安装好就会被删除

Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix]
postfix 的设定档要放在那里

Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search path
of any users.
daemon_directory: [/usr/libexec/postfix]
postfix 的 daemon 放在那里

Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin]
postfix 的 command 放在里

Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix]
postfix 的处理信件的 queue 目录

Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting interface.
sendmail_path: [/usr/sbin/sendmail]
sendmail 的程式位置,若不知道请按 [Enter]

Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases]
sendmail 产生别名的程式,若不知道请按 [Enter]

Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing command.
mailq_path: [/usr/bin/mailq]
sendmail 查看 mail 伫列的情况程式,若不知道请按 [Enter]

Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix]
postfix 执行期间的使用者

Please specify the group for mail submission and for queue management
commands. Specify a group name with a numerical group ID that is
not shared with other accounts, not even with the Postfix mail_owner
account. You can no longer specify "no" here.
setgid_group: [postdrop]
postfix 的群组 (SGID)

Please specify the destination directory for the Postfix HTML
files. Specify "no" if you do not want to install these files.
html_directory: [no]

Please specify the destination directory for the Postfix on-line manual
pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/man]

Please specify the destination directory for the Postfix README
files. Specify "no" if you do not want to install these files.
readme_directory: [no]

Warning: you still need to edit myorigin/mydestination/mynetworks
parameter settings in /etc/postfix/main.cf.

See also http://www.postfix.org/faq.html for information about dialup
sites or about sites inside a firewalled network.

BTW: Check your /etc/aliases file and be sure to set up aliases
that send mail for root and postmaster to a real person, then run
/usr/bin/newaliases.

[root@rhel200 postfix-2.1.5]#

开机时以 postfix 使为 mail system

[root@rhel200 postfix]# echo "/usr/sbin/postfix start" >> /etc/rc.d/rc.local
[root@rhel200 postfix]#

编辑设定档

[root@rhel200 postfix]# cd /etc/postfix
[root@rhel200 postfix]# vi main.cf
________________________________________________
# 设定本机的 host name
myhostname = ms1.abc.com.tw
# 设定 domain 网域
mydomain = abc.com.tw
# 设定帮忙 relay 的 hosts
mynetworks = 192.168.1.0/24, 127.0.0.0/8
# 设定本机要接收的 mail, 同 sendmail 的 local-host-names
mydestination = abc.com.tw
________________________________________________

[root@rhel200 postfix]#

启动 postfix 邮件系统

[root@rhel200 postfix]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@rhel200 postfix]#

查看 postfix 是否在听 25 port

[root@rhel200 postfix]# netstat -ntulp | grep :25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6462/master
[root@rhel200 postfix]#

好了,以上完成了 postfix 的安装和简易设定!再次强调,mail server 和 DNS 是脱不了关系的,请记得一定要设定好 DNS 的 MX record!可参考 bind - DNS 设定利用 Postfix 抵挡垃圾信

POP3 Service

安装好了 MTA 之后, 那么现在除了使用 mail, mutt 等套件来开之外, 其实是无法使用 Outlook 或是 Thunderbird 等相关的 MUT 来使用 POP 协定收信, 在这个章节, 我们将示范如何让你的 Mail Server 也支援 POP 服务.

我们在此, 使用 CentOS 4 来做示范, 其它如 Redhat Enterprise Linux 4, Fedora Core 1 ~ Fedora Core 3 都可以使用.

以 CentOS 4 来做示范的原因, 是因为他的 POP 套件有所更改, 以前要让系统支援 POP 服务, 只需安装一个 imap 套件, 并修改 /etc/xinetd.d 里的 ipop3 设定档即可, 但自从 Fedora Core 1 开始, 就使用 dovecot 来取代 imap, 当然, 设定方法也有所不同, 不过方便的设, 现在 imap 和 pop 服务都可以在 /etc/dovecot.conf 修改就可以了!

查看有无安装 dovecot

[steven@nbcentos ~]$ rpm -qa | grep dovecot
dovecot-0.99.11-2.EL4.1
[steven@nbcentos ~]$

如果没有安装的话, 只要再次安装就可以了

# rpm -ih dovecot-0.99.11-2.EL4.1.i386.rpm

现在安装完成之后, 如果您只需要很简单的 pop3 服务, 那么只要修改 /etc/dovecot.conf 里的一行档案就 OK 了!

# vi /etc/dovecot.conf
________________________________________________________
# 修改 protocos 参数, 只提供 pop3
protocols = pop3
________________________________________________________

再来, 就启动 dovecot 这个服务, 并看看 port 110 有没有被它 listen

# service dovecot start; netstat -ntulp | grep :110
tcp 0 0 :::110 :::* LISTEN 2282/dovecot
#

Last modified: 07/03/2005
02/26/2005

Index