邮件服务器配置

邮件服务器配置

postfix+dovecot+mysql+ssl

配置主要是根据该网站上的步骤进行的,自己略做改动,参考文献:

postfix配置参数

How To Configure a Mail Server Using Postfix, Dovecot, MySQL, and SpamAssassin

Postfix – Hosting Multiple Domains with Virtual Accounts

Postfix and Dovecot LMTP

主要遇到的问题和解决过程:

postfix部分

编译命令(这是我最初的编译命令,后来在使用过程中遇到了一些问题,有所修改):

[server@a]#make -f Makefile.init makefiles shared=yes dynamicmaps=yes CCARGS=”-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl” AUXLIBS=”-L/usr/local/BerkeleyDB/lib -ldb -L/usr/lib64/sasl2 -lsasl2″ AUXLIBS_MYSQL=”-L/usr/local/mysql/lib -lmysqlclient -lz -lm”

[server@a]#make

Q

[root@blog postfix-3.3.1]# make -f Makefile.init makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include’ ‘AUXLIBS_MYSQL=-L/usr/local/mysql/lib -lmysqlclient -lz -lm’

make -f Makefile.in MAKELEVEL= Makefiles

(echo “# Do not edit — this file documents how Postfix was built for your machine.”; /bin/sh makedefs) >makedefs.tmp

No <db.h> include file found.

Install the appropriate db*-devel package first.

make: *** [Makefiles] Error 1

make: *** [makefiles] Error 2

 

A:

(1)该错误是提示缺少Berkeley DB(现在阶段已经使用db5了),使用CCARGS=”-DNO_DB”编译参数,选择不使用Berkeley DB。[root@blog postfix-3.3.1]# make -f Makefile.init makefiles ‘CCARGS=-DNO_DB -DHAS_MYSQL -I/usr/local/mysql/include’ ‘AUXLIBS_MYSQL=-L/usr/local/mysql/lib -lmysqlclient -lz -lm’

Q

dict_db.c:758:2: error: #error “Unsupported Berkeley DB version”

A:

安装装db5-devel(Berkeley DB,postfix官方文档上的链接是指向oracle的,最近版本是18.x.x,安装后编译postfix会提示“不支持该版本”,根据网上找到的提示我查看了./postfix-3.3.1/src/util/dict_db.c文件,似乎postfix3.3.x只支持到版本6,而oracle网站上是不提供5、6版本。我用的发行版本是CentOS Linux release 7.5.1804,源安装只有db5。)yum install libdb,提示已经是最近版本,然后yum install libdb-devel

Q
/var/log/messages中提示如下错误:
postfix/smtpd[14519]: sql_select option missing
postfix/smtpd[14519]: auxpropfunc error no mechanism available
A:

分析:
由于没配置cyrus-sasl-sql,所以会有这个错误提示!
解决方法:
卸载:cyrus-sasl-sql
Q
/var/log/messages中提示如下错误:
postfix/smtpd[14459]: auxpropfunc error invalid parameter supplied
A:

分析:
由于没配置cyrus-sasl-ldap,所以会有这个错误提示!
解决方法:
卸载:cyrus-sasl-ldap

Q:不能发邮件,日志如下:

Sep 28 10:34:49 [localhost] postfix/smtpd[92778]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled

Sep 28 10:34:49 [localhost] postfix/smtpd[92778]: warning: TLS has been selected, but TLS support is not compiled in

Sep 28 10:34:50 [localhost] postfix/smtpd[92778]: connect from unknown[60.219.151.226]

Sep 28 10:34:50 [localhost] postfix/trivial-rewrite[92782]: warning: do not list domain 5x44.cn in BOTH mydestination and virtual_mailbox_domains

Sep 28 10:34:50 [localhost] postfix/smtpd[92778]: warning: unknown smtpd restriction: "reject_unauth_destionation"

Sep 28 10:34:50 [localhost] postfix/smtpd[92778]: NOQUEUE: reject: RCPT from unknown[60.219.151.226]: 451 4.3.5 Server configuration error; from=<hank@5x44.cn> to=<skiron_liu@163.com> proto=ESMTP helo=<eleven-PC>

Sep 28 10:34:50 [localhost] postfix/cleanup[92784]: 66C2481BFC: message-id=<20180928023450.66C2481BFC@mail.5x44.cn>

Sep 28 10:34:50 [localhost] postfix/qmgr[92495]: 66C2481BFC: from=<double-bounce@mail.5x44.cn>, size=850, nrcpt=1 (queue active)

Sep 28 10:34:50 [localhost] postfix/smtpd[92778]: disconnect from unknown[60.219.151.226] ehlo=1 mail=1 rcpt=0/1 quit=1 commands=3/4

Sep 28 10:34:50 [localhost] postfix/smtpd[92778]: connect from unknown[180.76.51.216]

Sep 28 10:34:50 [localhost] postfix/smtp[92786]: warning: host mail.5x44.cn[180.76.51.216]:25 greeted me with my own hostname mail.5x44.cn

Sep 28 10:34:50 [localhost] postfix/smtp[92786]: warning: host mail.5x44.cn[180.76.51.216]:25 replied to HELO/EHLO with my own hostname mail.5x44.cn

A:

分析,日志有两条警告,导致不能发邮件的原因是“warning: TLS has been selected, but TLS support is not compiled in”这条警告。重新看了一下编译选项,没开启TLS,添加编译选项后解决问题,红色部分是添加的。对于-lssl -lcrypto这两个开关我也不清楚是什么用处,不过在makedefs里写了。我就添加上了。

make -f Makefile.init makefiles shared=yes dynamicmaps=yes CCARGS="-DUSE_TLS -DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl" AUXLIBS="-lssl -lcrypto -L/usr/lib64/sasl2 -lsasl2" AUXLIBS_MYSQL="-L/usr/local/mysql/lib -lmysqlclient -lz -lm"

Q:收不到邮件
postfix/virtual[48712]: fatal: bad string length 0 < 1: virtual_mailbox_base =
A:
没设置virtual_mailbox_base参数,这个参数是本地邮箱位置。如:/var/mail/vhosts
Q:
postfix/virtual[49949]: error: open /etc/postfix/mysql-virtual-mailbox-maps.cf: Permission denied
A:
将该文件的权限设置成<postfixgroup>组可读。因为postfix启动是需要root用户,但是它的组件是需要postfix指定的用户启动。

Q:

postfix/virtual[51225]: warning: recipient eleven@5×44.cn: not found in virtual_uid_maps

A:

因为虚拟用户,没有本地系统账户,但是邮件需要有一个所有者,配置所有虚拟用户使用一个uid和gid,也可以分别为每个虚拟用户配置一个uid和gid。

virtual_uid_maps = static:1001
virtual_gid_maps = static:1001

Q:

postfix/trivial-rewrite[58368]: warning: do not list domain 5×44.cn in BOTH mydestination and virtual_mailbox_domains

A:

这个警告是说不要把5×44.cn这个域名同时放在mydestination和virtual_mailbox_domains中。我在main.cf文件中把mydestination那行注释掉就解决了。

Q:收邮件都收到一个名为“1”的文件中了。

A:因为我的postmap -q eleven@5x44.cn mysql:./mysql-virtual-mailbox-maps.cf返回就是1,还有就是我的dovecot设置的是maildir的方式,而postfix使用mbox方式(mbox会把所有的邮件内容都写到一个文件中,优写是写入速度比较快,但检索邮件慢 ;而maildir会建立不同的文件,优点检索快,不容易丢失文件,但如果硬盘的文件系统不支持太多文件的话这会是个问题。关于maildir和mbox的特点就不详细解释了。)。开始我想更改mysql-virtual-mailbox-maps.cf中的查询语句query = SELECT ‘%d/%u’ FROM virtual_users WHERE email=’%s’(%d代表域名,%u代表用户名,%s代表输入的查询字符)的语句,让postfix直接把邮件写成maildir格式(POSTFIX是支持的),不过后来感觉这样做比较并不“玩美”,对于后期改用其它POP/IMAP服务也不利,于是使用LMTP的方法把邮件发往LMTP服务器,再由LMTP服务器收信(听上去更复杂其实不然,因为LMTP服务器就是DOVECOT来担当的,这样就会不产生格式不符而导致不能收到邮件的问题),因为使用了LMTP方式,所以不在使用virtual_mailbox_maps这个参数了。

首先,vi /etc/postfix/main.cf 。添加virtual_transport = lmtp:unix:private/dovecot-lmtp
其次,vi /etc/dovecot/dovecot.conf。在protocols部分添加lmtp,协议之间用空格隔开
最后,编辑service lmtp部分,unix_listener /var/spool/postfix/private/dovecot-lmtp。unix_listener后面的地址很重要,需要和postfix中设置一样。
详细过程:https://wiki2.dovecot.org/HowTo/PostfixDovecotLMTP

Q:不能发邮件
Oct 7 14:18:17 [localhost] postfix/smtpd[113318]: NOQUEUE: reject: RCPT from unknown[111.xxx.xxx.xxx]: 550 5.1.1 <xxxxx@163.com>: Recipient address rejected: User unknown in virtual mailbox table; from=<eleven@5×44.cn> to=<xxxxx@163.com> proto=ESMTP helo=<tt-PC>

A:xxxxx@163.com是我自己的邮箱

 


dovecot部分

Q:

Sep 27 13:32:13 [localhost] dovecot: auth: Fatal: sql /etc/dovecot/dovecot-sql.conf.ext: Can’t open configuration file /etc/dovecot/dovecot-sql.conf.ext: No such file or directory

A:

/etc/dovecot/conf.d/auth-sql.conf.ext中passdb部分args的配置文件路径写错了。

Q:

Sep 27 13:49:01 [localhost] dovecot: auth: Fatal: Unknown database driver ‘mysql’

A:

因为我的dovecot是用yum安装的,所以这里使用yum install dovecot-mysql来安装mysql支持。

Q:

Sep 27 14:20:13 [localhost] dovecot: imap(hank@5×44.cn): Error: user hank@5×44.cn: Initialization failed: Namespace ”: mkdir(/var/mail/vhosts/5×44.cn/hank) failed: Permission denied (euid=1001(vmail) egid=1001(vmail) missing +w perm: /var/mail/vhosts/5×44.cn, dir owned by 0:12 mode=0755)

A:

5×44.cn这个目录是手动建立的,所以用客户端收邮件时不能自动建立文件,手动删除这个目录之后,再次启动邮件客户端,让系统自动建立相应目录.

Q:

Oct 16 15:35:57 [localhost] dovecot: lmtp(17740): Fatal: Error reading configuration: Invalid settings: postmaster_address setting not given

A:

分析:没设置postmaster_address参数。

解决方法:在/etc/dovecot/conf.d/15-lda.conf中把postmaster_address参数添加上,这里写的是邮件管理员地址,可以是任何邮件地址,目的是为了让别的管理员可以联系到你。还有一种方法:https://github.com/mail-in-a-box/mailinabox/issues/31#event-114690723 不过这种方法我没测试。PS:我个人认为这个参数不是很重要的参数,但是不填写,就收不到邮件。


其它:

Q:CA签署CSR请求时报TXT_DB error number 2错误

分析:这个错误是由于不能有两个证书一样。

A:

修改/etc/pki/CA/index.txt.attr文件中的unique_subject 设置成no。

Q:

如何建立证书和秘钥?

A:

(1)使用/etc/pki/tls/misc/CA -newca建立新的根证书,用于签署其它证书,证明是由自己核发的。

(2)openssl req -new -nodes -keyout mailkey.pem -out mailreq.pem -days 365

keyout后是私钥文件,out后是CSR文件(用于服务器签署使用)

(3)openssl ca -out mail_signed_cert.pem -infiles mailreq.pem

mail_signed_cert.pem就是CA签署后的证书。

发表回复