centos7.2下搭建postfix++dovecot+courier-authlib+extmail邮件收发系统

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.2下搭建postfix++dovecot+courier-authlib+extmail邮件收发系统相关的知识,希望对你有一定的参考价值。

centos7.2下搭建postfix++dovecot+courier-authlib+extmail邮件收发系统

 

专业的事由专业的人去做,现在DNS,mail邮箱系统基本都是专业的公司去做了,越来越少公司自己搭建DNS,mail等系统服务

这次由于服务器要迁移,公司的邮箱系统一直都是用开源的postfix的,只能自己折腾

在此记录一下,搭建全过程使用root账号,中间有一些错误调试的,都给忽略了,这里只给出最的配置

在文章最后面会有一些错误调试的记录


不管遇到什么错误,首先打印日志来看!

不管遇到什么错误,首先打印日志来看!

不管遇到什么错误,首先打印日志来看!


在网上大概了解了一下整个邮箱系统的组成: 

######################################### 

整个 extmail邮件系统,是由多个软件构成的: 

ExtMan           Web帐户管理后台(mailgraph_ext 图形日志分析) web管理

ExtMail          WebMail(perl 程序) web支持

Postfix          SMTP服务器,邮件传输代理(MTA),收发邮件

Maildrop         邮件投递代理(MDA) 

Courier-imap     IMAPPOP3 服务器 

Cyrus-sasl2      标准的SASL实现库,可以支持Courier Cyrus SMTP认证库 

