分享

postfix各类故障详细分析与解决

 大宝2338 2017-10-30

问题1  DNS无法正常解析邮件服务器

查看dns解析是否正常

[root@centos work]# nslookup  -type=mx mail.

Server: 10.3.0.100

Address: 10.3.0.100#53

mail. mail exchanger = 0 10.3.0.100..

^

偿试从其它机器给其发邮件

[root@centos work]# echo hello | mail -s 'hello' root@mail.

结果发现邮件被退回,查看邮件退回原因:

: Host or domain name not found. Name service error for

name=10.3.0.100. type=AAAA: Host not found

^

通过以上信息,我们发现邮件地址被解析成了10.3.0.100.,并不是mail.

其实在第6步就已经误入歧途了!因为我们要解析的应该是这个域的地址。而不是mail.这个主机名!

偿试解析这个域的邮件交换记录:

[root@centos work]# nslookup  -type=mx

Server: 10.3.0.100

Address: 10.3.0.100#53

*** Can't find : No answer

出错了!证明dns服务器配置不正确!

看看原来的配置文件

[root@centos58 postfix]# vim /var/named/chroot/var/named/data/.zone 

$TTL 86400

@       IN      SOA     root..   root. (

2012090301

120

240

360

86400 )

IN      NS      centos58..

mail    IN      MX 0    10.3.0.100   <-----这里写错了!

www     IN      A       10.3.0.100

mail    IN      A       10.3.0.100

修改.zone配置文件

[root@centos58 postfix]# vim /var/named/chroot/var/named/data/.zone 

$TTL 86400

@       IN      SOA     root..   root. (

2012090301

120

240

360

86400 )

IN      NS      centos58..

IN      MX 0    10.3.0.100

www     IN      A       10.3.0.100

mail    IN      A       10.3.0.100

[root@centos58 postfix]# /etc/init.d/named restart 

[root@centos58 postfix]# nslookup -type=mx

Server: 10.3.0.100

Address: 10.3.0.100#53

mail exchanger = 0 10.3.0.100..

本机解析成功!

再次发邮件成功!

--------------------------------------------------

问题2 myhostname字段填写错误导致postfix无法收到邮件

在客户端发邮件给服务器

[root@centos work]# echo test2 | mail -s "hello" root@mail.

在服务器端查看邮件,发现没有邮件

[root@centos58 postfix]# mail

No mail for root

查看客户端是否退信,没有退信信息。

[root@centos work]# mail

No mail for root

以上现象说明客户端已经将邮件发送至服务器端。客户端投递没有问题,问题出在服务器上。

这个问题出在main.cf配置文件的myhostname = centos58.上。此行代表监听主机名为centos58..而我发邮件的地址为mail.。所以postfix处理发给mail.的邮件!

注意:myhostname字段接的是邮件服务器监听的主机名,与本机的主机名无关,应该与dns所解析的主机名一致!我开始填的centos58.代表的是本机的主机名。这是错误的!

解决:

修改myhostname = centos58. 为 myhostname = mail.

重启/etc/init.d/postfix restart 

再次用客户端测试

[root@centos work]# echo test2 | mail -s "hello" root@mail.

[root@centos58 postfix]# mail

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root@centos.   Mon Sep  3 02:59  21/739   "hello"

& 1

Message 1:

From root@centos.  Mon Sep  3 02:59:29 2012

X-Original-To: root@mail.

Delivered-To: root@mail.

Date: Mon, 03 Sep 2012 17:59:33 +0800

To: root@mail.

Subject: hello

User-Agent: Heirloom mailx 12.4 7/29/08

MIME-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

From: root@centos. (root)

test2

& q

总结:myhostname代表的是postfix所监听的主机名,与本机的主机名不一样。应该与dns上解析的主机名保持一致。

ok!客户端发邮件成功!

---------------------------------------------

问题3 mydestination字段错误导致不能以域名结尾来发信

前面我们用的主机名为后缀发信

现在偿试用短域名发邮件给自己

[root@centos58 postfix]# echo own | mail -s 'hello' root@

[root@centos58 postfix]# mail

No mail for root

结果失败。

查看配置文件,原来在mydestination字段后面没有添加本地域名

修改配置文件,在mydestination后加上域。

mydestination = $myhostname, localhost.$mydomain, localhost,

[root@centos58 postfix]# /etc/init.d/postfix restart 

再次测试

[root@centos58 postfix]# echo own2 | mail -s 'hello' root@

[root@centos58 postfix]# mail

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root@centos58.sun.co  Mon Sep  3 03:24  18/638   "hello"

& 1

Message 1:

From root@centos58.  Mon Sep  3 03:24:46 2012

X-Original-To: root@

Delivered-To: root@

Date: Mon, 3 Sep 2012 03:24:45 -0700

From: root

To: root@

Subject: hello

own2

成功!

-----------------------------

问题4 访问extmail出现500错误

用浏览器访问mail.,会自动跳转到/extmail/cgi/index.cgi目录下。但页面会报500错误。

先看看我apache虚拟主机配置情况

[root@centos58 cgi-bin]# vim /etc/httpd/conf/httpd.conf 

NameVirtualHost *:80

ServerName mail.

DocumentRoot /var/www/extsuite/extmail/html/

ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi

Alias /extmail /var/www/extsuite/extmail/html

SuexecUserGroup postfix postfix

看apache错误日志

[root@centos58 extmail]# tail /var/log/httpd/error_log

......... 

[Wed Sep 05 20:16:48 2012] [error] [client 10.3.0.26] suexec policy violation: see suexec log for more details, referer: http://mail./

[Wed Sep 05 20:16:48 2012] [error] [client 10.3.0.26] Premature end of script headers: index.cgi, referer: http://mail./

[Wed Sep 05 20:16:48 2012] [error] [client 10.3.0.26] File does not exist: /var/www/extsuite/extmail/html/favicon.ico

提示查看suexec日志获得更详细信息。

查看suexec日志

[root@centos58 extmail]# tail /var/log/httpd/suexec.log 

..........

[2012-09-05 20:16:48]: uid: (89/postfix) gid: (89/89) cmd: index.cgi

[2012-09-05 20:16:48]: cannot run as forbidden uid (89/index.cgi)

可以看到postfix用户的id是不允许执行这个cgi文件的。

用suexec -V查看一下

[root@centos58 extmail]# suexec -V

-D AP_DOC_ROOT="/var/www"

-D AP_GID_MIN=100

-D AP_HTTPD_USER="apache"

-D AP_LOG_EXEC="/var/log/httpd/suexec.log"

-D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"

-D AP_UID_MIN=500

-D AP_USERDIR_SUFFIX="public_html"

由AP_UID_MIN可知,suexec执行的最小用户uid必需大于500.

那让我们创建一个普通用户

[root@centos58 extmail]# useradd -s /sbin/nologin vuser

[root@centos58 extmail]# id vuser

uid=1002(vuser) gid=1002(vuser) groups=1002(vuser)  <-------注意:这里id=1002对解决此问题虽有效,但会给后续配置带来很多问题。强烈建议映射账户id指定为1000!后面我会写出此故障现象

修改httpd.conf中SuexecUserGroup字段。

[root@centos58 extmail]# sed -i '/Suexec/s/postfix/vuser/g' /etc/httpd/conf/httpd.conf 

[root@centos58 extmail]# /etc/init.d/httpd restart

再次访问extmail,仍然提示同样错误。

再次查看日志

[root@centos58 extmail]# tail /var/log/httpd/suexec.log 

[2012-09-06 12:09:36]: uid: (1002/vuser) gid: (1002/1002) cmd: index.cgi

[2012-09-06 12:09:36]: target uid/gid (1002/1002) mismatch with directory (0/0) or program (0/0)

提示所执行用户的uid/gid与目录所属用户不匹配。提示目录所属用户及组均为root.

[root@centos58 extmail]# chown -R vuser.vuser cgi/

再次访问,错误提示不同了,这次提示未安装syslog.

Unix::Syslog not found, please install it first! (in cleanup) Undefined subroutine &Ext::Logger::do_closelog called at /var/www/extsuite/extmail/libs/Ext/Logger.pm line 86.

下载unix-syslog 地址:http://search./~mharnisch/Unix-Syslog-1.1/Syslog.pm

