zoukankan      html  css  js  c++  java
  • 最具体的历史centos下一个 postfix + extmail + dovecot + maildrop 安装注意事项2014更新

    这篇文章原本是2008年发表的,近期几天照此笔记又安装了一遍系统。这里更新一下记录。
    作者:wangdy

    本文发表于  http://blog.csdn.net/aryang/article/details/40593283  转载请注明!



    1. 概述
    安装环境是CentOS6.5,拿到server的时候仅仅有根文件夹的分区。邮件准备存储到 /var/mailbox下,后面内容会出现多次,假设要改动请注意不要有遗漏的地方。
    /var/spool/postfix是postfix存储队列的地方。 /var/vmail是用来存储邮件的。
    有条件的建议对 /var/spool/postfix和 /var/vmail进行了单独分区。

    CentOS提供了非常方便的yum在线安装。我的基本原则是非重要、对版本号不敏感的模块尽量用yum安装。邮件系统主要模块则用源代码编译安装。


    首先用yum安装的模块有:mysql mysql-server mysql-devel db4-devel openssl gcc libxml2 libxml2-develgcc-c++
    几个模块都须要用到PCRE。



    先说明一下几个模块的搭配。

    MTA用的是postfix-2.5.17。



    web模块是最先须要确定的,由于它决定了邮箱系统最核心的数据结构,这里选用国产的extmail,其它全部模块都依照extmail的结构进行配置改动。
    webmail使用 extmail-1.0.5,web管理模块用extman-0.2.5。



    extmail对maildrop的自己主动回复、转发等提供了非常好的支持。所以MDA採用最流行的maildrop(2.5.4)

    这里面简单说一下为什么要用maildrop。

    对虚拟用户投递的支持。postfix自带了一个投递代理(MDA):virtual
    virtual投递代理在 master.cf里描写叙述为:

    virtual  unix -      n       n      -       -      virtual

    假设我们在main.cf里设置virtual_transport = virtual。就表示对于包括在 virtual_mailbox_domains域名里的邮件。都使用virtual进行投递。
    postfix自带的virtual仅仅提供了最主要的QUOTA功能。假设想使用更复杂的功能,如自己主动转发,自己主动回复。邮件自己定义过滤等,就须要换成更高级的MDA。
    当然可选择的MDA有非常多种,比方procmail, maildrop等。

    我这里选用maildrop。

    用户信息存储方式也有非常多可选的。比方mysql,ldap等。这里选mysql,原因是各个模块,包含extmail等对这个支持最好最方便最简单。

    maildrop在投递邮件的时候。须要确定一些数据,比方收件用户的Maildir的路径,保存邮件用的uid,gid,邮箱容量等。这些数据须要 courier-authlib来提供。

    整个系统模块间的作用和关系是:

    postfix作为MTA(Mail Transfer Agent), 负责创建smtp服务(smtpd)接收本域用户或其它域名server投递来的邮件。负责向其它server投递(转发)邮件,管理邮件队列;
    maildrop作为MDA(Mail Delivery Agent)负责把从postfix接收到邮件存入邮件夹,同一时候还支持自己主动转发、自己主动回复。邮件过滤等功能;
    courier-authlib 为 maildrop 提供与用户相关的信息查询;
    dovecot提供系统的POP3和IMAP服务,同一时候给postfix提供SMTP的SASL认证服务。

    2. 系统基础配置

    假设系统已经安装postfix请先卸载!



    创建邮箱存储文件夹 /var/mailbox ,子文件夹结构为 ./[domain]/[username]
    创建负责邮件存取的用户和组帐户 vmail。注意要指定uid和gid。这两个id在后面非常多配置里要用到!
    #groupadd -g 1001 vmail
    #useradd -g vmail -u 1001 -s /sbin/nologin

    #chown vmail:vmail /var/mailbox
    #chmod 700 /var/mailbox

    postfix安装的是须要指定几个专门的用户和组
    #groupadd -g 2001 postfix
    #useradd -g postfix -u 1001 -s /sbin/nologin -M postfix
    #groupadd-g 2002 postdrop
    #useradd-g postdrop -u 2002 -s /bin/false -M postdrop

    3. courier-authlib安装

    下载 courier-authlib-0.66.1

     ./configure --sysconfdir=/etc --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-mailuser=1001 --with-mailgroup=1001

    注意此处已经用到了vmail用户的uid和gid!

    #cp /etc/authdaemonrc.dist /etc/authdaemonrc

    改动配置文件,启用mysql用户认证方式:

    #authmodulelist="authuserdb authmysql authcustom authpipe"
    authmodulelist="authmysql"

    #authmodulelistorig="authuserdb authmysql authcustom authpipe"
    authmodulelistorig="authmysql"

    authmysql的配置文件:
    #cp /etc/authmysqlrc.dist /etc/authmysqlrc

    改动相关配置,当中

    MYSQL_USER_TABLE        mailbox
    MYSQL_CRYPT_PWFIELD     crypt

    MYSQL_SELECT_CLAUSE     SELECT username as id,password as crypt,"" as clear,
                            '1001' as uid,'1001' as gid,  
                            CONCAT('/var/mailbox/',homedir) as home,    
                            CONCAT('/var/mailbox/',maildir) as maildir,  
                            quota,                                      
                            name                                        
                            FROM mailbox                                
                            WHERE  active = 1 and username = '$(local_part)@$(domain)'

    事实上就是配置了数据源是什么(mysql)。怎么连接,运行什么sql语句查询用户信息,数据的字段名是什么等。



    启动auth服务 
    # /usr/local/libexec/courier-authlib/authdaemond &

    4. Dovecot安装
     
     下载dovecot-2.0.21.tar.gz
    #./configure--prefix=/usr/local/dovecot --sysconfdir=/etc --with-sql --with-mysql
    #make
    #make install

    须要ssl支持能够加上參数--with-ssl=openssl

    拷贝 doc/example-config/下的 dovecot.conf 至 /etc/dovecot

    配置dovecot.conf:
    base_dir=/var/run/dovecot
    #支持的用户协议
    protocols=imap imaps pop3 pop3s
    listen=*
    disable_plaintext_auth = no
    #是否启用ssl
    ssl_disable = yes
    #邮件存储位置,%d表示域名,%n表示username
    mail_location= maildir:/var/vmail/%d/%n/Maildir
    pop3_uidl_format=%08Xu%08Xv
    authdefault {
    ...
    mechanisms= plain login digest-md5 cram-md5
            
    #验证password的配置文件
    passdb sql { 
             args = /etc/dovecot/dovecot-sql.conf
    }
    ...
    #查询用户信息的配置文件
    userdbsql {
             args = /etc/dovecot/dovecot-sql.conf
    }
    ...
    socketlisten {
       ...
       client {
         path = /var/spool/postfix/private/auth
         mode = 0660
         user = postfix
         group = postfix
       }
    }
    }
     
    编辑/etc/dovecot/dovecot-sql.conf:

    driver =mysql
    connect =host=localhost dbname=extmail user=extmail password=extmail
    default_pass_scheme=MD5-CRYPT
    password_query= SELECT password, maildir as userdb_home FROM mailbox WHERE username = '%u'
    user_query= select 1001 as uid ,1001 as gid from mailbox where username='%u' And active='1'

    注意文件中的username口令。
    password_query是pop3 or imap登录的时候运行的,传username查密码,邮箱文件夹
    user_query是查询用户存取邮件用的uid和gid的,这里写死了。。

    创建符号链接
    #ln -s/usr/local/dovecot/sbin/dovecot /usr/bin/dovecot

    启动dovecot服务
    # dovecot

    假设出错。看看 /var/log/dovecot

    5. 安装 maildrop
    下载 maildrop-2.5.4.tar.gz

    ./configure--enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root vmail'--enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1001--enable-maildrop-uid=1001 --with-trashquota --with-dirsync
     
    make& make install
     
    /etc/postfix/master.cf里添加
     
    maildrop  unix -       n       n      -       -       pipe
      flags=DRhu user=vmailargv=/usr/local/bin/maildrop -d ${recipient}

    6. 安装 postfix

    下载postfix-2.5.17.tar.gz
     
    编译
    # make CCARGS='-DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE="dovecot"
    -DHAS_PCRE-DHAS_MYSQL
    -I/usr/include/-I/usr/local/include -I/usr/include/mysql/'
    AUXLIBS='-L/usr/local/lib-L/usr/lib/mysql -lmysqlclient -lpcre'
    # make
    # make install

    -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE="dovecot" 
    表示启用SASL身份认证,并默认使用dovecot。


    mysql的几个路径能够依据实际情况做改动,我这里的文件夹都是yum默认安装的。
     
    注意make參数里加上正确的mysql -I  (头文件所在文件夹) -L(动态库所在文件夹)
    make install的提问所有回车默认。


    (install的时候假设默认參数里没有值。请依据错误提示认真检查)
     
    导入extmail的mysql表结构和数据。


    下载extman-0.2.5.tar.gz
    解开后进入 docs文件夹

    建库建表:
    # mysql-u root -p < extmail.sql
    注意extmail.sql里配置的数据库,username,口令都是extmail。能够编辑脚本改动。


    extmail.sql里创建的数据库用户 webman 是用在web后台管理的,extmail用在全部其它地方,包含postfix邮件收发,dovecot帐户验证、邮件收发,webmail里等。
     
    导入初始数据:
    #mysql-u root -p < init.sql
    (能够先吧 init.sql文件中的extmail.org改成你自己的域名。或登录web管理后再加入域名)
    把文件夹下 mysql_*.cf所有拷贝至/etc/postfix

    # cpmysql_*.cf /etc/postfix/
    改动cf文件中的username口令

    继续配置 postfix
    # mv/etc/aliases /etc/aliases.old
    # ln -s/etc/postfix/aliases /etc/aliases
    # /usr/bin/newaliases

    编辑  /etc/postfix/main.cf
     
    #邮件server域名
    myhostname= mail.abc.com
    #邮箱域名
    mydomain= abc.com
    myorigin= localhost
    mydestination= $myhostname localhost localhost.$mydomain
    #能够信赖的网络,后面的permit_mynetworks 说的就是这
    mynetworks= 127.0.0.0/8
    inet_interfaces= all
    home_mailbox=  mbox
    smtpd_banner= Welcome to ESMTP Server
    #设置能够随意从本机转发邮件的域名,黑莓什么的可能用到
    #relay_domains=
    alias_maps=

    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= 450
    non_fqdn_reject_code= 450
    unknown_virtual_alias_reject_code= 450
    unknown_virtual_mailbox_reject_code= 450
    maps_rbl_reject_code= 450

    maximal_queue_lifetime= 1
    bounce_queue_lifetime= 0
     
    #=====================VritualMailbox settings=========================
    #查询域名的配置
    virtual_mailbox_domains= mysql:/etc/postfix/mysql_virtual_domains_maps.cf
    virtual_alias_domains=
    virtual_alias_maps= mysql:/etc/postfix/mysql_virtual_alias_maps.cf
    #用maildrop投递邮件!后面会安装
    virtual_transport= maildrop

    maildrop_destination_recipient_limit=1

    #====================QUOTA========================
    #设置邮件限制大小和邮箱最大容量
    message_size_limit= 500001000 
    mailbox_size_limit= 500001000
    virtual_mailbox_limit= 209715200
     
    #====================SASLESMTP Authenticat=================
    #注: smtpd说的是接收邮件client发送邮件的服务, smtp说的是给别的邮件server投递用的服务
    #这个得加yes,不然你就为互联网贡献一个垃圾邮件server
    smtpd_sasl_auth_enable= yes
    #这里用到了dovecot ^_^
    smtpd_sasl_type= dovecot
    smtpd_sasl_path= private/auth
    broken_sasl_auth_clients= yes
    smtpd_sasl_local_domain=
    smtpd_sasl_security_options= noanonymous
     
    #注意第二行起有空格
    #这个说的是邮件client(包含本域用户client和别的server投递进来的)提交收件人的时候做的检查
    # permit_sasl_authenticated 表示 smtp 鉴权通过的permit。其它几种情况全拒!


    smtpd_recipient_restrictions=
     permit_sasl_authenticated,
     permit_mynetworks,
     reject_invalid_hostname,
     reject_non_fqdn_hostname,
     reject_non_fqdn_sender,
     reject_non_fqdn_recipient,
     reject_unknown_sender_domain,
     reject_unknown_recipient_domain,
     reject_unauth_pipelining,
     reject_unauth_destination
    #check_recipient_access pcre:/etc/postfix/spamd_filter_access

    #reject_rbl_client sbl.spamhaus.org,
    #reject_rbl_client cblless.anti-spam.org.cn,

    #检查发信人
    smtpd_sender_restrictions=
     permit_sasl_authenticated,
     permit_mynetworks,
     reject_non_fqdn_sender,
     reject_unknown_sender_domain,
     reject_sender_login_mismatch,
     reject_authenticated_sender_login_mismatch,
     reject_unauthenticated_sender_login_mismatch

    smtpd_helo_required= yes
    smtpd_helo_restrictions=
     permit_sasl_authenticated,
     permit_mynetworks,
     reject_invalid_hostname

    smtpd_sender_login_maps=
     mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
     mysql:/etc/postfix/mysql_virtual_alias_maps.cf

    disable_vrfy_command= yes

    smtpd_client_restrictions=
     permit_mynetworks,
     check_client_access hash:/etc/postfix/access

    #=====================TLS=========================
    #smtp的tls支持,此处不详述
    smtpd_use_tls= yes
    smtpd_tls_security_level= may
    smtpd_tls_key_file= /etc/postfix/certs/mail.key
    smtpd_tls_cert_file= /etc/postfix/certs/mail.crt
    smtpd_tls_loglevel= 1
    smtpd_tls_session_cache_timeout= 3600s
    smtpd_tls_session_cache_database= btree:/var/spool/postfix/smtpd_tls_cache
    tls_random_source= dev:/dev/urandom

    readme_directory= no
    command_directory= /usr/sbin
    daemon_directory= /usr/libexec/postfix
    queue_directory= /var/spool/postfix
    mail_owner= postfix
    data_directory= /var/lib/postfix

    启动postfix

    #postfix

    启动后注意观察 /etc/log/maillog 里是否有错误信息
     
    7. 安装extmail和extman!



    extman是邮箱的后台管理web,注意webman.cf里的配置:

    邮箱的根文件夹:
    SYS_MAILDIR_BASE= /var/mailbox 

    SYS_DEFAULT_UID= 1001
    SYS_DEFAULT_GID= 1001

    SYS_MYSQL_USER= webman
    SYS_MYSQL_PASS= webman 
     
    extmail里的 webmail.cf
     
    SYS_MAILDIR_BASE= /var/mailbox
     
    祝您成功!

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    文件下载的几种方式
    获取文件的后缀名(转为数组) 字符串和变量的拼接 HTML中字符串和变量的拼接
    小程序之选择拍照或者本地相册
    实时显示时间
    uni-app事件冒泡 如何解决事件冒泡 推荐tap事件
    Codeforces Global Round 7 C. Permutation Partitions(组合数学)
    Codeforces Global Round 7 B. Maximums(逻辑)
    Codeforces Global Round 7 A. Bad Ugly Numbers(数学)
    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
    Codeforces Round #622 (Div. 2) B. Different Rules(数学)
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4675701.html
Copyright © 2011-2022 走看看