Courier-authlib  负责courier-imap,maildrop的认证 Courier 数据认证库(mysql

MySQL            数据库,储存虚拟(|用户|别名)等信息

################################ 

postfix 收发邮件 

dovecot 投递邮件 

courier-authlib 身份验证  

mysql 存储账号信息 

extmail web支持 

extman web管理 

################################# 

 

主要就是安装几个大块的软件:

一.mysql数据库

二.postfix

三.courier-authlib

四.dovecot

五.extmai+extman

 

 

系统版本:

#cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

#uname -a

Linux VM_12_107_centos3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64GNU/Linux

 

准备工作:

[[email protected]_12_107_centos ~]# getenforce

Disabled

这里如果不是 Disabled 可以用setenfore=0命令把它设置为Disabled


centos 7.2 默认是用firewalld的,我这里开了firewalld服务,所以直接把端口给开了

[[email protected]_12_107_centos~]# firewall-cmd --add-port=110/tcp

[[email protected]_12_107_centos ~]# firewall-cmd--add-port=110/tcp --permanent

[[email protected]_12_107_centos~]# firewall-cmd --add-port=25/tcp

[[email protected]_12_107_centos ~]# firewall-cmd--add-port=25/tcp --permanent

--permanent 参数是为了使firewalld重启之后,这两条规则依然生效,如果不执行带--permanent参数的命令,重启firewalld 之后,这两条命令就无效了

 

 

一.安装数据库:

[[email protected]_12_107_centos ~]#yum -y install mariadb.x86_64 mariadb-server.x86_64mariadb-devel.x86_64

由于CentOS7.2的系统没有mysql数据库了,安装mariadb,不行后面再换(到最后发现mariadb也是可以用的,没什么影响)

 

启动数据库:

[[email protected]_12_107_centos mailbox]# service mariadb start

Redirecting to /bin/systemctl start  mariadb.service

[[email protected]_12_107_centos mailbox]#

检查数据库是否启动成功,发现OK

[[email protected]_12_107_centos mailbox]# ps aux |grep mysql

mysql   22791  0.0  0.0  9512  1500 ?        Ss  14:48   0:00 /bin/sh/usr/bin/mysqld_safe --basedir=/usr

mysql   22947  2.1  1.1 920572 95864 ?        Sl  14:48   0:00 /usr/libexec/mysqld--basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin--log-error=/var/log/mariadb/mariadb.log--pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

root    22984  0.0  0.0 112660  960 pts/0    R+   14:48  0:00 grep --color mysql

 

登录数据库:

[[email protected]_12_107_centos mailbox]# mysql -uroot

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.52-MariaDB MariaDBServer

 

MariaDB [mysql]> delete from user where host like ‘vm%‘;

Query OK, 2 rows affected (0.00 sec)

 

MariaDB [mysql]> delete from user where host=‘localhost‘ and user=‘root‘;

Query OK, 1 row affected (0.00 sec)

 

MariaDB [mysql]> delete from user where host=‘::1‘ and user=‘root‘;

Query OK, 1 row affected (0.00 sec)

 

MariaDB [mysql]> delete from user where host=‘localhost‘ and password=‘‘;

Query OK, 1 row affected (0.00 sec)

 

MariaDB [mysql]> update user set  password=password(‘ppppp902‘) whereuser=‘root‘;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1 Warnings: 0

 

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

上面的操作删除了一些无用的账号,给剩下的root账号设置密码,改了之后只能这样# mysql -u root  -p -h127.0.0.1  用密码登录

  

安装一些必须的插件和库:

[[email protected]_12_107_centos ~]# yum install gcc gcc-c++ opensslopenssl-devel db4-devel ntpdate  bzip2php-mysql cyrus-sasl-md5 perl-GD perl-DBD-MySQL perl-GD perl-CPAN perl-CGIperl-CGI-Session cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl cyrus-sasl-devellibtool-ltdl-devel telnet mail libicu-devel  -y

 

卸载系统自带的postfix

[[email protected]_12_107_centos ~]#yum remove postfix

 

添加用户和组:

[[email protected]_12_107_centos ~]groupadd -g 2525 postfix

[[email protected]_12_107_centos ~]useradd -g postfix -u 2525 -s /sbin/nologin-M postfix

[[email protected]_12_107_centos ~]groupadd -g 2526 postdrop

[[email protected]_12_107_centos ~]useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

这里把用户id和组id设置为25252526是因为后面的extman/webman.cf, postfix/main.cf这两个文件默认都用了这两个数字,不用改来改去那么麻烦

 

二.解压安装postfix

[[email protected]_12_107_centos ~]tar xf postfix-3.2-20160327.tar.gz

[[email protected]_12_107_centos ~]cd postfix-3.2-20160327

这里的postfix是3.2版本的,之所以是这个名字,是我自己从别的机器打包过来的,所以有个日期

 

安装之前先看一下目录下面有没有对应的头文件和库文件, makefile的时候要用到,如果没有这些文件,编译安装会出错的:

 

[[email protected]_12_107_centospostfix-3.2-20160327]# ls /usr/include/mysql/

auth_dialog_client.h  ma_dyncol.h     my_config_x86_64.h   my_net.h        mysql_time.h          plugin_auth.h             service_logger.h            sql_common.h

client_plugin.h       m_ctype.h       my_dbug.h            my_pthread.h     mysql_version.h       plugin_ftparser.h         service_my_snprintf.h       sql_state.h

decimal.h             m_string.h      my_decimal_limits.h  mysql_com.h      my_sys.h              plugin.h                 service_progress_report.h  sslopt-case.h

errmsg.h              my_alloc.h      my_dir.h             mysqld_ername.h  my_valgrind.h         private                   services.h                  sslopt-longopts.h

handler_ername.h      my_attribute.h  my_getopt.h          mysqld_error.h   my_xml.h              psi                       service_thd_alloc.h         sslopt-vars.h

handler_state.h       my_compiler.h   my_global.h          mysql_embed.h    plugin_audit.h        service_debug_sync.h      service_thd_wait.h          typelib.h

keycache.h            my_config.h     my_list.h            mysql.h          plugin_auth_common.h  service_kill_statement.h  service_thread_scheduler.h

[[email protected]_12_107_centospostfix-3.2-20160327]#

[[email protected]_12_107_centospostfix-3.2-20160327]# ls /usr/include/sasl/

hmac-md5.h md5global.h  md5.h  prop.h sasl.h  saslplug.h  saslutil.h

[[email protected]_12_107_centospostfix-3.2-20160327]#

[[email protected]_12_107_centospostfix-3.2-20160327]# ls /usr/lib64/mysql/

INFO_BIN INFO_SRC  libmysqlclient_r.so  libmysqlclient.so  libmysqlclient.so.18  libmysqlclient.so.18.0.0  mysqlbug mysql_config  plugin

[[email protected]_12_107_centos postfix-3.2-20160327]#

[[email protected]_12_107_centospostfix-3.2-20160327]# ls /usr/lib64/sasl2/

libanonymous.so    libanonymous.so.3.0.0  libcrammd5.so.3      libdigestmd5.so    libdigestmd5.so.3.0.0  liblogin.so.3      libplain.so    libplain.so.3.0.0  libsasldb.so.3

libanonymous.so.3  libcrammd5.so          libcrammd5.so.3.0.0  libdigestmd5.so.3  liblogin.so            liblogin.so.3.0.0  libplain.so.3 libsasldb.so      libsasldb.so.3.0.0

[[email protected]_12_107_centospostfix-3.2-20160327]#

 

postfix编译和安装(这里-I指定的头文件和库,就是上面ls查看的那些,像mysql这些如果手动安装指定了不同的目录,这里要用-I指定对应的目录才行)

[[email protected]_12_107_centospostfix-3.2-20160327]#make makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/include/mysql-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ‘‘AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lrt -lm -L/usr/lib64/sasl2-lsasl2 -lssl –lcrypto’

[[email protected]_12_107_centospostfix-3.2-20160327]#make –j4

[[email protected]_12_107_centospostfix-3.2-20160327]#make install

-j4 是指定编译的时候用4个核,多核的系统可以指定多个核,编译会快一点

 

 

安装过程要设置一些目录:安装的时候,就修改postfix的临时目录,别的全部回车用默认设置

 

Please specifythe prefix for installed file names. Specify this ONLY

if you are building ready-to-installpackages for distribution to OTHER

machines. See PACKAGE_README forinstructions.

install_root: [/]

 

Please specifya directory for scratch files while installing Postfix. You

must have write permission in thisdirectory.

tempdir:[/data/mailbox/software/postfix-3.2-20160327] /tmp/mailbox

 

Please specifythe final destination directory for installed Postfix

configuration files.

config_directory: [/etc/postfix]

 

Please specifythe final destination directory for installed Postfix

pppppistrative commands. This directoryshould be in the command search

path of pppppstrative users.

command_directory: [/usr/sbin]

 

Please specifythe final destination directory for installed Postfix

daemon programs. This directory should notbe in the command search path

of any users.

daemon_directory: [/usr/libexec/postfix]

 

Please specifythe final destination directory for Postfix-writable

data files such as caches or randomnumbers. This directory should not

be shared with non-Postfix software.

data_directory: [/var/lib/postfix]

 

Please specifythe final destination directory for the Postfix html

files. Specify "no" if you do notwant to install these files.

html_directory: [no]

 

Please specifythe owner of the Postfix queue. Specify an account with

numerical user ID and group ID values thatare not used by any other

accounts on the system.

mail_owner: [postfix]

 

Please specifythe final destination pathname for the installed Postfix

mailq command. This is theSendmail-compatible mail queue listing command.

mailq_path: [/usr/bin/mailq]

 

Please specifythe final destination directory for the Postfix on-line

manual pages. You can no longer specify"no" here.

manpage_directory: [/usr/local/man]

 

Please specifythe final destination pathname for the installed Postfix

newaliases command. This is theSendmail-compatible command to build

alias databases for the Postfix localdelivery agent.

newaliases_path: [/usr/bin/newaliases]

 

Please specify the final destinationdirectory for Postfix queues.

queue_directory: [/var/spool/postfix]

 

Please specifythe final destination directory for the Postfix README

files. Specify "no" if you do notwant to install these files.

readme_directory: [no]

 

Please specifythe final destination pathname for the installed Postfix

sendmail command. This is theSendmail-compatible mail posting interface.

sendmail_path: [/usr/sbin/sendmail]

 

Please specifythe group for mail submission and for queue management

commands. Specify a group name with anumerical group ID that is

not shared with other accounts, not evenwith the Postfix mail_owner

account. You can no longer specify"no" here.

setgid_group: [postdrop]

 

Please specifythe final destination directory for Postfix shared-library

files.

shlib_directory: [no]

 

Please specifythe final destination directory for non-executable files

that are shared among multiple Postfixinstances, such as postfix-files,

dynamicmaps.cf, as well as the multi-instancetemplate files main.cf.proto

and master.cf.proto.

meta_directory: [/etc/postfix]

 

 

修改postfix相关的目录的属性:

[[email protected]_12_107_centos mailbox]# chown postfix.postdrop /tmp/mailbox

[[email protected]_12_107_centos mailbox]# chownpostfix.postdrop /tmp/mailbox -R

[[email protected]_12_107_centos mailbox]# chown postfix.postfix /var/lib/postfix/

[[email protected]_12_107_centos mailbox]# chownpostfix.postfix /var/lib/postfix/  -R

[[email protected]_12_107_centos mailbox]#

[[email protected]_12_107_centos mailbox]# chownpostfix.postfix /var/spool/postfix/private/

[[email protected]_12_107_centos mailbox]# chownpostfix.postfix /var/spool/postfix/private/ -R

[[email protected]_12_107_centosmailbox]#

[[email protected]_12_107_centos mailbox]# chownpostfix.postdrop /var/spool/postfix/public/

[[email protected]_12_107_centos mailbox]# chownpostfix.postdrop /var/spool/postfix/public/ -R

[[email protected]_12_107_centosmailbox]#

注意public目录的postdrop的,如果搞错了,启动postfix的时候会有报警


生成二进制的库:(干嘛用的???我也不知道)

[[email protected]_12_107_centos mailbox]# newaliases

 

修改postfix配置文件/etc/postfix/main.cf

前面我们设置的一些目录,有些就在这里,如mailq_path = /usr/bin/mailq

完整的main.cf的文件如下:

compatibility_level = 2

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/libexec/postfix

data_directory = /var/lib/postfix

mail_owner = postfix

#这里是域名

myhostname = mail.pxxxd.cn

mydomain = pxxxd.cn

myorigin = pxxxd.cn

inet_interfaces = all

mydestination = $myhostname,localhost.$mydomain, localhost

#网络用内网这个段和本机,本机的段注意是127.0.0.0,不是127.0.0.1

mynetworks = 127.0.0.0/8,172.28.12.0/24

alias_maps = hash:/etc/aliases,nis:mail.aliases

alias_database = hash:/etc/aliases

home_mailbox = Maildir/

mail_spool_directory = /var/spool/mail

debug_peer_level = 2

debugger_command =

        PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

        ddd $daemon_directory/$process_name$process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /var/www/postfix_html

manpage_directory = /usr/local/man

sample_directory = /etc/postfix

readme_directory = no

inet_protocols = ipv4

meta_directory = /etc/postfix

shlib_directory = no

smtputf8_enable = no

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions =permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,reject_rbl_clientmulti.uribl.com,reject_rbl_client dsn.rfc-ignorant.org,reject_rbl_clientdul.dnsbl.sorbs.net,reject_rbl_client list.dsbl.org,reject_rbl_clientsbl-xbl.spamhaus.org,reject_rbl_client bl.spamcop.net,reject_rbl_clientdnsbl.sorbs.net,reject_rbl_client cbl.abuseat.org,reject_rbl_clientix.dnsbl.manitu.net,reject_rbl_client combined.rbl.msrbl.net,reject_rbl_clientrabl.nuclearelephant.com,reject_rbl_client cblless.anti-spam.org.cn

###################smtp认证#####################

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $mydomain

smtpd_sasl_security_options = noanonymous

smtpd_banner = Welcome to our $myhostname SMTP

###################虚拟认证相关###################

virtual_mailbox_base = /var/mailbox

virtual_mailbox_maps =mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

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

virtual_uid_maps = static:2525

virtual_gid_maps = static:2525

virtual_transport = virtual

smtpd_helo_required = yes

disable_vrfy_command = yes

strict_rfc821_envelopes = yes

invalid_hostname_reject_code = 554

multi_recipient_bounce_reject_code = 554

non_fqdn_reject_code = 554

relay_domains_reject_code = 554

unknown_address_reject_code = 554

unknown_client_reject_code = 554

unknown_hostname_reject_code = 554

unknown_local_recipient_reject_code = 554

unknown_relay_recipient_reject_code = 554

unknown_virtual_alias_reject_code = 554

unknown_virtual_mailbox_reject_code = 554

unverified_recipient_reject_code = 554

unverified_sender_reject_code = 554

 

启动postfix

[[email protected]_12_107_centos mailbox]# postfix start

postfix/postfix-script: starting thePostfix mail system

 

启用sasl认证:

[[email protected]_12_107_centossoftware]# service saslauthd start

Redirecting to /bin/systemctl start  saslauthd.service

 

添加DNS解析:

这里用的是阿里云的DNS,到对应的域名下去添加解析

A mail 12x.13x.14x.63

A pop 12x.13x.14x.63

A pop3 12x.13x.14x.63

A smtp 12x.13x.14x.63

MX @ mail.pxxxd.cn

 

postfix测试:

sh-3.2# telnet mail.pxxxd.cn 25

Trying 12x.13x.14x.63...

Connected to mail.pxxxd.cn.

Escape character is ‘^]‘.