[root@centos58 src]# tar xf /usr/src/Unix-Syslog-1.1.tar.gz 

[root@centos58 src]# cd Unix-Syslog-1.1

[root@centos58 Unix-Syslog-1.1]# perl Makefile.PL 

[root@centos58 Unix-Syslog-1.1]# make;make install

再次访问,终于ok!

总结:suexec可执行用户身份默认最小uid要大于500,这个问题要注意下。

~~~~~~~参考文献http://wenku.baidu.com/view/0e5aeac758f5f61fb73666b5.html~~~~~

----------------------------------

问题5  webman看不到图形验证码

在浏览器中访问extman看不到验证码图片,因为缺少GD插件。

下载gd软件包

[root@centos58 extman]# wget http://search./CPAN/authors/id/L/LD/LDS/GD-2.46.tar.gz

[root@centos58 src]# tar xf GD-2.46.tar.gz 

编译gd软件包报错,提示找不到gdlib-config文件。

[root@centos58 GD-2.46]# perl Makefile.PL 

**UNRECOVERABLE ERROR**

Could not find gdlib-config in the search path. Please install libgd 2.0.28 or higher.

查找gd-config所属软件包

[root@centos58 GD-2.46]# yum provides */gdlib-config

gd-devel-2.0.33-9.4.el5_4.2.x86_64 : The development libraries and header files

: for gd

Repo        : base

Matched from:

Filename    : /usr/bin/gdlib-config

找到所属软件包为gd-devel,安装软件包

[root@centos58 GD-2.46]# yum install gd-devel-2.0.33-9.4.el5_4.2.x86_64 -y

[root@centos58 GD-2.46]# whereis gdlib-config

gdlib-config: /usr/bin/gdlib-config

[root@centos58 GD-2.46]# perl Makefile.PL 

[root@centos58 GD-2.46]# make;make install 

编译成功,再次访问extman,能够看到验证码了!默认用户名root@extmail.org,密码extmail*123*,顺利登录。但登录后又报错!

Can't open /tmp/extman//sid_36e127fdd6ebcbb870b6b934b038df5e, No such file or directory

[ Go Back ] >> Re-Login

提示不能打开/tmp/extman。因为我们没有建立这个文件夹

[root@centos58 GD-2.46]# mkdir /tmp/extman

[root@centos58 GD-2.46]# chown -R vuser:vuser /tmp/extman/

再次登录,一切ok!

总结:gd插件为验证码插件,不装无法提供验证码,安装gd插件需要gd-devel包的支持,extman运行需要有/tmp/extman目录来放缓存文件

------------------------------------

问题6 启动图形化日志信息的报错归纳。

在启动mailgraph-init时报错

[root@centos58 mailgraph_ext]# /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init start

Starting mail statistics grapher: mailgraph_ext

nice: /usr/local/mailgraph_ext/mailgraph_ext.pl: No such file or directory

Starting queue statistics grapher: qmonitor

nice: /usr/local/mailgraph_ext/qmonitor.pl: No such file or directory

提示找不到/usr/local/mailgraph_ext/mailgraph_ext.pl和qmonitor.pl这两个文件,因为我们默认没有建立这两个路径

根据提示建目录

[root@centos58 mailgraph_ext]# mkdir /usr/local/mailgraph_ext

复制文件到指定目录

[root@centos58 mailgraph_ext]# cp /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph_ext.pl /usr/local/mailgraph_ext/

[root@centos58 mailgraph_ext]# cp /var/www/extsuite/extman/addon/mailgraph_ext/qmonitor.pl /usr/local/mailgraph_ext/

上述问题解决后,启动mailgraph-init又出现新的问题。

[root@centos58 mailgraph_ext]# /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init start

Starting mail statistics grapher: mailgraph_ext

Can't locate RRDs.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/mailgraph_ext/mailgraph_ext.pl line 292.

BEGIN failed--compilation aborted at /usr/local/mailgraph_ext/mailgraph_ext.pl line 292.

Starting queue statistics grapher: qmonitor

Can't locate RRDs.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/mailgraph_ext/qmonitor.pl line 8.

BEGIN failed--compilation aborted at /usr/local/mailgraph_ext/qmonitor.pl line 8.

提示找不到RRDs.pm,因为没有安装rrd图形采集工具。

安装rrdtool来解决上述问题。

无法用yum install 来安装rrdtool.添加yum源,使其支持yum安装rrdtool.

[root@centos58 src]# vim /etc/yum.repos.d/CentOS-Base.repo 

[dag]

name=Dag RPM Repository for Red Hat Enterprise Linux

baseurl=http://apt./redhat/el$releasever/en/$basearch/dag

gpgcheck=1

gpgkey=http://dag./rpm/packages/RPM-GPG-KEY.dag.txt

enabled=1

[root@centos58 src]# yum install rrdtool rrdtool-perl

rrds.pm的问题解决后,新的问题再次出现。

[root@centos58 mailgraph_ext]# /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init start

Starting mail statistics grapher: mailgraph_ext

Can't locate File/Tail.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/mailgraph_ext/mailgraph_ext.pl line 296.

BEGIN failed--compilation aborted at /usr/local/mailgraph_ext/mailgraph_ext.pl line 296.

Starting queue statistics grapher: qmonitor

提示没有安装File-Tail

下载安装File-Tail软件。

[root@centos58 src]# wget http://search./CPAN/authors/id/M/MG/MGRABNAR/File-Tail-0.99.3.tar.gz

[root@centos58 File-Tail-0.99.3]# perl Makefile.PL ;make;make install

再次启动终于成功!

[root@centos58 mailgraph_ext]# /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init start

Starting mail statistics grapher: mailgraph_ext

Starting queue statistics grapher: qmonitor

[root@centos58 File-Tail-0.99.3]# /var/www/extsuite/extman/addon/mailgraph_ext/qmonitor.pl start & 

在浏览器中点击Graph Log选项,可以看到出现了很多图形化日志界面!ok!

总结:要想启动mailgraph-init和qmonitor.pl绘图工具,必需建立/usr/local/mailgraph_ext,并将mailgraph_ext.pl,qmonitor.pl拷过去。否则会报错。并且要安装好rdtool rrdtool-perl File-Tail三个信赖包。

----------------------------

问题7 用extman管理界面添加新用户报错

偿试用extman管理界面添加新用户,结果报错!

DBD::mysql::st execute failed: INSERT command denied to user 'extmail'@'localhost' for table 'mailbox' at /var/www/extsuite/extman/libs/Ext/Mgr/MySQL.pm line 333

提示extmail用户没有对mailbox表的插入权限。

决定extman采用哪个用户身份来执行新建用户操作的配置文件在/var/www/extsuite/extman/webman.cf里面。

[root@centos58 extman]# vim /var/www/extsuite/extman/webman.cf

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = extmail

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock

以上指定了连接的用户名及密码extmail,以及数据库等信息。

进入数据库,查看extmail用户对extmail数据库的权限。

mysql> select user,db,host,insert_priv from mysql.db where db='extmail';

+---------+---------+-----------+-------------+

| user    | db      | host      | insert_priv |

+---------+---------+-----------+-------------+

| extmail | extmail | localhost | N           | 

| webman  | extmail | localhost | Y           | 

+---------+---------+-----------+-------------+

2 rows in set (0.00 sec)

可以看到extmail用户对extmail数据库而言是没有插入表的权限的。那么我们改变一下extmail用户的权限。

mysql> grant all on extmail.* to extmail@'localhost' identified by 'extmail';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,db,host,insert_priv from mysql.db where db='extmail';

+---------+---------+-----------+-------------+

| user    | db      | host      | insert_priv |

+---------+---------+-----------+-------------+

| extmail | extmail | localhost | Y           | 

| webman  | extmail | localhost | Y           | 

+---------+---------+-----------+-------------+

2 rows in set (0.00 sec)

已经拥有插入权限了!再回到web管理界面添加新用户看看。

New user test@extmail.org Added

成功添加用户,上述问题解决!注意:这里也可以不更改extmail的权限,而只需要调整webman.cf中的SYS_MYSQL_USER=webman,SYS_MYSQL_PASS = webman 即可。因为webman这个用户默认就是具有插入删除权限的!建议采用更改用户为webman的方式解决上述问题。

