虚拟用户和域与Postfix,Express,MySQL和松鼠邮件(Debian Wheezy)

本教程是Falko Timme的版权所有(c)2013。 它来自Christoph Haas的教程,您可以在http://workaround.org找到。 您可以根据知识共享许可2.5或更高版本免费使用本教程。

本文档介绍如何安装基于虚拟用户和域的Postfix邮件服务器,即MySQL数据库中的用户和域。 我还将展示Courier(Courier-POP3,Courier-IMAP)的安装和配置,以便Courier可以对Postfix使用的相同的MySQL数据库进行身份验证。

所得到的Postfix服务器能够使用SMTP-AUTHTLS配额 (默认情况下,配额不会内置到Postfix中),我将显示如何适当修补Postfix。 密码以加密形式存储在数据库中(我发现大多数文档都是处理明文密码,这是一个安全风险)。 除此之外,本教程还介绍了AmavisdSpamAssassinClamAV的安装 ,以便电子邮件扫描垃圾邮件和病毒。 我还将展示如何将SquirrelMail安装为Webmail界面,以便用户可以读取和发送电子邮件并更改密码。

这种“虚拟”设置(MySQL数据库中的虚拟用户和域)的优点是,它比基于“真实”系统用户的设置性能要好得多。 通过此虚拟设置,您的邮件服务器可以处理数千个域和用户。 此外,更容易管理,因为您只需在添加新用户/域或编辑现有的MySQL数据库时处理MySQL数据库。 没有更多的postmap命令来创建数据库文件,不需要再重新加载Postfix等。对于MySQL数据库的管理,您可以使用基于Web的工具,如phpMyAdmin,它也将安装在这个howto中。 第三个优点是用户使用电子邮件地址作为用户名(而不是用户名+电子邮件地址),这更容易理解和记住。

这是一个实践指南; 它不包括理论背景。 他们在网络上的许多其他文档中被处理。

本文档不附带任何形式的保证! 我想说,这不是设立这样一个制度的唯一办法。 实现这一目标有很多方法,但这是我所采取的方式。 我不会保证这将为您工作!

1初步说明

本教程基于Debian Wheezy,所以您应该在继续本教程之前设置一个基本的Debian Wheezy服务器安装。 系统应该有一个静态IP地址。 我在本教程中使用192.168.0.100作为我的IP地址,将server1.example.com用作主机名。

/ bin / sh的符号链接到/ bin / bash是非常重要的...

dpkg-reconfigure dash

使用破折号作为默认系统shell(/ bin / sh)? < - 不

...并禁用AppArmor:

/etc/init.d/apparmor stop 
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2安装Postfix,Courier,Saslauthd,MySQL,phpMyAdmin

要安装Postfix,Courier,Saslauthd,MySQL和phpMyAdmin,我们只需运行

apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass

你会被问到几个问题:

一般类型的邮件配置: < - 网站
系统邮件名称: < - server1.example.com
MySQL“root”用户的新密码: < - yourrootsqlpassword
重复MySQL“root”用户的密码: < - yourrootsqlpassword
创建基于Web的管理目录? < - 不
需要SSL证书 < - 好的
Web服务器自动重新配置: < - apache2
使用dbconfig-common配置phpmyadmin的数据库? < - 不

3应用配额补丁到Postfix

我们必须得到Postfix源代码,使用配额补丁进行修补,构建新的Postfix .deb包并安装这些.deb包:

apt-get build-dep postfix
cd /usr/src
apt-get source postfix