220 mail.pxxxd.cn ESMTP Postfix

ehlo localhost

250-mail.pxxxd.cn

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250-DSN

250 SMTPUTF8

测试失败,可以tail –f /var/log/maillog 去调试,这里先不管

 

查看postfix是否则支持支持cyrus风格的sasl认

[[email protected]_12_107_centos ~]# postconf -a

cyrus

dovecot

这里显示支持

 

添加sasl的认证方式:

一般情况下这个文件是没有的,创建文件vim /usr/lib64/sasl2/smtpd.conf,并添加两行:

pwcheck_method:saslauthd

mech_list:PLAIN LOGIN

 

保存之后,重新加载postfix的配置:

[[email protected]_12_107_centos ~]# postfix reload

postfix/postfix-script: refreshing thePostfix mail system

再次telnet,发现比刚才多了两行(红色字体),说明配置成功:

sh-3.2# telnet mail.pxxxd.cn 25

Trying 12x.13x.14x.63...

Connected to mail.pxxxd.cn.

Escape character is ‘^]‘.

220 mail.pxxxd.cn ESMTP Postfix

ehlo localhost

250-mail.pxxxd.cn

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250-DSN

250 SMTPUTF8

 

安装courier-unicode

tar xf courier-unicode-1.2.tar.bz2

