个人工具

“UbuntuHelp:PostfixCompleteVirtualMailSystemHowto/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
Postfix 映射如何实现?
Postfix 映射如何实现?
第107行: 第107行:
 
|postmaster:||root
 
|postmaster:||root
 
|}
 
|}
 +
 
{|border="1" cellspacing="0"
 
{|border="1" cellspacing="0"
| https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=IconHint.png || Usually we do not use colon(:) in LHS for Postfix and this has been done for backward compatibility with historical reasons. The local alias file is a special file that is compiled with '''newaliases''' command but not with usual Postfix mapping command '''postmap'''
+
| https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=IconHint.png || 过去为了保证回溯能力使用冒号(:),现在Postfix中通常我们不在LHS里使用。本地别名文件它是一个用 '''newaliases''' 命令编译的而不是用通常的Postfix 映射命令'''postmap'''编译的特别文件。
 
|}
 
|}
With a basic default Postfix installation we use text file for mappings. We write the mappings into this file and then convert it into a '''hash''' file using '''postmap''' command so Postfix can look up items quickly. For example, assume that we need to map our virtual mailboxes in a file called '''<code><nowiki>/etc/Postfix/virtual_mailboxes</nowiki></code>'''. The syntax of this file look like:
+
 
 +
Postfix基本默认安装中,我们为映射建立一个文本文件。我们把映射写入文本文件然后用'''postmap'''命令把此文本文件转换成一个 '''hash''' 文件。以便Postfix 能快速查到此条目。例如,假设我们在一个文件'''<code><nowiki>/etc/Postfix/virtual_mailboxes</nowiki></code>'''中映射我们的虚拟邮箱。文件结构如下:
 
<pre><nowiki>
 
<pre><nowiki>
 
info@domain1.com sigiri
 
info@domain1.com sigiri
 
info@domain2.com kala
 
info@domain2.com kala
 
</nowiki></pre>
 
