配置Postfix支持虚拟用户
软件包
[root@BENET3 benet]# ls
dovecot-1.1.4.tar.gz postfix-2.4.6.tar.gz zh_CN-1.4.13-20071220.tar.bz2
extmail-1.0.5.tar.gz postfix-2.4.6-vda-ng.patch.gz
extman-0.2.5.tar.gz squirrelmail-1.4.13.tar.bz2
[root@BENET3 benet]#
邮件系统账号已有
[root@BENET3 ~]# cat /etc/group | grep postdrop
postdrop:x:90:
[root@BENET3 ~]# cat /etc/group | grep postfix
mail:x:12:mail,postfix
postfix:x:89:
解压释放源码包、合并VGA补丁
[root@BENET3 benet]# tar zxf postfix-2.4.6.tar.gz -C /usr/src/
[root@BENET3 benet]# cp postfix-2.4.6-vda-ng.patch.gz /usr/src/postfix-2.4.6/
[root@BENET3 benet]# cd /usr/src/postfix-2.4.6/
[root@BENET3 postfix-2.4.6]# gunzip postfix-2.4.6-vda-ng.patch.gz
[root@BENET3 postfix-2.4.6]# patch -p1 < postfix-2.4.6-vda-ng.patch
patching file README_FILES/VDA_README
patching file src/global/mail_params.h
patching file src/util/file_limit.c
patching file src/virtual/mailbox.c
patching file src/virtual/maildir.c
patching file src/virtual/virtual.c
patching file src/virtual/virtual.h
[root@BENET3 postfix-2.4.6]#
制作一个编译的脚本
[root@BENET3 postfix-2.4.6]# vi build.sh
make makefiles \
> 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \
> -DUSE_SASL_AUTH \
> -DUSE_CYRUS_SASL -I/usr/include/sasl' \
> 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm \
> -L/usr/lib/sasl2 -lsasl2 '
~
~
~
...//中间波浪号省略
~
~
~
:wq
执行
[root@BENET3 postfix-2.4.6]# sh build.sh
执行结果
[root@BENET3 postfix-2.4.6]# sh build.sh
build.sh: line 1: CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \
> -DUSE_SASL_AUTH \
> -DUSE_CYRUS_SASL -I/usr/include/sasl: No such file or directory
[root@BENET3 postfix-2.4.6]#
重新修改脚本
[root@BENET3 postfix-2.4.6]# vim build.sh
make makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \
-DUSE_SASL_AUTH \
-DUSE_CYRUS_SASL -I/usr/include/sasl' \
'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm \
-L/usr/lib/sasl2 -lsasl2 '
~
~
~
~
...//中间省略
~
~
~
:wq
再次执行
[root@BENET3 postfix-2.4.6]# sh build.sh
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
set +e; if cmp makedefs.tmp conf/makedefs.out; then rm makedefs.tmp; \
else mv makedefs.tmp conf/makedefs.out; fi >/dev/null 2>/dev/null
set -e; for i in src/util src/global src/dns src/tls src/xsasl src/milter src/master src/postfix src/smtpstone src/sendmail src/error src/pickup src/cleanup src/smtpd src/local src/trivial-rewrite src/qmgr src/oqmgr src/smtp src/bounce src/pipe src/showq src/postalias src/postcat src/postconf src/postdrop src/postkick src/postlock src/postlog src/postmap src/postqueue src/postsuper src/qmqpd src/spawn src/flush src/verify src/virtual src/proxymap src/anvil src/scache src/discard src/tlsmgr; do \
(set -e; echo "[$i]"; cd $i; rm -f Makefile; \
make -f Makefile.in Makefile MAKELEVEL=) || exit 1; \
done;
[src/util]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/global]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/dns]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/tls]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/xsasl]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/milter]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/master]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postfix]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/smtpstone]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/sendmail]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/error]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/pickup]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/cleanup]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/smtpd]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/local]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/trivial-rewrite]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/qmgr]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/oqmgr]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/smtp]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/bounce]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/pipe]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/showq]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postalias]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postcat]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postconf]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postdrop]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postkick]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postlock]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postlog]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postmap]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postqueue]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/postsuper]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/qmqpd]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/spawn]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/flush]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/verify]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/virtual]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/proxymap]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/anvil]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/scache]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/discard]
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/tlsmgr]
cat ../../conf/makedefs.out Makefile.in >Makefile
rm -f Makefile; (cat conf/makedefs.out Makefile.in) >Makefile
[root@BENET3 postfix-2.4.6]#
make
[root@BENET3 postfix-2.4.6]# make
make结束后的错误提示
...//前面省略
dict_mysql.c:396: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c:396: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:398: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c:398: error: ‘HOST’ has no member named ‘ts’
dict_mysql.c:398: error: ‘HOST’ has no member named ‘ts’
dict_mysql.c: In function ‘dict_mysql_get_active’:
dict_mysql.c:447: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:463: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:465: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c: In function ‘dict_mysql_event’:
dict_mysql.c:479: error: ‘HOST’ has no member named ‘db’
dict_mysql.c: At top level:
dict_mysql.c:490: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
dict_mysql.c: In function ‘plmysql_connect_single’:
dict_mysql.c:542: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:544: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:545: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:545: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:549: error: ‘HOST’ has no member named ‘port’
dict_mysql.c:550: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:550: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:554: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:555: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c:558: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:558: error: ‘HOST’ has no member named ‘db’
dict_mysql.c: In function ‘plmysql_close_host’:
dict_mysql.c:566: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:567: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:568: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c: In function ‘plmysql_down_host’:
dict_mysql.c:577: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:578: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:579: error: ‘HOST’ has no member named ‘ts’
dict_mysql.c:580: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c: In function ‘host_init’:
dict_mysql.c:707: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:708: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:709: error: ‘HOST’ has no member named ‘port’
dict_mysql.c:710: error: ‘HOST’ has no member named ‘stat’
dict_mysql.c:711: error: ‘HOST’ has no member named ‘ts’
dict_mysql.c:719: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:723: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:725: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:726: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:727: error: ‘HOST’ has no member named ‘port’
dict_mysql.c:728: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:730: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:731: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:732: error: ‘HOST’ has no member named ‘type’
dict_mysql.c:737: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:737: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:738: error: ‘HOST’ has no member named ‘port’
dict_mysql.c:738: error: ‘HOST’ has no member named ‘type’
dict_mysql.c: In function ‘plmysql_dealloc’:
dict_mysql.c:772: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:773: error: ‘HOST’ has no member named ‘db’
dict_mysql.c:774: error: ‘HOST’ has no member named ‘hostname’
dict_mysql.c:775: error: ‘HOST’ has no member named ‘name’
dict_mysql.c:776: error: ‘HOST’ has no member named ‘name’
make: *** [dict_mysql.o] Error 1
make: *** [update] Error 1
[root@BENET3 postfix-2.4.6]#
查看是否安装mysql
[root@BENET3 postfix-2.4.6]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
mysql-devel-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
[root@BENET3 postfix-2.4.6]#
排错
[root@BENET3 postfix-2.4.6]# locate mysql.h
/usr/include/mysql/mysql.h
/usr/share/doc/rsyslog-5.8.10/ommysql.html
/usr/share/doc/rsyslog-5.8.10/rsyslog_mysql.html
/usr/src/postfix-2.4.6/src/global/dict_mysql.h
[root@BENET3 postfix-2.4.6]#
重新修改脚本
[root@BENET3 postfix-2.4.6]# vi build.sh
make makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/include/mysql \
-DUSE_SASL_AUTH \
-DUSE_CYRUS_SASL -I/usr/include/sasl' \
'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm \
-L/usr/lib/sasl2 -lsasl2 '
~
...//中间波浪号省略
~
:wq
测试
[root@BENET3 postfix-2.4.6]# make tidy
...//省略
[root@BENET3 postfix-2.4.6]# sh build.sh
...//省略
[root@BENET3 postfix-2.4.6]# make
...//省略
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status
make: *** [master] Error 1
make: *** [update] Error 1
[root@BENET3 postfix-2.4.6]#
根据错误提示排错
[root@BENET3 postfix-2.4.6]# locate mysqlclient
/usr/lib64/mysql/libmysqlclient.so
/usr/lib64/mysql/libmysqlclient.so.16
/usr/lib64/mysql/libmysqlclient.so.16.0.0
/usr/lib64/mysql/libmysqlclient_r.so
/usr/lib64/mysql/libmysqlclient_r.so.16
/usr/lib64/mysql/libmysqlclient_r.so.16.0.0
[root@BENET3 postfix-2.4.6]#
根据路径修改脚本
[root@BENET3 postfix-2.4.6]# vi build.sh
make makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/include/mysql \
-DUSE_SASL_AUTH \
-DUSE_CYRUS_SASL -I/usr/include/sasl' \
'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm \
-L/usr/lib/sasl2 -lsasl2 '
~
~
...//中间省略
~
~
-- INSERT --
再次测试
[root@BENET3 postfix-2.4.6]# make tidy
...//省略
[root@BENET3 postfix-2.4.6]# sh build.sh
...//省略
[root@BENET3 postfix-2.4.6]# make
...//省略
[src/discard]
gcc -Wmissing-prototypes -Wformat -DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -g -O -I. -I../../include -DLINUX2 -c discard.c
gcc -Wmissing-prototypes -Wformat -DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -g -O -I. -I../../include -DLINUX2 -o discard discard.o ../../lib/libmaster.a ../../lib/libglobal.a ../../lib/libutil.a -L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -ldb -lnsl -lresolv
cp discard ../../libexec
[src/tlsmgr]
gcc -Wmissing-prototypes -Wformat -DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -g -O -I. -I../../include -DLINUX2 -c tlsmgr.c
gcc -Wmissing-prototypes -Wformat -DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -g -O -I. -I../../include -DLINUX2 -o tlsmgr tlsmgr.o ../../lib/libmaster.a ../../lib/libtls.a ../../lib/libglobal.a ../../lib/libutil.a -L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -ldb -lnsl -lresolv
cp tlsmgr ../../libexec
[root@BENET3 postfix-2.4.6]#
这次没有报错
总结:我认为是因为自己的mysql是在最小化安装的时候选择安装的,而不是自己编译安装的, 如果是自己编译安装,那么按照最开始的去做就可以。简单说就是两种安装方式,文件的路径是有差异的。
make install
[root@BENET3 postfix]# make install
...//
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/VERP_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/VIRTUAL_README...
Updating /usr/share/doc/postfix-2.6.6/README_FILES/XCLIENT_README...
Updating /usr/share/doc/postfix-2.6.6/README_FILES/XFORWARD_README...
postfix: warning: valid_hostname: numeric hostname: 0
postfix: fatal: file /etc/postfix/main.cf: parameter mydomain: bad parameter value: 0
make: *** [install] Error 1
[root@BENET3 postfix-2.4.6]#
继续排错
[root@BENET3 postfix]# hostname
BENET3.0
估计是和这个有关系
将hostname改成benet之后重启
[root@BENET ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=BENET
[root@BENET ~]#
再次执行make install
[root@BENET postfix-2.4.6]# make install
...//中间省略
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/STANDARD_CONFIGURATION_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/TLS_LEGACY_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/TLS_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/TUNING_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/ULTRIX_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/UUCP_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/VERP_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/VIRTUAL_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/XCLIENT_README...
Skipping /usr/share/doc/postfix-2.6.6/README_FILES/XFORWARD_README...
[root@BENET postfix-2.4.6]#
设置测试用户
[root@mail log]# useradd xiaoqi
[root@mail log]# useradd lisi
[root@mail log]# passwd xiaoqi
Changing password for user xiaoqi.
New password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@mail log]# passwd lisi
Changing password for user lisi.
New password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@mail log]#
测试
[root@mail log]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 benet.com ESMTP Postfix
HELO locahost
250 benet.com
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
DAT
502 5.5.2 Error: command not recognized
data
354 End data with <CR><LF>.<CR><LF>
subject: A test Mail
HELLO!
This is test mail to test postfix!
.
250 2.0.0 Ok: queued as 495271025B6
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail log]#
查看
[root@mail new]# pwd
/home/lisi/Maildir/new
[root@mail new]# date
Fri Jul 22 22:45:44 CST 2016
[root@mail new]# ls -l
total 4
-rw-------. 1 lisi lisi 461 Jul 22 22:42 1469198568.Vfd00I20eM984903.mail.benet.com
[root@mail new]# cat 1469198568.Vfd00I20eM984903.mail.benet.com
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from locahost (localhost [IPv6:::1])
by benet.com (Postfix) with SMTP id 495271025B6
for <[email protected]>; Fri, 22 Jul 2016 22:40:46 +0800 (CST)
subject: A test Mail
Message-Id: <[email protected]>
Date: Fri, 22 Jul 2016 22:40:46 +0800 (CST)
From: [email protected]
To: undisclosed-recipients:;
HELLO!
This is test mail to test postfix!
[root@mail new]#