cd courier-unicode-1.2

./configure

make –j4 && make install

 

安装courier-authlib

[[email protected]_12_107_centos software]tar xf courier-authlib-0.66.4.tar.bz2

[[email protected]_12_107_centos software]cd courier-authlib-0.66.4/

[[email protected]_12_107_centos courier-authlib-0.66.4]#mkdir /usr/local/courier-authlib/

 

[[email protected]_12_107_centoscourier-authlib-0.66.4]#./configure --prefix=/usr/local/courier-authlib--sysconfdir=/etc --without-authpam --without-authshadow --without-authvchkpw--without-authpgsql --with-authmysql --with-mysql-libs=/usr/lib64/mysql--with-mysql-includes=/usr/include/mysql --with-redhat--with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc--with-mailuser=postfix --with-mailgroup=postfix

[[email protected]_12_107_centos courier-authlib-0.66.4]make–j4 && make install


添加courier启动脚本,并设置开机启动

[[email protected]_12_107_centos courier-authlib-0.66.4]cp courier-authlib.sysvinit /etc/init.d/courier-authlib

[[email protected]_12_107_centoscourier-authlib-0.66.4] chmod +x /etc/init.d/courier-authlib

[[email protected]_12_107_centoscourier-authlib-0.66.4] chkconfig --add courier-authlib