(确保在以下命令中使用正确的Postfix版本我已经安装了Postfix 2.9.6,您可以通过运行

postconf -d | grep mail_version

输出应如下所示:

root@server1:/usr/src# postconf -d | grep mail_version
mail_version = 2.9.6
milter_macro_v = $mail_name $mail_version
root@server1:/usr/src#

wget http://vda.sourceforge.net/VDA/postfix-vda-v11-2.9.6.patch
cd postfix-2.9.6
patch -p1 < ../postfix-vda-v11-2.9.6.patch

下一个打开debian /规则并将DEB_BUILD_HARDENING1更改为0

vi debian/rules
[...]
export DEB_BUILD_HARDENING=0
[...]

如果您不这样做,您的构建将失败并显示以下错误消息:

maildir.c: In function âdeliver_maildirâ:
maildir.c:974:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:977:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:983:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:986:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c: In function âsql2fileâ:
maildir.c:404:25: warning: ignoring return value of âreadâ, declared with attribute warn_unused_result [-Wunused-result]
maildir.c:417:26: warning: ignoring return value of âwriteâ, declared with attribute warn_unused_result [-Wunused-result]
cc1: some warnings being treated as errors
make: *** [maildir.o] Error 1
make: Leaving directory `/usr/src/postfix-2.9.3/src/virtual'
make[1]: *** [update] Error 1
make[1]: Leaving directory `/usr/src/postfix-2.9.3'
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
root@server1:/usr/src/postfix-2.9.3#

现在我们可以构建新的Postfix .deb包:

dpkg-buildpackage

现在我们去一个目录,这就是新的.deb包的创建地方:

cd ..

命令

ls -l

显示可用包:

root@server1:/usr/src# ls -l
total 8400
drwxr-xr-x  4 root root    4096 May  7 01:24 linux-headers-3.2.0-4-amd64
drwxr-xr-x  4 root root    4096 May  7 01:24 linux-headers-3.2.0-4-common
lrwxrwxrwx  1 root root      23 Jun 24  2012 linux-kbuild-3.2 -> ../lib/linux-kbuild-3.2
drwxr-xr-x 18 root root    4096 Jul  1 21:13 postfix-2.9.6
-rw-r--r--  1 root root    3561 Jul  1 21:13 postfix_2.9.6-2_amd64.changes
-rw-r--r--  1 root root 1529980 Jul  1 21:13 postfix_2.9.6-2_amd64.deb
-rw-r--r--  1 root root  254432 Jul  1 21:12 postfix_2.9.6-2.diff.gz
-rw-r--r--  1 root root    1492 Jul  1 21:12 postfix_2.9.6-2.dsc
-rw-r--r--  1 root root 3767309 Mar 11 15:03 postfix_2.9.6.orig.tar.gz
-rw-r--r--  1 root root  255470 Jul  1 21:13 postfix-cdb_2.9.6-2_amd64.deb
-rw-r--r--  1 root root  367774 Jul  1 21:13 postfix-dev_2.9.6-2_all.deb
-rw-r--r--  1 root root 1294258 Jul  1 21:13 postfix-doc_2.9.6-2_all.deb
-rw-r--r--  1 root root  264196 Jul  1 21:13 postfix-ldap_2.9.6-2_amd64.deb
-rw-r--r--  1 root root  257322 Jul  1 21:13 postfix-mysql_2.9.6-2_amd64.deb
-rw-r--r--  1 root root  257376 Jul  1 21:13 postfix-pcre_2.9.6-2_amd64.deb
-rw-r--r--  1 root root  257476 Jul  1 21:13 postfix-pgsql_2.9.6-2_amd64.deb
-rw-r--r--  1 root root   55009 May  7 08:47 postfix-vda-v11-2.9.6.patch
drwxr-xr-x  7 root root    4096 May  7 01:24 virtualbox-guest-4.1.18
root@server1:/usr/src#

选择postfixpostfix-mysql包,并安装它们如下所示:

dpkg -i postfix_2.9.6-2_amd64.deb postfix-mysql_2.9.6-2_amd64.deb

4为Postfix / Courier创建MySQL数据库

现在我们创建一个名为mail的数据库:

mysqladmin -u root -p create mail

接下来,我们去MySQL shell:

mysql -u root -p

在MySQL shell上,我们用邮件数据库中具有SELECT,INSERT,UPDATE,DELETE权限的passwort mail_admin_password (替换为自己的密码)创建用户mail_admin 。 该用户将被Postfix和Courier用于连接到邮件数据库:

GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost' IDENTIFIED BY 'mail_admin_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost.localdomain' IDENTIFIED BY 'mail_admin_password';
FLUSH PRIVILEGES;

仍然在MySQL shell上,我们创建Postfix和Courier所需的表:

USE mail;
CREATE TABLE domains (
domain varchar(50) NOT NULL,
PRIMARY KEY (domain) )
ENGINE=MyISAM;
CREATE TABLE forwardings (
source varchar(80) NOT NULL,
destination TEXT NOT NULL,
PRIMARY KEY (source) )
ENGINE=MyISAM;
CREATE TABLE users (
email varchar(80) NOT NULL,
password varchar(20) NOT NULL,
quota INT(10) DEFAULT '10485760',
PRIMARY KEY (email)
) ENGINE=MyISAM;
CREATE TABLE transport (
domain varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) ENGINE=MyISAM;
quit;

你可能已经注意到,随着戒烟; 命令我们已经离开了MySQL shell,并回到了Linux shell。

表将存储Postfix应接收(例如example.com )的电子邮件的每个虚拟域。

example.com

发表用于将一个电子邮件地址别名,例如将[email protected]电子邮件转发[email protected]

资源 目的地
[email protected] [email protected]

用户表存储所有虚拟用户(即,电子邮件地址,因为电子邮件地址和用户名相同)和密码( 加密形式!)和每个邮箱的配额值(在本示例中,默认值为10485760字节意味着10MB)。

电子邮件 密码 配额
[email protected] No.4E4skNvGa (加密形式的“秘密”) 10485760

运输表是可选的,适用于高级用户。 它允许将单个用户,整个域或所有邮件的邮件转发到另一个服务器。 例如,

运输
example.com smtp:[1.2.3.4]

将通过smtp协议将所有em.com的电子邮件转发到IP地址为1.2.3.4的服务器(方括号[]表示“不查找MX DNS记录”)(这对IP地址有意义。 。)如果您使用完全限定域名(FQDN),则不要使用方括号。

BTW,(我假设您的邮件服务器系统的IP地址为192.168.0.100 ),您可以通过http://192.168.0.100/phpmyadmin/在浏览器中访问phpMyAdmin并以mail_admin身份登录。 那么你可以看看数据库。 以后可以使用phpMyAdmin管理邮件服务器。

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