总结:extman的配置文件webman.cf里面的默认用户是填的extmail,但我们在导入extman默认的两张表extmail.sql init.sql时,表中默认只给extmail这个用户查询数据库的权限,而给webman这个用户管理数据库的权限,所以要么更改extmail用户的权限,要么更换webman.cf中的用户名为webman解决上面问题。 

------------------------------------

问题8 新用户无法登录

添加成功后,我们登录看看,结果登录报错,提示未知用户或密码。

Invalid account or password

查看日志文件

[root@centos58 extman]# tail /var/log/maillog

Sep  7 11:19:56 centos58 extmail[17739]: user=, client=10.3.0.26, module=login, status=badlogin <---用test登录

Sep  7 11:21:20 centos58 extmail[17801]: user=<>, client=10.3.0.26, module=login, status=badlogin    <---用test@extmail.org用户登录情况

Sep  7 11:21:58 centos58 extmail[17823]: user=, client=10.3.0.26, module=login, status=badlogin

进入mysql查看一下test用户情况

[root@centos58 ~]# mysql -uextmail -pextmail

mysql> use extmail;

由前面无法新建用户的故障我们知道了用户信息是保存在mailbox这张表中,所以我们直接查看这张表的数据,看能不能发现什么。

mysql> select username,uid,password,maildir,mailhost,domain from mailbox\G;

*************************** 2. row ***************************

username: test@extmail.org

uid: test

password: $1$sikOoDKi$GMTYxGVX0h2qV5ID9qjsJ1

maildir: extmail.org/test/Maildir/

mailhost: 

domain: extmail.org

2 rows in set (0.00 sec)

可以看到我们新建的test用户实际是属于extmail.org域的,也就是和我的并不是同一个域。问题就在这。(当然,可以直接在web管理界面看到test用户所属域,更简单)

进入到extman web管理界面,添加新的域 

Add ok

这时候在添加新用户的时候就可以选则用户所属的域了。

New user test2@ Added

回到extmail登录界面,用test2用户登录,成功登录!

总结:这个问题比较2b。粗心所致。

-------------------------------------

问题9 webmail发送邮件测试,结果一直停在发送界面,无法发送邮件。

查看日志文件。

[root@centos58 ~]# tail /var/log/maillog -f

Sep  7 11:53:39 centos58 postfix/smtpd[19109]: fatal: open /etc/postfix/mysql_virtual_alias_maps.cf: No such file or directory

Sep  7 11:53:40 centos58 postfix/master[7686]: warning: process /usr/libexec/postfix/smtpd pid 19109 exit status 1

Sep  7 11:53:40 centos58 postfix/master[7686]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling

Sep  7 11:54:40 centos58 postfix/smtpd[19153]: fatal: open /etc/postfix/mysql_virtual_alias_maps.cf: No such file or directory

Sep  7 11:54:41 centos58 postfix/master[7686]: warning: process /usr/libexec/postfix/smtpd pid 19153 exit status 1

Sep  7 11:54:41 centos58 postfix/master[7686]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling

Sep  7 11:55:41 centos58 postfix/smtpd[19191]: fatal: open /etc/postfix/mysql_virtual_alias_maps.cf: No such file or directory

Sep  7 11:55:42 centos58 postfix/master[7686]: warning: process /usr/libexec/postfix/smtpd pid 19191 exit status 1

Sep  7 11:55:42 centos58 postfix/master[7686]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling

没有mysql_virtual_alias_maps.cf文件。

提示信息很明显,在/etc/postfix文件夹下没有mysql_virtual_maps.cf等文件。因为我没将extman下面的模板文件拷贝过来。这些包默认在extman的docs目录下面。

[root@centos58 docs]# pwd

/var/www/extsuite/extman/docs

[root@centos58 docs]# cp mysql_virtual_* /etc/postfix/

再来访问下看看报什么错!邮件发送成功,没有此类报错。问题解决! 

看看日志记录情况

[root@centos58 docs]# tail /var/log/maillog

Sep  7 15:50:38 centos58 postfix/smtpd[28365]: disconnect from localhost.localdomain[127.0.0.1]

Sep  7 15:53:49 centos58 extmail[28486]: user=, client=10.3.0.26, module=login, status=badlogin

Sep  7 15:54:01 centos58 extmail[28490]: user=, client=10.3.0.26, module=login, status=loginok

Sep  7 15:55:42 centos58 postfix/smtpd[28608]: warning: smtpd_sasl_auth_enable is true, but SASL support is not compiled in

Sep  7 15:55:42 centos58 postfix/smtpd[28608]: connect from localhost.localdomain[127.0.0.1]

Sep  7 15:55:42 centos58 postfix/smtpd[28608]: B74BEE3010: client=localhost.localdomain[127.0.0.1]

Sep  7 15:55:42 centos58 postfix/cleanup[28614]: B74BEE3010: message-id=<20120907075542.B74BEE3010@mail.>

Sep  7 15:55:42 centos58 postfix/qmgr[7688]: B74BEE3010: from=, size=655, nrcpt=2 (queue active)

Sep  7 15:55:42 centos58 postfix/smtpd[28608]: disconnect from localhost.localdomain[127.0.0.1]

Sep  7 15:55:45 centos58 postfix/smtp[28616]: B74BEE3010: to=, relay=163mx02.mxmail.netease.com[220.181.12.69]:25, delay=3, delays=0.26/0.15/0.59/2, dsn=2.0.0, status=sent (250 Mail OK queued as mx19,RcCowEDJXnyKqElQzTtvEQ--.1649S2 1347004556)

由以上日志可以看到邮件已经被正确投递出去了!进到163邮箱确认一下看。成功收到邮件!

总结:关于无法发送出邮件的原因很多,无法一一例举。具体原因建议多看日志来寻找答案!

-------------------------------------

问题10 mysql虚拟用户认证不通过,无法发信

[root@centos581 postfix]# telnet mail. 25

Trying 10.3.0.100...

Connected to mail. (10.3.0.100).

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo da

250-mail.

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:aa@bb.com

250 2.1.0 Ok

rcpt to:test1@

550 5.1.1: Recipient address rejected: User unknown in local recipient table

提示我用户未知,被拒绝。

那么我们回到mysql中查看test1@这个用户是否真的不存在

mysql> select domain from domain;

+--------------+

| domain       |

+--------------+

| extmail.org  | 

| mail. | 

|      | 

+--------------+

mysql> select name,username,uidnumber,password from mailbox where username='test1@';

+------------+------------------------+-----------+------------------------------------+

| name       | username               | uidnumber | password                           |

+------------+------------------------+-----------+------------------------------------+

| test1      | test1@          |      1000 | $1$qeG0Ns8D$63ABiq2nF7jgNQ7EyN7UC/ | 

+------------+------------------------+-----------+------------------------------------+

用户是存在于数据库中的

再查看maillog日志情况

[root@centos58 ~]# tail /var/log/maillog

Sep 10 16:43:42 centos58 postfix/cleanup[7155]: D9329A6F8: message-id=<>

Sep 10 16:43:43 centos58 postfix/qmgr[19071]: D9329A6F8: from=, size=175, nrcpt=1 (queue active)

Sep 10 16:43:43 centos58 postfix/trivial-rewrite[7125]: warning: do not list domain mail. in BOTH virtual_mailbox_domains and relay_domains

Sep 10 16:43:43 centos58 postfix/virtual[7157]: D9329A6F8: to=, relay=virtual, delay=49, delays=49/0.05/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)

Sep 10 16:43:43 centos58 postfix/qmgr[19071]: D9329A6F8: removed

Sep 10 16:43:46 centos58 postfix/smtpd[7101]: disconnect from unknown[10.3.0.101]

Sep 10 16:49:30 centos58 postfix/smtpd[7440]: warning: smtpd_sasl_auth_enable is true, but SASL support is not compiled in

Sep 10 16:49:30 centos58 postfix/smtpd[7440]: connect from unknown[10.3.0.101]

Sep 10 16:49:49 centos58 postfix/trivial-rewrite[7443]: warning: do not list domain in BOTH mydestination and virtual_mailbox_domains

Sep 10 16:49:49 centos58 postfix/smtpd[7440]: NOQUEUE: reject: RCPT from unknown[10.3.0.101]: 550 5.1.1: Recipient address rejected: User unknown in local recipient table; from=to=proto=ESMTP helo=

