/*************************************************************************
/*主题:postfix邮件系统的安装与测试
/*
/*原作位置:
/* http://www.hempeldesigngroup.com/embedded/stories/bdgFreeBSDPostfix.html
/*作者不详
/*
/*翻译:Patrick
/*
/*时间:2004-8-5
/*
/*如果大家看到了文中的错误请给我留言,谢谢!
/*************************************************************************
一,导言:
前几篇文章已经让你通过源代码安装了perl-5.8,接下来我们讨论一些认真的事情。我们为什么要在服务器上安装一个邮件系统?
服务器上一些你不是每天需要的东西会变得没有用。你不需要键盘,鼠标,显示器去控制它,因为那些可以由PuTTY通过ssh界面来完成。事实上,你的服务器可能在一个你根本不知道的储藏室中。
谁给我们发来email。你的服务器会把如安全报告或日常系统检测通过邮件发给你。一旦你安装了bug跟踪器,它就会把bug报告或其他有用的信息发给每个小组成员。
所以,为什么不让这个系统默认的sendmail系统运行在FreeBSD上呢?毕竟,它处理着50%的Internet上的email。这是因为一个临时系统的管理员(你)可能很少或没有机会真正去理解晦涩的sendmail配置文件中的文法。所以甚至我们都不用去实验,我们可以用postfix来代替。
这篇文章中,我们会通过源代码来安装postfix,并且讲一些解决构建依存关系的方法。我会给你展示怎样用空客户(Null Client)建立一个邮件,这意味着它不发送或路由任何本地邮件。它只是发送邮件到你的本地邮件服务器或直接发到Internet上。
二,资源:
Postfix的程序有着很广的应用,自然它有自己的网站(www.postfix.org),有非常好的安装简介。
O'Reilly OnLamp网站也有一个比较不错的关于基本安装和配置的文章。(http://www.onlamp.com/pub/a/bsd/2003/08/21/postfix.html)
至于那些想深入研究postfix的朋友,这本O'Relly postfix book(http://www.amazon.com/exec/obidos/ASIN/0596002122/hempeldesigngrou)是最好选择。
三,从CVS安装postfix:
从源代码安装postfix是非常简单的。第一件事是解决port是否需要相关的库或应用。如果你用postfix作为package名在FreeBSD Posts Search页上搜索会非常简单的。这有一个查询链接:
http://www.freebsd.org/cgi/ports.cgi?query=postfix&stype=name
我们真的很幸运,名字中包含postfix的package不是很多。看一下列表,我们知道可用的ports有:
·postfix-2.2.20040504 - which is really called postfix-current
·postfix-2.1.4 - which is really called postfix
不管你是否反对,我最终选择了postfix-current,除非你确实需要最近的更新程序,但对于我们的系统我不确定我们是否真的需要。
检查Requires行我们会发现安装和运行postfix需要pcre-4.5。点击链接你会看到pcre-4.5在devel类中。并且它好象还需要一个同样在devel类中的libtool-1.5.6_1。
简单说,postfix的依存关系如下:
mail/postfix
+- devel/pcre
+- devel/libtool15
现在我们有足够的信息去取回相关的port文件来安装postfix。这是我用来获得postfix的命令,当然要root身份:
setenv CVSROOT :pserver:anoncvs@anoncvs.fr.FreeBSD.org:/home/ncvs
cd /usr
cvs login
cvs checkout -A -P -r RELEASE_4_10_0 ports/devel/libtool15
cvs checkout -A -P -r RELEASE_4_10_0 ports/devel/pcre
cvs checkout -A -P -r RELEASE_4_10_0 ports/mail/postfix
cvs logout
建立postfix就可以简单的输入:
cd /usr/ports/mail/postfix
make install
postfix的安装脚本是交互式的。不要改变任何东西直接标注OK并按return来使用默认信息。在脚本运行时,你会看到这些输出信息(与这篇在多久以前完成有关):
===> postfix-2.0.19,1 depends on shared library: pcre.0 - not found
===> Verifying install for pcre.0 in /usr/ports/devel/pcre
===> pcre-4.5 is marked as broken: unknown LIBTOOL version: 14.
不要紧张,这只是告诉我们需要用libtool15来代替libtool14。所以我们只需把它下载下来,如下:
setenv CVSROOT :pserver:anoncvs@anoncvs.fr.FreeBSD.org:/home/ncvs
cd /usr
cvs login
cvs checkout -A -P -r RELEASE_4_10_0 ports/devel/libtool14
cvs logout
并重新运行build……
cd /usr/ports/postfix
make install
过一会,如果一切比较顺利,你会收到下列提示:
Would you like to activate Postfix in /etc/mail/mailer.conf [n]?
回答y并按回车。然后你会看到如下提示:
You need user "postfix" added to group "mail".
Would you like me to add it [y]?
再回答y并按回车。到安装完成之间都是这样的交互。
四,Post-Tnstallation必须品为postfix:
假设一切安装顺利,所有工作完成,现在我们需要做一些post-install设置在进行下一步之前。
这有一个关于安装程序的一些重要信息的一个拷贝。我们会做些有用的讨论……
If you have postfix configured in your /etc/mail/mailer.conf (answered yes to
the previous question) and would like to enable postfix to start at boot time,
please set these variables in your /etc/rc.conf file:
sendmail_enable="YES"
sendmail_flags="-bd"
sendmail_pidfile="/var/spool/postfix/pid/master.pid"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sendmail_msp_queue_enable="NO"
This will disable Sendmail completely.
Alternatively to the above settings, you can enable postfix to start with
the other local services, for example, after your database server starts if
you need it to be running for postfix. To do this, set in your rc.conf file:
sendmail_enable="NONE"
Then make the following symbolic link:
cd /usr/local/etc/rc.d
ln -s /usr/local/sbin/postfix postfix.sh
我把他们拷贝到我的/etc/rc.conf文件中。
Also, you will want to disable some Sendmail-specific daily maintenance
routines in your /etc/periodic.conf file:
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
这会使实验失败,因为在我的最小安装的服务器上根本没有/etc/periodic.conf文件。此外我还禁止了sendmail在FreeBSD的初始安装中。
If you are using SASL, you need to make sure that postfix has aclearcase/" target="_blank" >ccess to read
the sasldb file. This is accomplished by adding postfix to group mail and
making the /usr/local/etc/sasldb* file(s) readable by group mail (this should
be the default for new installs).
我没用SASL,所以我不用做什么。这就是所有post-install的步骤,现在我们去配置postfix。
五,用空客户(Null Client)配置postfix:
我的用来深入开发的最小化服务器不准备变成一个完全的邮件系统。事实上,它只不过是发过一些邮件给其他人。目前为止我还没有让它收过邮件。一个服务器只是发送邮件在postfix的术语中叫空客户(Null Client)。
所以现在要做的第一件事就是禁止postfix收邮件的能力。你可以通过编辑你的配置文件像这样(http://www.postfix.org/STANDARD_CONFIGURATION_README.html#null_client)来实现这个功能。等等,慢一点。让我们明白这里面真正的意思。特别是有关禁止本地邮件发送的这部分。严密到我们接触的master.cf文件中的什么部分会实现这些事。
这里有一个有关我的master.cf文件中禁止邮件接收和发布的部分的拷贝:
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
#smtp inet n - n - - smtpd
#submission inet n - n - - smtpd
# -o smtpd_etrn_restrictions=reject
#628 inet n - n - - qmqpd
pickup fifo n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - n - - showq
error unix - - n - - error
#local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
看它是如何通过在前面加"#"前缀来注释掉smtp和本地服务的。保存这个文件,现在我们可以开始安装系统其他的部分。
我现在运行我的服务器在我的本地网络上。我有一个Linksys的无线路由来处理所有这个屋子里的传输,并且他连接到我的DSL modem上。我的DSL modem从我当地的ISP中获得IP 地址。
为了让事情更复杂些,我用一个真实的域名,但是它的主机在美国的另一头。最后,我的ISP(和其他很多一样)不会允许发email,除非它可以检查出邮件来源的域名是真实的。
在一个默认安装的postfix上,你需要做三件事来把邮件发送出去。这是我main.cf中相关的段:
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = funkenfanger
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
mydomain = hempeldesigngroup.com
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites. If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
#myorigin = $mydomain
myorigin = $mydomain
我所做的就是为:myhostname, mydomain和myorigin加上合理的值。其中最重要的是myorigin,因为它需要一个真实的域名否则你的邮件主机会退回它或更严重的默默的忽略它。
所以,重申一遍,只需设置myhostname, mydomain和myorigin,并确定myorigin是一个真实的域。如果你不知道现在应该填什么,用example.com来解决。
六,启动并测试postfix:
坚持,我们马上就完成了。如果从开始这篇文章到现在你还没有重启的的系统(你为什么要重启)你就需要手工启动postfix。如下:
postfix start
任何时候你改变了当前运行的postfix的设置时,你需要让postfix知道,它才能解析这些变化,如下:
postfix reload
你可以给你自己发些邮件作为测试。我假设当你读到这时,你已经去查看你的邮件了。我没有在机器上通过GUI安装,我是通过PuTTY访问的它,所以我该怎么发送email呢?
回到早期的Internet,这些石器时代的hacker可以通过命令行接口去发邮件!是的,这是真的!
这有一个关于我的测试邮件会话的抄本:
funkenfanger# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/mail/sysadmin": 0 messages
& m rhempel@bmts.com
Subject: Test Message
Postfix is up and running on funkenfanger!
.
EOT
& q
funkenfanger#
真的非常原始,哈。"&"是邮件系统的提示符。"m" 后面跟一个邮件地址表示开始一个邮件。一个"."开头的空行表示邮件的结尾,它会让你返回到"&"提示符,"q"把我们带回到系统标准提示符。
当然,你会用自己的邮件地址来测试你的postfix。虽然我非常高兴收到你们的邮件,但是我真的不想收到所有你们的测试邮件。
一旦你返回到系统提示符,你就可以用如下方法检查邮件是否发出去了:
funkenfanger# mailq
Mail queue is empty
funkenfanger#
In a few minutes, fire up your email client and check your mail. You
should get an email from "Charlie Root" with the subject and body you just
typed in. If not, yo umight want to check the last few lines of
/var/log/maillog to see if there are any error messages that can
help you figure out what went wrong.
Well, that's it! We're done with the postfix setup. You'll
be getting at least two emails a day from your server. One is the daily run
output, and the other is the security run output. They'll give you a basic
idea of how your box is doing, how many times other folks tried to hack
it, and other useful stuff like disk usage statistics.
Now we can move on to getting Apache 2 up and running. See you at the next
article.
Postfix邮件系统的初级文章