[[email protected]_12_107_centoscourier-authlib-0.66.4] chkconfig courier-authlib on

[[email protected]_12_107_centoscourier-authlib-0.66.4] echo"/usr/local/courier-authlib/lib/courier-authlib" >>/etc/ld.so.conf.d/courier-authlib.conf

[[email protected]_12_107_centoscourier-authlib-0.66.4] ldconfig

[[email protected]_12_107_centoscourier-authlib-0.66.4] service courier-authlib start

 

[[email protected]_12_107_centos ~]cp/etc/authdaemonrc.dist  /etc/authdaemonrc

[[email protected]_12_107_centos~]cp /etc/authmysqlrc.dist /etc/authmysqlrc

修改过程忽略,这里直接把完整的配置文件贴出来,后面用cat命令贴出来的,都是该文件的完整配置信息:

[[email protected]_12_107_centos conf.d]# cat/etc/authmysqlrc | grep -v ^#

MYSQL_SERVER        localhost

MYSQL_USERNAME         extmail

MYSQL_PASSWORD         extmail

MYSQL_SOCKET         /var/lib/mysql/mysql.sock

MYSQL_PORT            3306

MYSQL_OPT        0

MYSQL_DATABASE           extmail

MYSQL_USER_TABLE       mailbox

MYSQL_CRYPT_PWFIELD crypt

MYSQL_CLEAR_PWFIELD password

MYSQL_UID_FIELD           2525

MYSQL_GID_FIELD           2526

MYSQL_LOGIN_FIELD       username

MYSQL_HOME_FIELD       concat(‘/var/mailbox‘,homedir)

MYSQL_NAME_FIELD       name

MYSQL_MAILDIR_FIELD   concat(‘/var/mailbox‘,homedir)

 

认证用mysql的:

[[email protected]_12_107_centos conf.d]# cat/etc/authdaemonrc | grep -v ^#

authmodulelist="authmysql"

authmodulelistorig="authmysql"

daemons=10

authdaemonvar=/usr/local/courier-authlib/var/spool/authdaemon

DEBUG_LOGIN=0

DEFAULTOPTIONS=""

LOGGEROPTS=""

 

 

安装dovecot:

[[email protected]_12_107_centos~]#yum install -y  dovecot dovecot-mysql

[[email protected]_12_107_centos ~]#cd/etc/dovecot

[[email protected]_12_107_centosdovecot]#cat dovecot.conf | grep -v ^#

protocols = imap pop3 lmtp

disable_plaintext_auth = no

ssl_disable = no

listen = *