日志分析:

1,smtpd_sasl_auth_enable is true, but SASL support is not compiled in

sasl认证已经打开,但没有加载sasl支持!因为我用的是rpm版,而rpm版默认是不支持sasl认证的。这个问题与解决此问题无关,但我在后面会解决。

2,warning: do not list domain in BOTH mydestination and virtual_mailbox_domains

(我原来将这句话理解为“没有在mydestination和virtual_mailbox_domains参数中找到这个域!”这是错误的!)

意思应该是 不要在mydestination和virtual_mailbox_domains同时定义同一个域,会冲突!且在出现冲突的情况下,系统会默认以mydestination中定义的为准,那就代表着mysql中添加的虚拟域不生效,那么该域下的虚拟账户同样也就无法生效了。这也就是为什么一直提示我的域中的test1用户找不到的原因了,因为本地用户里面根本没这个账户,而mysql里面虽然有,但根本没生效!

3,Recipient address rejected: User unknown in local recipient table;

收件地址拒绝,没有找到用户test1@。受上面错误配置的影响。

解决办法:

根据日志分析,出现上述问题主要原因在于mydestination和virtual_mailbox_domains冲突所致!

那么我们将mydestination字段留空!

[root@centos58 courier-authlib]# vim /etc/postfix/main.cf

mydestination = $mydomain

改为

mydestination =

[root@centos58 courier-authlib]# /etc/init.d/postfix restart

再次测试

[root@centos Desktop]# telnet 10.3.0.100 25

Trying 10.3.0.100...

Connected to 10.3.0.100.

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo

501 Syntax: EHLO hostname

mail from:ss@

250 2.1.0 Ok

rcpt to:test1@

250 2.1.5 Ok

data

354 End data with.

hello test mail!

.

250 2.0.0 Ok: queued as 76BB1E319C

quit

221 2.0.0 Bye

Connection closed by foreign host.

测试成功,没有再报错!

再看看日志情况

[root@centos58 courier-authlib]# tail /var/log/maillog

Sep 12 09:16:55 centos58 postfix/postfix-script[15306]: starting the Postfix mail system

Sep 12 09:16:55 centos58 postfix/master[15307]: daemon started -- version 2.8.12, configuration /etc/postfix

Sep 12 09:17:32 centos58 postfix/smtpd[15347]: warning: smtpd_sasl_auth_enable is true, but SASL support is not compiled in

Sep 12 09:17:32 centos58 postfix/smtpd[15347]: connect from centos.[10.3.0.26]

Sep 12 09:18:09 centos58 postfix/smtpd[15347]: 76BB1E319C: client=centos.[10.3.0.26]

Sep 12 09:18:22 centos58 postfix/cleanup[15396]: 76BB1E319C: message-id=<>

Sep 12 09:18:22 centos58 postfix/qmgr[15309]: 76BB1E319C: from=, size=193, nrcpt=1 (queue active)

Sep 12 09:18:22 centos58 postfix/virtual[15401]: 76BB1E319C: to=, relay=virtual, delay=38, delays=38/0.05/0/0.05, dsn=2.0.0, status=sent (delivered to maildir)

Sep 12 09:18:22 centos58 postfix/qmgr[15309]: 76BB1E319C: removed

Sep 12 09:18:23 centos58 postfix/smtpd[15347]: disconnect from centos.[10.3.0.26]

ok!日志记录正常!

用浏览器登录mail.,用test1用户登录邮箱看是否收到邮件。ok!test1顺利收到邮件。看是否能发信给test2,ok顺利发送!发给外网sunjiebin2006@163.com看看,ok顺利发送!

登录test2@和sunjiebin2006@163.com查看邮件。一路绿灯,都收到!

总结:在打开了虚拟认证后最好将mydestination字段留空或注释掉,不要和virtual_mailbox_domains中定义的域相同而导致冲突。当然,如果mydestination中的域名和mysql中定义的虚拟域不相同的话也是可以的!

------------------------------------

问题11 pop3无法顺利收信

测试pop3收信

下面又迎来了新的问题,发信虽然成功,收信仍需努力!pop3收信认证又有问题!

[root@centos Desktop]# telnet mail. 110

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

+OK Dovecot ready.

user test1@

+OK

pass 123456

+OK Logged in.

-ERR [IN-USE] Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2012-09-13 14:54:01]

Connection closed by foreign host.

直接提示无法打开收信夹。在服务器端看日志

[root@centos58 postfix]# tail /var/log/maillog

Sep 13 14:54:01 centos58 dovecot: auth-worker(default): mysql: Connected to localhost (extmail)

