📄 1417.html
字号:
<h1><a name="a.7"></a>7. 安装Postfix</h1>
<h2><a name="a.7.1"></a>7.1. 下载</h2>
<p> <a href="javascript:if(confirm('http://www.postfix.org/ftp-sites.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.postfix.org/ftp-sites.html'" tppabs="http://www.postfix.org/ftp-sites.html" target="_top">http://www.postfix.org/ftp-sites.html</a></p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td> <p>[root@mail root]# <span class="type">cd /usr/src</span></p>
<p>[root@mail src]# <span class="type">wget <a href="javascript:if(confirm('http://postfix.energybeam.com/source/official/postfix-2.0.16.tar.gz \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://postfix.energybeam.com/source/official/postfix-2.0.16.tar.gz'" tppabs="http://postfix.energybeam.com/source/official/postfix-2.0.16.tar.gz">http://postfix.energybeam.com/source/official/postfix-2.0.16.tar.gz</a>
</span> </p></td>
</tr>
</tbody></table>
<h2><a name="a.7.2"></a>7.2. 编译与安装</h2>
<p> 如果你的系统上原来有sendmail,先将其停止并将其文件改名:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td> <p>[root@mail src]# <span class="type">/etc/init.d/sendmail stop</span></p>
<p>[root@mail src]# <span class="type">chkconfig --level 0123456 sendmail
off <br>
</span>[root@mail src]# <span class="type">mv /usr/bin/newaliases /usr/bin/newaliases.orig</span></p>
<p>[root@mail src]# <span class="type">mv /usr/bin/mailq /usr/bin/mailq.orig</span></p>
<p>[root@mail src]# <span class="type">mv /usr/sbin/sendmail /usr/sbin/sendmail.orig</span></p>
</td>
</tr>
</tbody></table>
<p> </p>
<p> 然后添加两个组:postfix和maildrop和一个用户:postfix</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td> <p>[root@mail src]# <span class="type">groupadd -g 400 postfix</span></p>
<p>[root@mail src]# <span class="type">groupadd -g 401 postdrop</span></p>
<p>[root@mail src]# <span class="type">useradd -u 400 -g 400 -c postfix
-M -d/no/where -s/no/shell postfix</span></p>
</td>
</tr>
</tbody></table>
<p> 这里的组和用户的ID是系统中未使用的ID。</p>
<p> </p>
<p> 编译Postfix,并支持mysql和sasl:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td> <p>[root@mail src]# <span class="type">tar -xvzf postfix-2.0.16.tar.gz</span></p>
<p>[root@mail src]# <span class="type">cd postfix-2.0.16</span></p>
<p> </p>
<p>[root@mail postfix-2.0.16]# <span class="type">make -f Makefile.init
makefiles \</span></p>
<p>> <span class="type">'CCARGS=-DUSE_SASL_AUTH -DHAS_MYSQL -I/usr/include/mysql
-I/usr/include/sasl' \</span></p>
<p>> <span class="type">'AUXLIBS=-L/usr/lib/mysql -L/usr/lib/sasl2
-lmysqlclient -lsasl2 -lz -lm'</span></p>
<p>[root@mail postfix-2.0.16]# <span class="type">make install</span></p>
</td>
</tr>
</tbody></table>
<p> 安装时,安装程序会提问一些问题,可以直接按回车采用默认值。</p>
<p> 这里切记要指定正确的SASL2的INCLUDE和LIB位置。由于现在很多linux发行版上都已经带有了sasl,如果不指定的话,很可能会使用了不同版本的头文件和库,在这种情况下,每次连接SMTP时,smtpd就会发生致命错误“Fatal:
SASL per-connection server init...”而崩溃。</p>
<p> </p>
<p> 给postfix用户做一个系统别名,并将超级用户的邮箱转发到一个普通用户。使用/etc/postfix/aliases别名数据库:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td><p>[root@mail postfix-2.0.16]# <font color="#ff0000">cd /etc/postfix</font></p>
<p>[root@mail postfix]# <span class="type">echo 'root: virtualuser@cngnu.org'
>> /etc/postfix/aliases</span></p>
</td>
</tr>
</tbody></table>
<p> 生成/etc/postfix/aliases别名数据库:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td>[root@mail postfix]# <span class="type">postalias /etc/postfix/aliases</span></td>
</tr>
</tbody></table>
<p> 生成/etc/postfix/virtual的DB库:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td>
<p>[root@mail postfix]# <span class="type">postmap virtual</span></p></td>
</tr>
</tbody></table>
<p> 保留db格式的virtual库是为了系统临时增加转发方便起见。</p>
<h2><a name="a.7.3"></a>7.3. 配置</h2>
<p> 修改/etc/postfix/master.cf中的关于cyrus的配置,(cyrus的命令行和以前有不兼容的地方,确保你的cyrus的参数如下使用了-r
${sender}参数):</p>
<table width="100%" border="0" bgcolor="#ccffcc">
<tbody><tr>
<td><p>[root@mail postfix]# <span class="type">vi master.cf</span></p>
</td>
</tr>
</tbody></table>
<p> 将如下两行:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td bgcolor="#ffffcc"> cyrus unix - n n - - pipe<br>
user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}</td>
</tr>
</tbody></table>
<p> 修改为:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td bgcolor="#ffffcc"> cyrus unix - n n - - pipe<br>
user=cyrus argv=/usr/cyrus/bin/deliver -e -r ${sender} -m ${extension}
${user}</td>
</tr>
</tbody></table>
<p> 这里要把cyrus的路径修改为你的cyrus实际安装路径(我们下面会将cyrus-imap安装到/usr/cyrus)。 记着user=...这行前面是以空格缩进的(是上一行的续行)。</p>
<p> </p><table width="100%" border="0" bgcolor="#ccffcc">
<tbody><tr>
<td><p>[root@mail postfix]# <span class="type">vi main.cf</span></p>
</td>
</tr>
</tbody></table>
<p> </p>
<p> 修改/etc/postfix/main.cf的配置:</p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td bgcolor="#ffffcc">
<p>myhostname = mail.cngnu.org</p>
<p>mydomain = cngnu.org</p>
<p>myorigin = $mydomain</p>
<p>mydestination = $mydomain,$myhostname</p>
<p>mynetworks_style = host</p>
<p> </p>
<p>alias_maps = hash:/etc/postfix/aliases</p>
<p>alias_database = hash:/etc/postfix/aliases</p>
<p> </p>
<p>home_mailbox = Maildir/</p>
<p></p>
<p> </p>
<p>mailbox_transport = cyrus</p>
<p>fallback_transport = cyrus</p>
<p> </p>
<p>virtual_maps = hash:/etc/postfix/virtual,mysql:/etc/postfix/virtual.mysql</p>
<p> </p>
<p>smtpd_sasl_auth_enable = yes</p>
<p>broken_sasl_auth_clients = yes</p>
<p>smtpd_sasl_security_options = noanonymous</p>
<p> </p>
<p>smtpd_recipient_restrictions = <br>
permit_mynetworks,<br>
permit_sasl_authenticated,<br>
check_recipient_access mysql:/etc/postfix/filter.mysql,<br>
reject_invalid_hostname,<br>
reject_non_fqdn_hostname,<br>
reject_unknown_sender_domain,<br>
reject_non_fqdn_sender,<br>
reject_non_fqdn_recipient,<br>
reject_unknown_recipient_domain,<br>
reject_unauth_pipelining,<br>
reject_unauth_destination,<br>
permit</p>
<p></p>
<p></p></td>
</tr>
</tbody></table>
<p> 如果希望支持更多的虚拟域,可以在mydestination参数后面加上你所要支持的域即可。</p>
<p> 通过virtual和virtual.mysql为系统提供了邮箱本地查询表。</p>
<p> 使用了SASL来进行SMTP发信认证。</p>
<p> 通过smtpd_recipient_restrictions提供了基本的反垃圾邮件功能。首先允许本地网络(这里是本机)和通过SASL认
证的用户可以使用本服务器发信;然后检查每个用户的全局邮件过滤功能是否打开,如果关闭则不进行后面的反垃圾邮件检查;其后是一些Postfix支持的基
本反垃圾邮件功能。</p>
<p> 创建/etc/postfix/virtual.mysql,它提供了本地用户和邮件转发功能。FORWARD字段默认是指向用户的存储邮箱名
的(Cyrus-IMAP所管理的邮箱名称),即进行本地投递;如果FORWARD字段是另外一个用户名或者邮件地址,则该邮件被转发到别的用户或其它邮
件地址。对于</p>
<ul>
<li>非虚拟域邮箱:其存储邮箱与用户名相同</li>
<li>虚拟域邮箱:为了支持多个域,考虑到不同的域可能拥有相同的用
户名(本地部分),所以使用邮件全称作为用户的登录名(POP/IMAP的登录名和SMTP认证的登录名),但是由于Cyrus-IMAP不直接支持虚拟
域,不能在邮件的本地部分包含“@”,所以实际的存储邮箱名把“@”替换为“~”。</li>
</ul>
<table width="100%" border="0" bgcolor="#ccffcc">
<tbody><tr>
<td><p>[root@mail postfix]# <span class="type">vi virtual.mysql</span></p></td>
</tr>
</tbody></table>
<p> </p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td bgcolor="#ffffcc">
<p>#</p>
<p># mysql config file for alias lookups on postfix</p>
<p>#</p>
<p> </p>
<p># the user name and password to log into the mysql server</p>
<p>hosts = localhost</p>
<p>user = mail</p>
<p>password = secret</p>
<p> </p>
<p># the database name on the servers</p>
<p>dbname = mail</p>
<p> </p>
<p># the table name</p>
<p>table = USER</p>
<p> </p>
<p>select_field = FORWARD</p>
<p>where_field = USERNAME</p>
<p>additional_conditions = and STATUS = 1 limit 1</p>
</td>
</tr>
</tbody></table>
<p> </p>
<table width="100%" border="0" bgcolor="#ccffcc">
<tbody><tr>
<td><p>[root@mail postfix]# <span class="type">vi filter.mysql</span></p></td>
</tr>
</tbody></table>
<p> </p>
<table border="0" width="100%" bgcolor="#ccffcc">
<tbody><tr>
<td bgcolor="#ffffcc">
<p>#</p>
<p># mysql config file for filter flag on postfix</p>
<p>#</p>
<p> </p>
<p># the user name and password to log into the mysql server</p>
<p>hosts = localhost</p>
<p>user = mail</p>
<p>password = secret</p>
<p> </p>
<p># the database name on the servers</p>
<p>dbname = mail</p>
<p> </p>
<p># the table name</p>
<p>table = USER</p>
<p> </p>
<p>select_field = FILTER</p>
<p># OK : ignore filter</p>
<p># DUNNO : filter </p>
<p>where_field = MAIL </p>
<p>additional_conditions = and STATUS = 1 limit 1</p></td>
</tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -