|
发表于 2013-4-5 16:15:38
|
|阅读模式
来自 中国广东广州
继postfix+extmail+mysql虚拟用户邮件体系的搭建之后的一篇文章
参考网络文章,整理了一下,记录下来
环境:Centos5.5,安装base,Development Tools,Development Libraries。后一项选择的所有可选包。
关闭sendmail,并将它的随系统自动启动功能关闭:
# service sendmail stop
# chkconfig sendmail off
接下来配置邮件服务器
web平台:lamp
web用户界面及后台管理: extmail extman。以前一直用这个,页面美观,易操作。易管理。
SMTP服务器:postfix2.8
pop3服务器:dovecot2.0
MDA服务器:maildrop2.5
验证服务器:dovecot做smtp验证,courier-authlib做pop3验证。
杀毒+反垃圾:mailscanner+clamav+spamassassin,之所以用这个组合一个是maillscanner功能很强大。
主要软件都是最新的版本。看起来会比那些老文档爽吧,而且网上对dovecot+maildrop的组合用的好像不是很多,我个人觉得这个组合效率应该不比courier套件的组合低。我用maildrop主要也是为实现自动回复的功能。
安装配置前准备:LAMP(略)
1.改主机名(非必要,但别是除localhost之外的其他主机名了,修改主机名也是为了避免出现不必要的错误)
# vim /etc/sysconfig/network
HOSTNAME=mail.zhaoyuefei.com
# hostname mail.zhaoyuefei.com
注销再登陆,验证一下:
[root@mail ~]# hostname
mail.zhaoyuefei.com
[root@mail ~]# uname -n
mail.zhaoyuefei.com
2.DNS解析设置
这里为内外环境,在本机和服务器端的hosts文件中加入
192.168.1.107 mail.zhaoyuefei.com
3.lamp安装配置(略),确保lamp没有问题
4.安装courier-authlib,maildrop
安装前先建立想要建立相关的用户信息
groupadd postdrop
groupadd -g 1000 postfix
useradd -u 1000 -g postfix -s /sbin/nologin -G postdrop postfix
groupadd dovecot
useradd -s /sbin/nologin -g dovecot dovecot
groupadd -g 1010 vmail
useradd -u 1010 -g vmail -d /mailbox -s /sbin/nologin vmail
建立存放虚拟域,用户及邮件的目录
mkdir /mailbox
chown -R vmail.vmail /mailbox
建立所需的数据库
tar zxvf extman-1.1.tar.gz
cd extman-1.1/docs
mysql -uroot -p < extmail.sql
mysql -uroot -p < init.sql
# tar xvf courier-authlib-0.63.0.tar.bz2
# cd courier-authlib-0.63.0
# ./configure --with-redhat --with-authmysql=yes --with-mailuser=vmail --with-mailgroup=vmail --with-mysql-libs=/usr/local/webserver/mysql/lib --with-mysql-includes=/usr/local/webserver/mysql/include --prefix=/usr/local/authlib --without-stdheaderdir
# make && make install
configure: error: Cannot find either the gdbm or the db library.
如果出现上述错误,解决方案是安装下面的软件在进行
# yum install gdbm-devel -y
# cd /usr/local/authlib/etc/authlib/
# cp authdaemonrc.dist authdaemonrc
# cp authmysqlrc.dist authmysqlrc
编辑authdaemonrc,确保为以下内容:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
authdaemonvar=/usr/local/authlib/var/spool/authdaemon
DEBUG_LOGIN=0
DEFAULTOPTIONS=""
LOGGEROPTS=""
其中前三行是需要自行修改的
编辑authmysqlrc确保为以下内容:
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
DEFAULT_DOMAIN zhaoyuefei.com
MYSQL_UID_FIELD uidnumber
MYSQL_GID_FIELD gidnumber
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD homedir
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,
CONCAT("/mailbox/",homedir),CONCAT("/mailbox/",maildir),\
quota,name from mailbox\
where username="$(local_part)@$(domain)";
注:MYSQL_SELECT_CLAUSE......应用这个查询语句的目的是为了取得maildrop的自动回复功能
如果后面测试出现:maildrop[23819]: Temporary authentication failure.
将上面的sql查询语句改为一行来写
设置authlib的共享库:
# echo "/usr/local/authlib/lib/courier-authlib" >> /etc/ld.so.conf
# ldconfig
拷贝安装包内的courier-authlib.sysvinit到/etc/init.d下:
cp courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod 755 /etc/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig --level 2345 courier-authlib on
service courier-authlib start
chmod +x /usr/local/authlib/var/spool/authdaemon
ln -sv /usr/local/authlib/bin/courierauthconfig /usr/bin
ln -sv /usr/local/authlib/include/* /usr/include
注:上面两个连接文件在安装maildrop时,会去相应目录检查这些文件。
# tar xvf maildrop-2.5.5.tar.bz2
# cd maildrop-2.5.5
# ./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root vmail' --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1010 --enable-maildrop-gid=1010 --with-trashquota --with-dirsync
# make && make install
安装完成以后用命令maildrop -v检查一下是否支持courier认证,显示以下信息,表明正确安装。如果没有第二行,很可能是courier安装时没有指定vmail用户,或者courierauthconfig没有连接正确
[root@mail ~]# maildrop -v
maildrop 2.5.5 Copyright 1998-2005 Double Precision, Inc.
GDBM/DB extensions enabled.
Courier Authentication Library extension enabled.
Maildir quota extension are now always enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.
如果提示:maildrop: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
编辑/etc/ld.so.conf加入/usr/local/lib
# ldconfig
编辑maildrop日志文件
# vim /etc/maildroprc 添加
logfile "/var/log/maildrop.log"
# touch /var/log/maildrop.log
# chown -R vmail.vmail /var/log/maildrop.log
这个文件要自行建立,而且权限要正确,否则在测试时会出现“不能建立这个文件”。
=========================================================================
5.postfix+dovecot
(1)安装
编译postfix时把sasl验证改为dovecot。并且使用自动安装方式,省去交互式安装需要手动按回车的麻烦,我这里是安照默认安装的路径。
rpm -e postfix --nodeps #卸载自带的postfix
postfix还依赖一些包
yum install openssl
yum install openssl-devel
yum install db*
还有记得上面mysql的库文件要加到ld.so.conf中,并使之生效。
# echo "/usr/local/webserver/mysql/lib/mysql/" >> /etc/ld.so.conf
# tar xvf postfix-2.8.10.tar.gz
# cd postfix-2.8.10
# chmod 755 ./postfix-install
# ln -sv /usr/local/webserver/mysql/lib/mysql /usr/lib/mysql
# ln -sv /usr/local/webserver/mysql/include/mysql /usr/include/mysql
# make makefiles CCARGS='-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH \
-DDEF_SERVER_SASL_TYPE=\"dovecot\" -DUSE_TLS -I/usr/include' AUXLIBS='-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto'
# make
# ./postfix-install -non-interactive \
install_root=/ tempdir=/tmp \
config_directory=/etc/postfix \
command_directory=/usr/sbin \
daemon_directory=/usr/libexec/postfix \
data_directory=/var/lib/postfix \
html_directory=no \
mail_owner=postfix \
mailq_path=/usr/bin/mailq \
manpage_directory=/usr/local/man \
newaliases_path=/usr/bin/newaliases \
queue_directory=/var/spool/postfix \
readme_directory=no \
sendmail_path=/usr/sbin/sendmail \
setgid_group=postdrop
生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
# newaliases
# tar xvf dovecot-2.0.20.tar.gz
# cd dovecot-2.0.20
# ./configure --prefix=/usr/local/dovecot --sysconfdir=/etc --localstatedir=/var --with-sql --with-mysql --with-ssl=openssl
# make && make install
(2)配置
postconf -n > /etc/postfix/main.cf.new #把默认的main.cf中的有效配置提取出来.
mv /etc/postfix/main.cf /etc/postfix/main.cf.bak
mv /etc/postfix/main.cf.new /etc/postfix/main.cf
下面是我的main.cf配置:
# sed -e /^#/d /etc/postfix/main.cf
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/local/man
sample_directory = /etc/postfix
unknown_local_recipient_reject_code = 550
#smtpd_peername_lookup = no
readme_directory = no
header_checks = regexp:/etc/postfix/header_checks #这个配置是调用MailScanner用的,可以不加。
mydomain = zhaoyuefei.com
myhostname = mail.zhaoyuefei.com
myorigin = $mydomain
inet_interfaces = all
mydestination =
mynetworks_style = subnet
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/ #邮箱格式为Maildir
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
virtual_mailbox_base = /mailbox #我的邮箱目录
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
# mysql_virtual_mailbox_maps.cf这个文件可以从extman解压包中的doc目录中取得
# 下面的三个mysql_virtual.....文件也同样从extman的doc中取得,拷贝到相应目录即可
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:1010 #vmail的ID
virtual_gid_maps = static:1010
virtual_transport = maildrop: #使用maildrop做本地的投递
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit=1
message_size_limit = 14336000 #邮件大小的限制,网上有的说是限制附件这不准确
virtual_mailbox_limit = 209715200
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_mailbox_limit_message = sorry,the user'smaildir has overdrawn his diskspace quota,please try again later.
virtual_overquota_bounce = yes
smtpd_banner = $myhostname ESMTP unknow #添加这一行,不显示SMTP服务器的相关信息
编辑dovecot配置文件
cp /usr/local/dovecot/share/doc/dovecot/example-config/dovecot.conf /etc/dovecot/
cp /usr/local/dovecot/share/doc/dovecot/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-mysql.conf
两个关键的配置样例文件在安装目录的share/doc下,拷贝到指定的存放配置文件的目录(根据安装时的选项)。
原创文章来自:http://www.tvvcd.com/news/84848/ |
|