Sep 13 14:54:01 centos58 dovecot: POP3(test1@): stat(/home/domains//test1/Maildir/cur) failed: Permission denied

Sep 13 14:54:01 centos58 dovecot: POP3(test1@): stat(/home/domains//test1/Maildir/cur) failed: Permission denied

Sep 13 14:54:01 centos58 dovecot: POP3(test1@): Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2012-09-13 14:54:01]

Sep 13 14:54:01 centos58 dovecot: POP3(test1@): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0

Sep 13 14:54:01 centos58 dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.3.0.26, lip=::ffff:10.3.0.100

提示/home/domains//test1/Maildir/cur文件夹无法访问

我们看看这个目录的权限

[root@centos58 domains]# ll -d /home/domains/

drwx------ 5 vuser vuser 4096 Sep  7 16:21 /home/domains/

[root@centos58 domains]# ll /home/domains//

drwx------ 3 vuser vuser 4096 Sep 10 10:40 test1

drwx------ 3 vuser vuser 4096 Sep  7 11:50 test2

drwx------ 3 vuser vuser 4096 Sep 12 09:55 test3

所有目录都属于vuser,且只有vuser具有完全权限,其它用户都没有权限。

那么我们试着更改一下权限看看。

[root@centos58 home]# chmod 755 domains/     <-----注意这个父目录的权限,如果只改/home/domains/下面的子目录而不改/home/domains目录本身的话依然会无法访问!

[root@centos58 domains]# chmod 755 /

[root@centos58 ]# cp -a test1 test1.bak

[root@centos58 ]# chmod -R 777 test1

[root@centos58 home]# ll -d domains/

drwxr-xr-x 5 vuser vuser 4096 Sep  7 16:21 domains/

[root@centos58 domains]# ll -d

drwxr-xr-x 6 vuser vuser 4096 Sep 13 15:26

[root@centos58 domains]# ll -d /test1

drwxrwxrwx 3 vuser vuser 4096 Sep 10 10:40 /test1

现在test1文件夹及其父目录所有用户都能访问了。下面我们再测试一下看

[root@centos Desktop]# telnet  mail. 110

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

+OK Dovecot ready.

user test1@

+OK

pass 123456

+OK Logged in.

list

+OK 7 messages:

1 279

2 666

3 1112

retr 1

+OK 279 octets

Return-Path:

X-Original-To: test1@

Delivered-To: test1@

Received: from centos. (centos. [10.3.0.26])

by mail. (Postfix) with SMTP id 76BB1E319C

for; Wed, 12 Sep 2012 09:17:44 +0800 (CST)

hello test mail!

改了权限后,pop3认证也成功了!那么引发出一个问题,很明显pop3并不是用的我们的vuser用户来读取用户的邮件的,那么它是用的哪个用户呢?我们总不能将所有邮件权限都设为777吧,那样太不安全了!

一个偶然的机会发现了它的默认用户

[root@centos58 Maildir]# ll

total 64

-rwxrwxrwx 1 vuser vuser   452 Sep 12 14:08 abook.cf

drwxrwxrwx 2 vuser vuser  4096 Sep 13 16:54 cur

-rw------- 1  1000  1000   240 Sep 13 16:54 dovecot.index

-rw------- 1  1000  1000 16384 Sep 13 15:43 dovecot.index.cache

-rw------- 1  1000  1000   360 Sep 13 16:54 dovecot.index.log

-rw------- 1  1000  1000   425 Sep 13 16:54 dovecot-uidlist

原来它用的是id=1000这个用户,但这个用户在我系统中并不存在。问题好解决了。把vuser的uid改为1000应该就行了!

其实这个默认用户不仅仅只是适用于dovecot,extmail/extman所用的虚拟账户也是默认映射为id=1000的这个本地用户。可以通查询mailbox表来查看一下。

mysql> select username,uidnumber,gidnumber from mailbox ;

+------------------------+-----------+-----------+

| username               | uidnumber | gidnumber |

+------------------------+-----------+-----------+

| postmaster@extmail.org |      1000 |      1000 | 

| test@extmail.org       |      1000 |      1000 | 

| test2@          |      1000 |      1000 | 

下面将相关目录的uid,gid都改为1000这个用户

[root@centos58 Maildir]# id vuser

uid=1002(vuser) gid=1002(vuser) groups=1002(vuser)

[root@centos58 Maildir]# usermod -u 1000 vuser

[root@centos58 Maildir]# id vuser

uid=1000(vuser) gid=1002(vuser) groups=1002(vuser)

[root@centos58 Maildir]# usermod -g 1000 vuser

[root@centos58 Maildir]# id vuser

uid=1000(vuser) gid=1000(vuser) groups=1000(vuser)

[root@centos58 home]# chown -R vuser:vuser domains 

[root@centos58 home]# ll -d domains/

drwxr-xr-x 5 1002 1002 4096 Sep  7 16:21 domains/

[root@centos58 home]# chown -R vuser:vuser domains

[root@centos58 home]# ll -d domains/

drwxr-xr-x 5 vuser vuser 4096 Sep  7 16:21 domains/

好了,现在邮件的权限都为vuser,并且uid,gid都为1000了!

我们把test1的文件夹都恢复默认

[root@centos58 domains]# chmod 700

[root@centos58 ]# chmod -R 700 test1

[root@centos58 ]# ll test1

total 8

drwx------ 10 vuser vuser 4096 Sep 13 17:38 Maildir

注意还要改一下postfix里面的main.cf,因为以前我们设的虚拟映射用户为1002要改过来

[root@centos58 ~]# vim /etc/postfix/main.cf

virtual_uid_maps = static:1002

virtual_gid_maps = static:1002

改为

virtual_uid_maps = static:1000

virtual_gid_maps = static:1000

[root@centos58 ~]# /etc/init.d/postfix restart

注意同时还得改变下网站家目录的所属用户。因为以前我们是用的uid=1002的用户。不改回来会提示访问拒绝。

[root@centos58 home]# find /var/www/ -uid 1002 -exec chown vuser:vuser  {} \;

现在再来telnet测试一下

[root@centos Desktop]# telnet  mail. 110

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

+OK Dovecot ready.

user test1@

+OK

pass 123456

+OK Logged in.

list

+OK 8 messages:

1 279

用test2@来测试下

[root@centos Desktop]# telnet  mail. 110

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

+OK Dovecot ready.

user test2@

+OK

pass 123456

+OK Logged in.

这次真的都ok了!

登录webmail也成功了!

至此,发信认证和收信认证都成功了!

总结:此次故障出现主要是“问题4”埋下的祸根,当时不知道uid=1000是必需的。问题本身并不难,看日志提示就知道错误问题所在,但为什么dovecot默认用户是uid=1000这个用户?这个我也不太清楚。

------------------------------------

问题12 定制rpm版的postfix时报错

由于前面我们默认的rpm版postfix软件包并没有支持sasl认证,现在我们用rpm定制版重新安装postfix

下载定制版rpm

[root@centos58 postfix-2.8.12]# wget http://ftp./official/2.8/SRPMS/postfix-2.8.8-1.src.rpm

[root@centos58 postfix-2.8.12]# rpm -ivh /usr/src/postfix-2.8.8-1.src.rpm 

[root@centos58 SPECS]# vim /usr/src/redhat/SPECS/postfix.spec 

%define with_cdb          0

%define with_ldap         1

%define with_mysql        1

%define with_mysql_redhat 1

%define with_pcre         0

%define with_pgsql        0

%define with_sasl         2

%define with_spf          0

%define with_dovecot      1

%define with_tls          1

%define with_tlsfix       2

%define with_vda          0

with_mysql为1代表支持www.mysql.com网站上面的mysql。

with_mysql_redhat为1代表支持redhat的mysql,即我们用yum装的就属于这种。

with_sasl为2代表支持sasl2。为1代表支持sasl1。现在一般都是用sasl2了。所以选2。

[root@centos58 SPECS]# rpmbuild -ba postfix.spec 

error: Failed build dependencies:

MySQL-shared is needed by postfix-2.8.8-1.rhel5.x86_64

MySQL-devel is needed by postfix-2.8.8-1.rhel5.x86_64

出现报错说要MySQL-shared MySQL-devel.

[root@centos58 SPECS]# yum list MySQL*

[root@centos58 SPECS]# yum list MySQL* |grep shared

[root@centos58 SPECS]# yum list MySQL* |grep devel

mysql-devel.x86_64                       5.0.95-1.el5_7.1              installed

mysql-devel.i386                         5.0.95-1.el5_7.1              updates  

yum中竟然没有MySQL-shared!!

看下postfix.spec中的代码

[root@centos58 SPECS]# vim postfix.spec

%if %{with_mysql}

Requires: MySQL-shared

BuildRequires: MySQL-shared, MySQL-devel

原来是加载mysql支持的时候要这个。

去掉mysq的支持,保留mysql-redhat试一下。

%define with_mysql        0

%define with_mysql_redhat 1

没有看到error之类的报错,编译成功!

进入rpm包生成的位置

[root@centos58 RPMS]# ls /usr/src/redhat/RPMS/x86_64/

postfix-2.8.8-1.rhel5.x86_64.rpm  postfix-debuginfo-2.8.8-1.rhel5.x86_64.rpm

安装定制好的rpm包

[root@centos58 x86_64]# rpm -ivh postfix-2.8.8-1.rhel5.x86_64.rpm 

[root@centos58 x86_64]# rpm -q postfix

postfix-2.8.8-1.rhel5

看看支持的模块

[root@centos58 x86_64]# postconf -m

btree

cidr

environ

hash

internal

ldap

mysql

nis

proxy

regexp

static

tcp

texthash

unix

可看到支持mysql

[root@centos58 x86_64]# cp /etc/postfix/main.cf.bak /etc/postfix/main.cf

cp: overwrite `/etc/postfix/main.cf'? y

[root@centos58 x86_64]# /etc/init.d/postfix restart

查看是不是支持sasl认证了!

[root@centos58 local]# postconf  -a 

cyrus   <---------这里出现这一行代表postfix已经支持了sasl认证模块,与配置文件main.cf中是否打开sasl认证无关

dovecot

可以看到有了cyrus。。也可以用下面的telnet上去看,看到两个AUTH证明成功了!

[root@centos Desktop]# telnet  mail. 25

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo test

250-mail.

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN   <---------这里出现认证支持仅代表main.cf配置文件中已经打开了认证功能,与postfix是否支持sasl模块无关

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

看来postfix已经支持sasl认证了。

总结:在定制版中,如果你没有安装oracle官网的mysql的时,就不要打开 with_mysql 这个参数的支持。直接打开 with_mysql_redhat 就行了。我们默认就是用的这个。

------------------------------------

问题13 用sasl发信认证失败

我们来测试一下发信看看

首先用perl产生加密的登录账号和密码

[root@centos58 postfix-2.8.12]# perl -MMIME::Base64 -e "print encode_base64('test1@');"

dGVzdDFAc3VuLmNvbQ==

[root@centos58 postfix-2.8.12]# perl -MMIME::Base64 -e "print encode_base64('123456');"

MTIzNDU2

回到客户端来测试

[root@centos Desktop]# telnet  mail. 25

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo test  

250-mail.

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

auth login

334 VXNlcm5hbWU6

dGVzdDFAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

535 5.7.8 Error: authentication failed: generic failure

竟然认证失败了!看日志!

[root@centos58 ~]# tail /var/log/maillog

Sep 13 09:17:21 centos58 authdaemond: Installing libauthmysql

Sep 13 09:17:21 centos58 authdaemond: Installation complete: authmysql

Sep 13 09:18:32 centos58 extmail[5083]: user=, client=10.3.0.26, module=login, status=loginok

Sep 13 09:19:20 centos58 postfix/smtpd[5149]: connect from centos.[10.3.0.26]

Sep 13 09:22:33 centos58 postfix/smtpd[5149]: warning: SASL authentication failure: cannot connect to saslauthd server: No such file or directory

Sep 13 09:22:33 centos58 postfix/smtpd[5149]: warning: centos.[10.3.0.26]: SASL login authentication failed: generic failure

说不能连接到saslauthd服务。因为没启动saslauthd...!

[root@centos58 ~]# /etc/init.d/saslauthd start

Starting saslauthd:                                        [  OK  ]

[root@centos Desktop]# telnet mail. 25Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo go

250-mail.

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

auth login

334 VXNlcm5hbWU6

dGVzdDFAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

535 5.7.8 Error: authentication failed: authentication failure

还是失败了!

[root@centos58 ~]# tail /var/log/maillog

Sep 13 09:31:04 centos58 postfix/smtpd[5800]: connect from centos.[10.3.0.26]

Sep 13 09:31:44 centos58 postfix/smtpd[5800]: warning: centos.[10.3.0.26]: SASL login authentication failed: authentication failure

Sep 13 09:31:50 centos58 postfix/smtpd[5800]: disconnect from centos.[10.3.0.26]

这次不再是找不到服务器了,而是提示认证失败了!

我们用本地用户试试

[root@centos Desktop]# telnet mail. 25

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

220 mail. ESMTP Postfix

ehlo helo

250-mail.

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

auth login

334 VXNlcm5hbWU6

c3Vu

334 UGFzc3dvcmQ6

MTIzNDU2

235 2.7.0 Authentication successful

本地认证是成功的!

为什么会出现这种情况?我们看看我们的sasl进程

[root@centos58 local]# ps aux |grep sasl

root      5535  0.0  0.1  48856  1140 ?        Ss   09:25   0:00 /usr/sbin/saslauthd -m /var/run/saslauthd -a pam

root      5536  0.0  0.1  48856  1128 ?        S    09:25   0:00 /usr/sbin/saslauthd -m /var/run/saslauthd -a pam

其中-m代表saslauthd的工作目录在/var/run/saslauthd下面。-a代表所启用的验证机制。这里代表用pam来验证!pam验证是啥?我们的系统登录就是用的调用pam来验证用户密码的啊!也就是说,这时候的saslauthd是调用的pam来验证的我们的账户!而pam刚好可以验证本地账户。这也就是为什么我用真实账户sun为什么能验证通过的原因。而我们的虚拟账号test1@并不是用pam机制来验证,而是采用的mysql自身来验证的,所以会提示验证失败!那么saslauthd能否支持mysql的验证呢?我们可以man saslauthd来看看,发现saslauthd支持多达10种认证方式,但偏偏没有mysql的验证!所以说,用saslauthd是不能验证mysql虚拟账户的!那么我们得改变一下postfix所采用的验证机制!

[root@centos58 local]# vim /usr/lib64/sasl2/smtpd.conf

pwcheck_method: authdaemond  <-----这里不再是saslauthd

mech_list: PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socke  <--------这里有错误,我先不改过来,等着看后面的好戏吧!

[root@centos Desktop]# telnet mail. 25

.......

auth login

334 VXNlcm5hbWU6

dGVzdDFAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

535 5.7.8 Error: authentication failed: generic failure

还是失败了!再看日志

[root@centos58 usr]# tail /var/log/maillog

......

Sep 13 11:37:22 centos58 postfix/smtpd[31886]: warning: SASL authentication failure: cannot connect to Courier authdaemond: No such file or directory

Sep 13 11:37:22 centos58 postfix/smtpd[31886]: warning: centos.[10.3.0.26]: SASL login authentication failed: generic failure

提示无法连接到authdaemond进程,找不到文件或目录。我们先看看有没有启动这个进程

[root@centos58 usr]# ps aux  | grep authdaemond

root     31384  0.0  0.0   3808   440 ?        S    11:31   0:00 /usr/local/courier-authlib/sbin/courierlogger -pid=/usr/local/courier-authlib/var/spool/authdaemon/pid -start /usr/local/courier-authlib/libexec/courier-authlib/authdaemond

root     31385  0.0  0.1  52448  1548 ?        S    11:31   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond

root     31386  0.0  0.0  52448   480 ?        S    11:31   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond

进程是启动的。把进程停掉,结果报错还是一样的结果!所以不是courier-authlib进程的问题,而是postfix压根儿就没和authdaemond建立连接。

我们在学习mysql的时候知道,mysql本地连接是利用socket和进程通信的。那么同样的,现在postfix和courier连接也是利用socket来连接的。那么首先我们先确定一下我们指定的socket是否存在吧!

[root@centos58 local]# vim /usr/lib64/sasl2/smtpd.conf

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socke

[root@centos58 ~]# ls /usr/local/courier-authlib/var/spool/authdaemon/socke

ls: /usr/local/courier-authlib/var/spool/authdaemon/socke: No such file or directory

看到没,根本没这个文件!那么问题就在这了!

[root@centos58 local]# vim /usr/lib64/sasl2/smtpd.conf

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socke  <-----看到问题所在了吧!掉了个t!

改过来

[root@centos58 local]# vim /usr/lib64/sasl2/smtpd.conf

pwcheck_method: authdaemond

mech_list: PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

[root@centos58 local]# /etc/init.d/postfix restart    <----------一定要重启postfix才能使修改过的smtpd.conf重新生效,我开始就是没重启进程而苦恼了很久找不到原因!

登录验证看

[root@centos Desktop]# telnet mail. 25

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

220 mail. ESMTP Postfix

auth login

334 VXNlcm5hbWU6

dGVzdDFAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

235 2.7.0 Authentication successful

验证成功!

另外,网络上也说了出现此问题的方法,一般大致有三种情况。

1,smtp.conf配置文件中文件名或参数写错

2,/usr/local/courier-authlib/var/spool/authdaemon/这个目录权限不对,需要755权限才能正确运行。

3,postfix开启了chroot环境,导致postfix只能读取其笼环境之内的文件。

下面我们来验证下1和2问题

问题1

[root@centos58 usr]# vim /usr/lib64/sasl2/smtpd.conf

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket 

我在socket后面故意多打了一个空格

[root@centos58 usr]# /etc/init.d/postfix restart

[root@centos Desktop]# telnet mail. 25

auth login

334 VXNlcm5hbWU6

dGVzdDJAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

535 5.7.8 Error: authentication failed: generic failure

果然认证失败。

[root@centos58 local]# tail /var/log/maillog

Sep 13 12:59:49 centos58 postfix/smtpd[5327]: warning: SASL authentication failure: cannot connect to Courier authdaemond: No such file or directory

Sep 13 12:59:49 centos58 postfix/smtpd[5327]: warning: centos.[10.3.0.26]: SASL login authentication failed: generic failure

同样的日志信息

问题2

[root@centos58 usr]# ll /usr/local/courier-authlib/var/spool/authdaemon/ -d

drwxr-xr-x 2 daemon daemon 4096 Sep 13 12:36 /usr/local/courier-authlib/var/spool/authdaemon/

[root@centos58 usr]# chmod 744 /usr/local/courier-authlib/var/spool/authdaemon/

[root@centos58 usr]# /etc/init.d/postfix restart

[root@centos Desktop]# telnet mail. 25

....

auth login

334 VXNlcm5hbWU6

dGVzdDJAc3VuLmNvbQ==

334 UGFzc3dvcmQ6

MTIzNDU2

535 5.7.8 Error: authentication failed: generic failure

[root@centos58 local]# tail /var/log/maillog

Sep 13 13:06:11 centos58 postfix/smtpd[6059]: warning: SASL authentication failure: cannot connect to Courier authdaemond: Permission denied

Sep 13 13:06:11 centos58 postfix/smtpd[6059]: warning: centos.[10.3.0.26]: SASL login authentication failed: generic failure

也是同样的日志信息!

至此,smtp发信认证搞定了!

总结:出现sasl认证失败,我遇到了三个原因。

1,postfix未添加sasl模块支持.这时候可以通过安装源码包或定制rpm包来添加支持。

2,mysql的sasl认证要用courier-authlib这个软件来支持,系统默认装的的cyrus-sasl是不支持mysql认证的

3,/usr/lib/sasl2/smtpd.conf这个配置文件里面认证方式要采用authdaemond,而不是saslauthd。配置文件中socket路径一定要写对,不要多打空格!

4,服务要启动!

--------------------------------------------------------------------------------------------------

问题14 imap无法连接

有时候imap连接好好的,可过一会后就发现无法连接上了。雷鸟报超过最大连接数限制。直接用telnet服务器发现无法连接。

[root@centos Desktop]# telnet mail. 143

Trying 10.3.0.100...

Connected to mail..

Escape character is '^]'.

Connection closed by foreign host.

查看服务器端日志

[root@mail bin]# tail /var/log/maillog 

Sep 21 13:49:12 mail imapd: Maximum connection limit reached for ::ffff:116.24.82.12

提示已经达到最大连接数限制。

我们用netstat看看连接数为多少了

[root@mail etc]# netstat  -tna |grep 143

tcp        0      0 10.3.0.100:143           116.24.82.12:2393           ESTABLISHED 

tcp        0      0 10.3.0.100:143           116.24.82.12:2395           ESTABLISHED 

tcp        0      0 10.3.0.100:143           116.24.82.12:2394           ESTABLISHED 

tcp        0      0 10.3.0.100:143           116.24.82.12:2397           TIME_WAIT   

tcp        0      0 10.3.0.100:143           116.24.82.12:2396           ESTABLISHED 

tcp        0      0 10.3.0.100:143           116.24.82.12:2398           TIME_WAIT   

可以看到116.24.82.12的客户端ip和服务器端共建立了4个连接

这时候telnet上去就直接报拒绝了。

解决办法:

我们看看imapd配置文件

[root@yx_host etc]# vim /usr/lib/courier-imap/etc/imapd

#  Maximum number of connections to accept from the same IP address

MAXPERIP=4    <-----这个即代表每个ip最大连接数为4,与上面连接数吻合!

改为

MAXPERIP=20

由于公司用的人比较多,所以4个显然不够用。将这个值改为20.

[root@mail etc]# /etc/init.d/courier-imap restart

搞定! 

--------------------------------------------------------------------------------------------------

2012.11.02

问题15,每次发信很慢,要几十秒才能发信成功

直接看日志情况:

Oct 24 15:02:39 localhost postfix/smtpd[99067]: connect from unknown[113.116.236.65]

Oct 24 15:03:01 localhost postfix/smtpd[99067]: warning: 65.236.116.113.opm.blitzed.org: RBL lookup error: Host or domain name not found. Name service error for name=65.236.116.113.opm.blitzed.org type=A: Host not found, try again

Oct 24 15:03:01 localhost postfix/smtpd[99067]: AB89823F046: client=unknown[113.116.236.65], sasl_method=LOGIN, sasl_username=test2@example.com

Oct 24 15:03:01 localhost postfix/cleanup[99102]: AB89823F046: message-id=<201210241502429841144@example.com>

Oct 24 15:03:01 localhost postfix/qmgr[12944]: AB89823F046: from=, size=1701, nrcpt=1 (queue active)

Oct 24 15:03:01 localhost postfix/smtpd[99067]: disconnect from unknown[113.116.236.65]

Oct 24 15:03:02 localhost postfix/smtp[99103]: AB89823F046: to=<445335413@qq.com>, relay=mx3.qq.com[119.147.192.199]:25, delay=23, delays=23/0/0.04/0.31, dsn=2.0.0, status=sent (250 Ok: queued as )

Oct 24 15:03:02 localhost postfix/qmgr[12944]: AB89823F046: removed

日志显示我们15:02:39开始连接,而在15:03:01返回了RBL查询错误信息,随后才发出邮件。问题很明显,RBL查询超时导致的!

编辑main.cf,去掉RBL实时黑名单查询功能。

localhost# vi /etc/postfix/main.cf

#smtpd_client_restrictions =

#       reject_rbl_client cblless., 

#       reject_rbl_client cdl., 

#       reject_rbl_client opm.blitzed.org, 

#       reject_rbl_client bl.spamcop.net 

localhost# postfix reload

再发邮件

Oct 24 15:25:16 localhost postfix/smtpd[99296]: connect from unknown[113.116.236.65]

Oct 24 15:25:16 localhost postfix/smtpd[99296]: AD9BC23F047: client=unknown[113.116.236.65], sasl_method=LOGIN, sasl_username=test2@example.com

Oct 24 15:25:16 localhost postfix/cleanup[99348]: AD9BC23F047: message-id=<201210241525203286146@example.com>

Oct 24 15:25:16 localhost postfix/qmgr[99278]: AD9BC23F047: from=, size=1703, nrcpt=1 (queue active)

Oct 24 15:25:16 localhost postfix/smtpd[99296]: disconnect from unknown[113.116.236.65]

Oct 24 15:25:17 localhost postfix/smtp[99356]: AD9BC23F047: to=<445335413@qq.com>, relay=mx3.qq.com[113.108.77.23]:25, delay=0.49, delays=0.14/0/0.05/0.31, dsn=2.0.0, status=sent (250 Ok: queued as )

Oct 24 15:25:17 localhost postfix/qmgr[99278]: AD9BC23F047: removed

从连接到发送1s内完成,正常了!

总结:由于开户了客户端RBL查询验证功能,所以在客户端发信之前postfix服务器会先将客户端IP发给RBL服务器来查询该IP是否位于实时黑名单之中。如果在黑名单中,则会拒绝客户端的发信请求。而当postfix无法连接上RBL服务器时,则会有一个等待超时的时间,只有在查询超时后,才会继续后续的投递操作。所以,造成了发信过程中几十秒的延迟问题。

中国反垃圾邮件联盟  http://www./

postfix中配置使用casa RBL http://www./AID/15

只不过 cblless. 这个链接地址貌似连接不上。所以我取消了RBL功能。

--------------------------------------------------------------------------------------------------

2012.11.02

问题16 extmail总是无法发送邮件,一直卡在正在发邮件那里。而用foxmail等邮件客户端却可以正常发送。

分析: 

查看日志

localhost# tail -20000 /var/log/maillog | grep test2

Oct 24 02:55:26 localhost extmail[12253]: user=, client=163.125.216.2, module=login, status=loginok

Oct 24 02:56:28 localhost postfix/smtpd[12204]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 553 5.7.1 : Sender address rejected: not logged in; from= to= proto=ESMTP helo=

Oct 24 03:07:01 localhost postfix/smtpd[12206]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 553 5.7.1 : Sender address rejected: not logged in; from= to= proto=ESMTP helo=提示来自Localhost的登录拒绝,提示没有登录。因为extmail没有使用认证发信的方式。 reject: RCPT from localhost[127.0.0.1]: 553Oct 24 03:00:02 localhost extmail[34131]: user=, client=27.38.21.195, module=login, status=loginok

提示来自127.0.0.1的登录拒绝.

Sender address rejected: not logged in

提示发信地址拒绝,因为前面登录失败,所以这里提示我们没有登录,拒绝发信。

服务器不允许我们本地登录,那么我们查看一下mynetworks选项的设定。

localhost# grep mynetworks /etc/postfix/main.cf

结果发现配置文件中没有定义mynetworks选项。

解决:

将mynetworks添加上,然后在smtpd_sender_restrictions选项中允许mynetworks登录。

localhost# vi main.cf

mynetworks = 127.0.0.0/8

smtpd_sender_restrictions =

permit_mynetworks,

reject_sender_login_mismatch,

reject_non_fqdn_sender,

reject_unauthenticated_sender_login_mismatch,

reject_non_fqdn_recipient,

reject_invalid_hostname,

reject_unknown_sender_domain,

check_sender_access hash:/etc/postfix/sender_access

localhost# postfix reload

postfix/postfix-script: refreshing the Postfix mail system

再次发信,立即成功了!

我们再来看看日志

localhost# tail -1000 /var/log/maillog |grep test2 -A 5 -B 5

Oct 24 03:00:02 localhost postfix/smtpd[33884]: connect from localhost[127.0.0.1]

Oct 24 03:00:02 localhost postfix/smtpd[33884]: 676E323F008: client=localhost[127.0.0.1]

Oct 24 03:00:02 localhost postfix/cleanup[34146]: 676E323F008: message-id=<20121101173439.676E323F008@mail.example.com>

Oct 24 03:00:02 localhost postfix/qmgr[64388]: 676E323F008: from=, size=564, nrcpt=1 (queue active)

Oct 24 03:00:02 localhost postfix/smtpd[33884]: disconnect from localhost[127.0.0.1]

Oct 24 03:00:02 localhost postfix/virtual[34147]: 676E323F008: to=, relay=virtual, delay=0.14, delays=0.1/0/0/0.04, dsn=2.0.0, status=sent (delivered to maildir)

Oct 24 03:00:02 localhost postfix/qmgr[64388]: 676E323F008: removed

connect from localhost[127.0.0.1] 

这一行日志告诉了我们是从本地localhost登录,并且登录成功了。继而发信也成功了!

总结:extmail默认是用127.0.0.1来连接本地的Postfix服务器来发信,而不是通过用户认证的方式来发信,而foxmail等则是通过客户端认证来连接到服务器。而此前我在配置文件中只允许了认证用户登录,而没有添加mynetworks的允许,所以导致了上述问题的出现。

--------------------------------------------------------------------------------------------------2012.11.02

问题17  foxmail发信提示rcpt错误

说是用户名未找到。可我extmail中确定是有此用户的

解决:

出现以上问题,其实是因为我们开启了用户发信验证,而配置文件又缺少了 smtpd_sender_login_maps = 这行参数。

具体情况,请参阅 http://coolerfeng.blog.51cto.com/133059/48317 这篇博客!

再次修改配置文件,增加smtpd_sender_login_maps参数

#alter smtp_sender_restrictions

smtpd_sender_restrictions =

reject_sender_login_mismatch,

reject_non_fqdn_sender,

reject_authenticated_sender_login_mismatch,

reject_unauthenticated_sender_login_mismatch,

#       reject_non_fqdn_hostname,

reject_non_fqdn_recipient,

reject_invalid_hostname,

reject_unknown_sender_domain,

check_sender_access hash:/etc/postfix/sender_access

smtpd_sender_login_maps =        <-----新增加的

mysql:/etc/postfix/mysql_virtual_sender_maps.cf,     <-----新增加的

mysql:/etc/postfix/mysql_virtual_alias_maps.cf       <-----新增加的

重新载入配置文件

localhost# postfix reload

postfix/postfix-script: refreshing the Postfix mail system

再用foxmail发信,提示发信成功了!

qq邮箱顺利收到发出的邮件,成功!

--------------------------------------------------------------------------

2012.11.27

问题18  出现maildrop访问拒绝。

[root@localhost extmail]# tail /var/log/maillog

Nov 27 09:24:33 localhost postfix/pickup[725]: fatal: scan_dir_push: open directory maildrop: Permission denied

Nov 27 09:24:34 localhost postfix/master[26729]: warning: process /usr/libexec/postfix/pickup pid 725 exit status 1

[root@localhost extmail]# ll /var/spool/postfix/

总计 56

drwx------ 2 vuser root     4096 11-26 16:56 active

drwx------ 2 vuser root     4096 11-26 16:56 bounce

drwx------ 2 vuser root     4096 11-26 16:56 corrupt

drwx------ 2 vuser root     4096 11-26 16:56 defer

drwx------ 2 vuser root     4096 11-26 16:56 deferred

drwx------ 2 vuser root     4096 11-26 16:56 flush

drwx------ 2 vuser root     4096 11-26 16:56 hold

drwx------ 2 vuser root     4096 11-26 16:56 incoming

drwx-wx--- 2 vuser postdrop 4096 11-27 04:02 maildrop

drwxr-xr-x 2 root  root     4096 11-26 17:51 pid

drwx------ 2 vuser root     4096 11-26 17:28 private

drwx--x--- 2 vuser postdrop 4096 11-26 17:28 public

drwx------ 2 vuser root     4096 11-26 16:56 saved

drwx------ 2 vuser root     4096 11-26 16:56 trace

分析:postfix在执行的时候,会读取/var/spool/postfix/maildrop文件夹中的内容,但是由于maildrop是属于vuser和postdrop组的,而执行postfix程序的用户是postfix。maildrop的权限为731。postfix用户就无法读取了

出现上述原因是因为我一开始在新建postfix用户时指定id为1000,然后安装postfix,但后来我把postfix用户的id改了,然后新建了一个用户vuser,把id指为1000。导致原本属于postfix用户的文件夹变成了vuser的了。

解决:把用户改回来即可

[root@localhost extmail]# id vuser

uid=1000(vuser) gid=1000(vuser) groups=1000(vuser)

[root@localhost extmail]# id postfix

uid=25(postfix) gid=25(postfix) groups=25(postfix),1200(postdrop)

[root@localhost extmail]# chown -R postfix /var/spool/postfix/*

[root@localhost extmail]# postfix  reload               

postfix/postfix-script: refreshing the Postfix mail system

没有上述错误提示了。

---------------------------------------------------------------------------

2012.11.27

问题20  访问extmail出现

“Can't chdir to /opt/mailbox/test.com/test1/Maildir/, No such file or directory”报错,用户无法进入extmail邮箱。如图:

分析:

1,查看日志

[root@localhost extmail]# tail /var/log/maillog

Nov 27 10:09:21 localhost extmail[2286]: user=, client=113.97.240.45, module=login, status=loginok

日志中就只有这一条有用的信息。没有任何错误提示。

2,查看对应的文件夹,可看到mailbox根文件夹内为空,邮件目录未自动创建。

[root@localhost extmail]# ll /opt/mailbox/         

总计 0

3,更改权限为777,再重新在extman中建立新的域和用户

[root@localhost extmail]# chmod 777 -R /opt/mailbox/

[root@localhost extmail]# ll /opt/mailbox/ -d

drwxrwxrwx 2 vuser vuser 4096 11-27 10:03 /opt/mailbox/

4,结果仍然是什么都没有。

5,重新检查main.cf配置文件,找到原因,原来掉了一项virtual_transport选项。

解决:

将virtual_transport参数加上,该参数默认值为virtual。

[root@localhost extmail]# vim /etc/postfix/main.cf

virtual_uid_maps = static:1000

virtual_gid_maps = static:1000

virtual_transport = virtual

[root@localhost extmail]# postfix  reload

在extman中将原来的未生效的域test.com删除再重新建立。删除域的时候要先将用户删除,再删别名,最后删域。否则删除会失败。

总结:必需在main.cf中指定virtual_transport,且值为virtual。不指定这个参数或指定值错误都会导致收发邮件出问题。在下面问题21中就是因为错误的参数值而造成收信。

virtual_transport定义邮件投递代理类型,默认为virtual,这个virtual类型会将发来的邮件根据$virtual_mailbox_maps 中的定义来将邮件投递到指定的域,没有这个参数,那么postfix收下的邮件就不知道放哪里,所以就不会自动创建域和用户目录了。。

参考:http://www./postconf.5.html#virtual_transport

http://www./virtual.8.html

---------------------------------------------------

2012.11.28

问题21  信件发出后无任何错误提示,但收件方却收不到刚发的邮件。

maillog日志:

Nov 27 15:29:54 localhost postfix/qmgr[13975]: warning: connect to transport private/vuser: No such file or directory

Nov 27 15:29:54 localhost postfix/qmgr[13975]: D48E35DD15A: from=, size=608, nrcpt=1 (queue active)

Nov 27 15:29:54 localhost postfix/error[14398]: 334DC5DD178: to=, relay=none, delay=1104, delays=1104/0.01/0/0.01, dsn=4.3.0, status=deferred (mail transport unavailable)

有用信息为:

warning: connect to transport private/vuser: No such file or directory

localhost postfix/error

status=deferred (mail transport unavailable)

找了好久的原因。最后发现原来是main.cf中的virtual_transport 配置错误。

[root@localhost ~]# vim /etc/postfix/main.cf

virtual_transport = vuser    <------原来的配置

要将其改为virtual

virtual_transport=virtual    <------现在的配置

[root@localhost ~]# postfix  reload

再次发信,再次查看日志情况。

[root@localhost ~]# tail /var/log/maillog

Nov 27 15:41:56 localhost postfix/qmgr[14519]: 9151D5DD17E: from=, size=605, nrcpt=1 (queue active)

Nov 27 15:41:56 localhost postfix/smtpd[14532]: disconnect from localhost.localdomain[127.0.0.1]

Nov 27 15:41:56 localhost postfix/virtual[14582]: 9151D5DD17E: to=, relay=virtual, delay=0.05, delays=0.05/0/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)

问题解决!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多