!include conf.d/*.conf

 

[[email protected]_12_107_centos dovecot]# cd conf.d/

[[email protected]_12_107_centosconf.d]# cat 10-auth.conf | grep -v ^#

auth_mechanisms = plain

!include auth-system.conf.ext

 

[[email protected]_12_107_centos conf.d]# cat10-mail.conf | grep -v ^#

mail_location =maildir:/var/mailbox/%d/%n/Maildir

mbox_write_locks = fcntl

 

[[email protected]_12_107_centos conf.d]# cat 10-logging.conf  | grep -v ^#

debug_log_path = /var/log/dovecot.log

auth_debug = yes

auth_debug_passwords = yes

mail_debug = yes

 

[email protected]_12_107_centos conf.d]# cp auth-sql.conf.ext auth-sql.conf

[[email protected]_12_107_centosconf.d]# cat auth-sql.conf | grep -v ^#

passdb {

 driver = sql

 args = /etc/dovecot/dovecot-mysql.conf

}

userdb {

 driver = sql

 args = /etc/dovecot/dovecot-mysql.conf

}

 

[email protected]_12_107_centos conf.d]# cat/etc/dovecot/dovecot-mysql.conf | grep -v ^#

driver = mysql

connect = host=localhost dbname=extmailuser=root [email protected]

default_pass_scheme = CRYPT

password_query = SELECT username ASuser,password AS password FROM mailbox WHERE username = ‘%u‘

user_query = SELECT maildir, uidnumber ASuid, gidnumber AS gid FROM mailbox WHERE username = ‘%u‘

 

extmail and extman 安装:

[email protected]_12_107_centos software]# tar -xf extmail-1.2.tar.gz

[email protected]_12_107_centos software]# tar xf extman-1.1.tar.gz

 

[email protected]_12_107_centos software]# mkdir/var/www/extsuite/extmail/ -p

[email protected]_12_107_centos software]# mkdir/var/www/extsuite/extman/ -p

 

[email protected]_12_107_centos software]# rsync -al extmail-1.2/* /var/www/extsuite/extmail/

[email protected]_12_107_centos software]# rsync -al extman-1.1/* /var/www/extsuite/extman/

 

[[email protected]_12_107_centos software]# cd /var/www/extsuite/extmail/

[email protected]_12_107_centos extmail]# cp webmail.cf.default webmail.cf

[[email protected]_12_107_centosextmail]# cat webmail.cf | grep -v ^#

SYS_CONFIG = /var/www/extsuite/extmail/

SYS_LANGDIR =/var/www/extsuite/extmail/lang

SYS_TEMPLDIR =/var/www/extsuite/extmail/html

SYS_HTTP_CACHE= 0

SYS_SMTP_HOST =127.0.0.1

SYS_SMTP_PORT =25

SYS_SMTP_TIMEOUT= 5

SYS_SPAM_REPORT_ON= 0

SYS_SPAM_REPORT_TYPE= dspam

SYS_SHOW_WARN =0

SYS_IP_SECURITY_ON= 1

SYS_PERMIT_NOQUOTA= 1

SYS_SESS_DIR =/tmp

SYS_UPLOAD_TMPDIR= /tmp

SYS_LOG_ON = 1

SYS_LOG_TYPE =syslog

SYS_LOG_FILE =/var/log/extmail.log

SYS_SESS_TIMEOUT= 0

SYS_SESS_COOKIE_ONLY= 1

SYS_USER_PSIZE= 10

SYS_USER_SCREEN= auto

SYS_USER_LANG =zh_CN

SYS_APP_TYPE =WebMail

SYS_USER_TEMPLATE= default

SYS_USER_CHARSET= utf-8

SYS_USER_TRYLOCAL= 1

SYS_USER_TIMEZONE= +0800

SYS_USER_CCSENT= 1

SYS_USER_SHOW_HTML= 1

SYS_USER_COMPOSE_HTML = 1

SYS_USER_CONV_LINK =1

SYS_USER_ADDR2ABOOK = 1

SYS_MESSAGE_SIZE_LIMIT= 5242880

SYS_MIN_PASS_LEN= 2

SYS_MFILTER_ON= 1

SYS_NETDISK_ON= 1

SYS_SHOW_SIGNUP= 1

SYS_DEBUG_ON =1

SYS_AUTH_TYPE =mysql

SYS_MAILDIR_BASE= /var/mailbox

SYS_AUTH_SCHEMA= virtual

SYS_CRYPT_TYPE= md5crypt

SYS_MYSQL_USER= root

SYS_MYSQL_PASS = [email protected]

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

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

SYS_MYSQL_TABLE = mailbox

SYS_MYSQL_ATTR_USERNAME = username

SYS_MYSQL_ATTR_DOMAIN = domain

SYS_MYSQL_ATTR_PASSWD = password

SYS_MYSQL_ATTR_CLEARPW = clearpwd

SYS_MYSQL_ATTR_QUOTA = quota

SYS_MYSQL_ATTR_NDQUOTA = netdiskquota

SYS_MYSQL_ATTR_HOME = homedir

SYS_MYSQL_ATTR_MAILDIR = maildir

SYS_MYSQL_ATTR_DISABLEWEBMAIL =disablewebmail

SYS_MYSQL_ATTR_DISABLENETDISK =disablenetdisk

SYS_MYSQL_ATTR_DISABLEPWDCHANGE =disablepwdchange

SYS_MYSQL_ATTR_ACTIVE = active

SYS_MYSQL_ATTR_PWD_QUESTION = question

SYS_MYSQL_ATTR_PWD_ANSWER = answer

SYS_LDAP_BASE =o=extmailAccount,dc=example.com

SYS_LDAP_RDN = cn=Manager,dc=example.com

SYS_LDAP_PASS = secret

SYS_LDAP_HOST = localhost

SYS_LDAP_ATTR_USERNAME = mail

SYS_LDAP_ATTR_DOMAIN = virtualDomain

SYS_LDAP_ATTR_PASSWD = userPassword

SYS_LDAP_ATTR_CLEARPW = clearPassword

SYS_LDAP_ATTR_QUOTA = mailQuota

SYS_LDAP_ATTR_NDQUOTA = netdiskQuota

SYS_LDAP_ATTR_HOME = homeDirectory

SYS_LDAP_ATTR_MAILDIR = mailMessageStore

SYS_LDAP_ATTR_DISABLEWEBMAIL =disablewebmail

SYS_LDAP_ATTR_DISABLENETDISK =disablenetdisk

SYS_LDAP_ATTR_DISABLEPWDCHANGE =disablePasswdChange

SYS_LDAP_ATTR_ACTIVE = active

SYS_LDAP_ATTR_PWD_QUESTION = question

SYS_LDAP_ATTR_PWD_ANSWER = answer

SYS_AUTHLIB_SOCKET= /usr/local/courier-authlib/var/spool/authdaemon/socket

SYS_G_ABOOK_TYPE= file

SYS_G_ABOOK_LDAP_HOST= localhost

SYS_G_ABOOK_LDAP_BASE= ou=AddressBook,dc=example.com

SYS_G_ABOOK_LDAP_ROOTDN =cn=Manager,dc=example.com

SYS_G_ABOOK_LDAP_ROOTPW = secret

SYS_G_ABOOK_LDAP_FILTER =objectClass=OfficePerson

SYS_G_ABOOK_FILE_PATH= /var/www/extsuite/extmail/globabook.cf

SYS_G_ABOOK_FILE_LOCK = 1

SYS_G_ABOOK_FILE_CONVERT = 0

SYS_G_ABOOK_FILE_CHARSET = utf-8

 

[[email protected]_12_107_centos extmail]# cd../extman/

[[email protected]_12_107_centos extman]#

[[email protected]_12_107_centos extman]#

[[email protected]_12_107_centos extman]# cp webman.cf.default webman.cf

[[email protected]_12_107_centos extman]# cat webman.cf | grep -v ^#

SYS_CONFIG = /var/www/extsuite/extman/

SYS_LANGDIR =/var/www/extsuite/extman/lang

SYS_TEMPLDIR =/var/www/extsuite/extman/html

SYS_MAILDIR_BASE= /var/mailbox

SYS_SHOW_WARN =0

SYS_SESS_DIR =/tmp/

SYS_CAPTCHA_ON= 0

SYS_CAPTCHA_KEY= r3s9b6a7

SYS_CAPTCHA_LEN= 8

SYS_PURGE_DATA= 0

SYS_PSIZE = 20

SYS_APP_TYPE =ExtMan

SYS_TEMPLATE_NAME= default

SYS_DEFAULT_EXPIRE= 1y

SYS_GROUPMAIL_SENDER= [email protected]

SYS_DEFAULT_SERVICES= webmail,smtpd,smtp,pop3,netdisk

SYS_ISP_MODE =no

SYS_DOMAIN_HASHDIR= yes

SYS_DOMAIN_HASHDIR_DEPTH= 2x2

SYS_USER_HASHDIR= yes

SYS_USER_HASHDIR_DEPTH= 2x2

SYS_MIN_UID =500

SYS_MIN_GID =100

SYS_DEFAULT_UID= 2525

SYS_DEFAULT_GID= 2525

SYS_QUOTA_MULTIPLIER= 1048576

SYS_QUOTA_TYPE= courier

SYS_DEFAULT_MAXQUOTA= 500

SYS_DEFAULT_MAXALIAS= 100

SYS_DEFAULT_MAXUSERS = 100

SYS_DEFAULT_MAXNDQUOTA = 500

SYS_USER_DEFAULT_QUOTA= 5

SYS_USER_DEFAULT_NDQUOTA= 5

SYS_USER_DEFAULT_EXPIRE = 1y

SYS_BACKEND_TYPE= mysql

SYS_CRYPT_TYPE= md5crypt

SYS_MYSQL_USER= webman

SYS_MYSQL_PASS = webman

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

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

SYS_MYSQL_TABLE = manager

SYS_MYSQL_ATTR_USERNAME = username

SYS_MYSQL_ATTR_PASSWD = password

SYS_LDAP_BASE =dc=extmail.org

SYS_LDAP_RDN = cn=Manager,dc=extmail.org

SYS_LDAP_PASS = secret

SYS_LDAP_HOST = localhost

SYS_LDAP_ATTR_USERNAME = mail

SYS_LDAP_ATTR_PASSWD = userPassword

SYS_RRD_DATADIR= /var/lib

SYS_RRD_TMPDIR= /tmp/viewlog

SYS_RRD_QUEUE_ON= yes

SYS_CMDSERVER_SOCK= /tmp/cmdserver.sock

SYS_CMDSERVER_MAXCONN= 5

SYS_CMDSERVER_PID= /var/run/cmdserver.pid

SYS_CMDSERVER_LOG= /var/log/cmdserver.log

SYS_CMDSERVER_AUTHCODE= your_auth_code_here

SYS_IGNORE_SERVER_LIST= web

 

[[email protected]_12_107_centos extman]#chown -R postfix.postfix /var/www/extsuite/extman/cgi/

[[email protected]_12_107_centos extman]#chown -R postfix.postfix /var/www/extsuite/extmail/cgi/

 

用vim的命令把里面的TYPE关键字都改成ENGINE,否则导入会报错:

[[email protected] extman]# vim docs/extmail.sql

:% s/TYPE/ENGINE/g

 

[[email protected]_12_107_centos extman]# mysql-uroot -p < docs/extmail.sql

[[email protected]_12_107_centos extman]# mysql-uroot -p < docs/init.sql

这里导入之后,记得登录mysql,给extmail授权:grant all on *.* to [email protected] ;

 

[email protected]_12_107_centos extman]# cp docs/mysql_virtual_* /etc/postfix/

[email protected]_12_107_centos extman]#vim /var/www/extsuite/extmail/dispatch-init

打开这个文件,把里面的SU_UID,SU_GID的值改为postfix,如果cgi端口不想用8888也可以改掉,改掉的话,后面nginx的cgi端口也要改


写个超级简单的脚本启动和关闭mail服务器:

[[email protected]_12_107_centos mailbox]# cat mail.sh

#!/bin/bash

case $1 in

  stop)

      postfix stop

      service saslauthd stop

      /etc/init.d/courier-authlib stop

      service dovecot stop

      #apachectl stop

      /var/www/extsuite/extmail/dispatch-init stop

      ;;

  start)

      postfix start

      service saslauthd start

      /etc/init.d/courier-authlib start

      service dovecot start

      #apachectl start

      /var/www/extsuite/extmail/dispatch-init start

      ;;

esac

     /var/www/extsuite/extman/daemon/cmdserver –daemon

 

 

nginx配置,一定要用include 把这个mail.conf添加进去:

[[email protected]_12_107_centos~]# cat /data/local/nginx-1.8.0/conf/mail.conf

server {

  listen       80;

  server_name  mail.pxxxd.cn;

  index index.html index.htm index.php index.cgi;

  root /var/www/extsuite/extmail/html/;

  location /extmail/cgi/ {

             fastcgi_pass          127.0.0.1:8888;

            fastcgi_index         index.cgi;

            fastcgi_param SCRIPT_FILENAME  /var/www/extsuite/extmail/cgi/$fastcgi_script_name;

            include              fastcgi.conf;

       }

        location /extmail/  {

            alias /var/www/extsuite/extmail/html/;

       }

       location /extman/cgi/ {

            fastcgi_pass         127.0.0.1:8888;

            fastcgi_index         index.cgi;

            fastcgi_param  SCRIPT_FILENAME  /var/www/extsuite/extman/cgi/$fastcgi_script_name;

            include            fastcgi.conf;

       }

       location /extman/ {

            alias /var/www/extsuite/extman/html/;

       }

     access_log /data/local/nginx-1.8.0/logs/mail.log;

}

 

执行上面的脚本mail.sh,启动nginx就可以了

先到extman去添加用户,然后到Extmail登录收发邮件。

 

 

参考链接:

http://www.thinksaas.cn/topics/0/506/506622.html

 

extman 后台登录,图形日志页面报错:

Can‘t locate RRDs.pm in @INC (@INCcontains: /var/www/extsuite/extman/libs /usr/local/lib64/perl5/usr/local/share/perl5 /usr/lib64/perl5/vendor_perl/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at/var/www/extsuite/extman/libs/Ext/GraphLog.pm line 23. BEGINfailed--compilation aborted at /var/www/extsuite/extman/libs/Ext/GraphLog.pmline 23. Compilation failed in require at/var/www/extsuite/extman/libs/Ext/MgrApp/ViewLog.pm line 22. BEGIN failed--compilationaborted at /var/www/extsuite/extman/libs/Ext/MgrApp/ViewLog.pm line 22.Compilation failed in require at /var/www/extsuite/extman/cgi/viewlog.cgi line18.

 

yum provides "*/RRDS.pam"