</nowiki></pre>
You may have noticed that we don't have colon(:) in the '''LHS''' of the mappings file
+
你可能已经注意到在映射文件的左手边“左手边”我们没有使用冒号(:)。然后你需要运行:
Then you need to run:
+
 
<pre><nowiki>
 
<pre><nowiki>
 
postmap /etc/postfix/virtual_mailboxes
 
postmap /etc/postfix/virtual_mailboxes
 
</nowiki></pre>
 
</nowiki></pre>
You can access this mappings in the Postfix configuration file by including the following line:
+
你可以通过在Postfix配置文件中加入下面这行命令来访问映射:
 
<pre><nowiki>
 
<pre><nowiki>
 
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes
 
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes
 
</nowiki></pre>
 
</nowiki></pre>
 
In our setup, we will replace this text mapping files with MySQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. Since database tables can and usually contain more than just two columns you will need to tell Postfix which database column is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration file which will look something like this:
 
In our setup, we will replace this text mapping files with MySQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. Since database tables can and usually contain more than just two columns you will need to tell Postfix which database column is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration file which will look something like this:
<pre><nowiki>
+
在我们的安装过程中,我们将会用MySQL表来替换这个映射文本文件。因为我们的目的是更灵活,更健壮,更易升级的控制数据。数据库表可以包含两列或更多的列。当然你需要告诉Postfix 数据库中哪一列是LHS,哪一列是RHS。我们可以建一个下列样子的配置文件来完成这一任务。<pre><nowiki>
 
user = postfix
 
user = postfix
 
password = YJiNLQtubgnOE
 
password = YJiNLQtubgnOE

2008年7月5日 (六) 10:12的版本

摘要

在网上有许多HOWTO来描述如何创建邮件服务器,不同的人对MTAs有不同选择.有的人喜欢用Qmail有些人喜欢用Postfix和Exim.很长一段时间内我都喜欢用Qmail来做为我的MTA,它是一个极好的软件.但是Qmail是需要许可证的,没有方便用户在他们所习惯使用的平台上简单使用的编译好的可执行代码。虽然安装Qmail并不是那么困难,但是用户需要应用各种各样的补丁和技巧等完成完全安装。由于上述原因,并且它一旦安装完毕,运行情况还是令人满意的。所以Qmail成为了很多电脑怪杰的最爱。Qmail的缺点是升级困难,因为每次都需要编译源码并安装。综上所述,决定使用Postfix:一种像Qmail一样快速和安全的MTA,并且易与在任何Linux版本上安装和配置Basic System . Postfix 有许多附加功能并且支持Maildir 邮箱格式, PostgreSQL 后台MySQL很容易存储和管理虚拟域。这里将为希望使用Ubuntu Linux作为服务平台的ISPs,虚拟主机提供商,单个公司等安装一个完整的包含发病毒和垃圾邮件虚拟邮件域系统。

系统概述

开始安装之前,必须了解我们的系统是如何工作的。一个虚拟邮件系统必须能够控制许多域,这些域有很多用户并且用户使用不同接口。当你在同一个邮件系统中控制多个域的时候,虚拟邮件系统会提出一些管理问题。我们必须用我们的技术回答这些问题。例如,你有下面的问题需要回答。

  • 如果有两个用户在不同的域中使用了同一个用户名,你怎么办?
  • 如果你提供了IMAP访问和smtp认证,如何将不同的认证值守程序组合在同一个系统中呢?
  • 如何保证构成系统的各个组件的安全性?
  • 如果用户要求使用自己的垃圾邮件过滤策略,我们应该如何处理?
  • 每一个域的管理员要求使用基于web接口来管理他们的邮件域。
  • 如何为postfix建立一个基于web的管理系统。
  • 每个用户要求基于web接口改变邮件帐户密码。
  • 如何备份用户帐号数据库及灾难恢复。
  • 利用ssl实现传输层安全。
  • 控制任何一个域的邮件列表。

你如何一并处理以上提出的所有问题?不要担心,我会逐个回答这些问题。高高兴兴地继续读下去。

使用这个系统你会得到什么

  • 基于web的系统管理
  • 域的数量没有限制
  • 与操作系统用户无关的虚拟邮件用户
  • 特定域用户名
  • 邮箱容量分配
  • 通过web访问邮件帐号
  • 基于web接口改变用户密码
  • 支持IMAP,POP3
  • 自动回复
  • SMTP认证保证安全中转
  • SSL保证传输层安全
  • 强力垃圾邮件过滤
  • 反病毒过滤
  • 日志分析

必备软件包

我们系统必须使用下列程序包,大多数可以在APT中找到。在安装小节部分,你会学会如何安装和配置他们。

整体架构图

下面图示了我们建立的整体架构,如果你仔细观察这张图,你能从图上了解整个系统。

PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=CompleteSetupOverview.png

在我们的系统中:

  • Postfix:负责通过MTA接收和发送emails。
  • MySQL :数据库服务器保存postfix的控制信息。主要涉及用户信息,域信息,email转发及密码
  • Courier :像postfix一样的独立的邮件服务,我们利用它的pop3/IMAP服务部件使用户访问邮箱。
  • SASL:简单认证与安全层 。你的邮件服务仅信任内部地址,所以对使用外部网络地址的用户进行身份认证。通过SASL对SMTP认证使你的邮件服务信任他们。

Postfix 映射如何实现?

理解Postfix 如何实现映射非常重要。我们系统的核心就是Postfix 映射,在这里我们主要讨论这个问题,不要跳过这个部分。

映射通常的字面意义是:在两个值之间建立关系。我们在Postfix中必须映射的是邮件用户帐号或邮件地址。例如Postfix使用的本地别名与本地系统用户映射文件:/etc/aliases, 显示了映射结构:

postmaster: root

这一映射结构导致所有发往postmaster@yourdomain.tld 的信件都被重定向到 root@yourdomain.tld. 我们将上面的映射结构分成左手边LHS 和右手边RHS。RHS和LHS 是在映射关系中常用的缩略语。下表更清晰的说明了映射关系。

LHS RHS
postmaster: root
PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=IconHint.png 过去为了保证回溯能力使用冒号(:),现在Postfix中通常我们不在LHS里使用。本地别名文件它是一个用 newaliases 命令编译的而不是用通常的Postfix 映射命令postmap编译的特别文件。

Postfix基本默认安装中,我们为映射建立一个文本文件。我们把映射写入文本文件然后用postmap命令把此文本文件转换成一个 hash 文件。以便Postfix 能快速查到此条目。例如,假设我们在一个文件/etc/Postfix/virtual_mailboxes中映射我们的虚拟邮箱。文件结构如下:

info@domain1.com sigiri
info@domain2.com kala

你可能已经注意到在映射文件的左手边“左手边”我们没有使用冒号(:)。然后你需要运行:

postmap /etc/postfix/virtual_mailboxes

你可以通过在Postfix配置文件中加入下面这行命令来访问映射:

virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes

In our setup, we will replace this text mapping files with MySQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. Since database tables can and usually contain more than just two columns you will need to tell Postfix which database column is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration file which will look something like this:

在我们的安装过程中,我们将会用MySQL表来替换这个映射文本文件。因为我们的目的是更灵活,更健壮,更易升级的控制数据。数据库表可以包含两列或更多的列。当然你需要告诉Postfix 数据库中哪一列是LHS,哪一列是RHS。我们可以建一个下列样子的配置文件来完成这一任务。
user = postfix
password = YJiNLQtubgnOE
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'

For the purposes of this discussion, lets assume this is saved in a file called /etc/postfix/mysql_virtual_mailbox_maps.cf. You would then be able to use this mapping in postfix using the following entry in main.cf file.

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

The fields in this configuration file are the user that needs to connect to the MySQL database, password of that MySQL user, dbname, the name of the MySQL database, table ,the name of the table in MySQL database and hosts, the name of the server that MySQL runs on. Postfix uses the this configuration file as a guide on how to use the database table as a mapping similar to the mapping file with two fields described above. The LHS of the mapping is defined as where_field and the RHS is defined as select_field. In this example we will map the maildir column to the username column. Using the configuation, Postfix constructs a SQL query something like select maildir from postfix.mailbox where username='johndoe' to lookup the maildir for a given username. The following table breaks this distiction out:

LHS RHS
where_field select_field
username maildir