解决:

yum -y install perl-Time-HiResperl-Time-HiRes-Value perl-File-Tail  rrdtool rrdtool-perl 

还是不行,没了上面的错误提示,但是图形日志的图片不正常

 yum -y install perl-CPAN

重启mail服务,不行

cp /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext 

cd /usr/local/mailgraph_ext 

 ./mailgraph-init start  

Starting mail statistics grapher: mailgraph_ext

Can‘t locate File/Tail.pm in @INC (@INC contains: /root/perl5/lib/perl5/5.16.3/x86_64-linux-thread-multi /root/perl5/lib/perl5/5.16.3 /root/perl5/lib/perl5/x86_64-linux-thread-multi /root/perl5/lib/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) 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-1.3.tar.gz   安装

[[email protected] mailgraph_ext]# ./mailgraph-init start

Starting mail statistics grapher: mailgraph_ext

Starting queue statistics grapher: qmonitor

再次登录,OK !!!!所有图形正常

 

上面用到了ehlo等命令,这里给个说明:

smtp状态码:

1XX

2XX:正确信息

3XX:当前信息没有结束

4XX:暂时性错误

5XX:永久性错误

smtp:协议命令

helo (smtp协议)

ehlo (esmtp协议)

mail from:    邮件发送人

rcpt to: 邮件接收人

date 邮件内容

Subject 邮件标题

. 邮件结束符

alias:邮件别名

[email protected]:[email protected]   法网abc的其实会发到efg

使用newaliases来生成/etc/aliases.db

验证postfix是否安装OK

 

其他常见错误google有,不贴了,第一次自己搭建应该会有不少问题的,重要的是慢慢尝试

不知道什么原因一定要打印日志,查看日志,拿错误日志搜索,是解决问题的最佳方法

 

 有问题欢迎留言


本文出自 “BYWIND” 博客,转载请与作者联系!

以上是关于centos7.2下搭建postfix++dovecot+courier-authlib+extmail邮件收发系统的主要内容,如果未能解决你的问题,请参考以下文章

linux下怎么快速搭建postfix??

Centos 下搭建postfix和Dovecot的邮箱服务系统

Centos 下搭建postfix和Dovecot的邮箱服务系统

Linux系统,Centos7版本下搭建postfix服务器及其相关配置应用

Linux运维高级篇—CentOS 7下Postfix邮件服务器搭建

linux环境下利用postfix和dovecot搭建邮件服务器,快速创建用户脚本