接上一篇内容,postfix及dovecot基本安装成功,但没有管理界面,不方便操作,下面开始集成postadmin及Roundcube。
一、安装LNMP
推荐一种方便快捷安装方式 https://lnmp.org/install.html
二、配置postfixadmin
1、下载postfixadmin,
地址:https://sourceforge.net/projects/postfixadmin/,本例使用的是postfixadmin-3.2.tar.gz。
解压到nginx的网页目录(/chroot/www/postfixadmin/)。
2、创建配置数据库
修改配置文件/chroot/www/postfixadmin/config.inc.php
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = '127.0.0.1';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix';
$CONF['database_name'] = 'postfix';
为postfixadmin创建Mysql数据库与权限记录
启动数据库,进入数据库
创建postfix数据库,并创建postfix用户且授权
mysql> create database postfix;
mysql> grant all on postfix.* to postfix@'localhost' identified by 'postfix';
mysql> flush privileges;
测试postfix能否登录成功。
[root@home html]# mysql -u postfix -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 53806
Server version: 5.6.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| postfix |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> use postfix
Database changed
mysql>
安装配置
打开安装配置界面
http://ip地址/postfixadmin/public/setup.php
接下来就是按界面提示配置相关数据库用户名及密码,生成数据结构,设置超级管理员信息。
进入登录界面
http://ip/postfixadmin/public/login.php
配置我们需要的域名信息,在域名下创建邮箱信息。
配置Postfix
虚拟域名配置
在上一次安装的过程中配置支持虚拟域名。
/etc/postfix/main.cf
#虚拟域名配置
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
# Additional for quota support
#virtual_create_maildirsize = yes
#virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
#virtual_mailbox_limit_override = yes
#virtual_maildir_limit_message = Sorry, this user has exceeded their disk space quota, please try again later.
#virtual_overquota_bounce = yes
#Specify the user/group that owns the mail folders. I'm not sure if this is strictly necessary when using Dovecot's LDA.
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
注意:
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
这里根据实现情况修改默认的用户ID及用户组ID号,当前配置使用的是5000
创建Mysql脚本
创建/etc/postfix/mysql_virtual_domains_maps.cf文件
[root@home ~]# vim /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
创建/etc/postfix/mysql_virtual_alias_maps.cf文件
[root@home ~]# vim /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
创建/etc/postfix/mysql_virtual_mailbox_maps.cf文件
[root@home ~]# vim /etc/postfix/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'
创建/etc/postfix/mysql_virtual_mailbox_limit_maps.cf文件
[root@home ~]# vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
SMTP 认证设定
SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式
查看postfix支持的认证,默认支持dovecot
[root@home ~]# postconf -a
cyrus
dovecot
修改/etc/postfix/main.cf配置文件
用系统用户SMTP认证配置如下(修改前)
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
修改为以下配置内容(修改后)
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/run/dovecot/auth-client
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
使用Dovecot做为投递
[root@home ~]# vim /etc/postfix/main.cf
# TRANSPORT MAP
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
#修改master.cf文件
[root@home ~]# vim /etc/postfix/master.cf
#在最后增加这两行,注意flags前面有两个空格,不然会报错
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
二、配置dovecot
前面已经安装了dovecot,现在配置dovecot的配置文件,主要是集成数据库相关配置。
修改配置
修改/etc/dovecot/dovecot.conf
[root@home ~]# vim /etc/dovecot/dovecot.conf
protocols = imap pop3
listen = *
dict {
quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf
修改/etc/dovecot/conf.d/10-auth.conf
[root@home ~]# vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login cram-md5
!include auth-sql.conf.ext
修改/etc/dovecot/conf.d/10-mail.conf
[root@home ~]# vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:%hMaildir
mbox_write_locks = fcntl
修改/etc/dovecot/conf.d/10-master.conf
[root@home ~]# vim /etc/dovecot/conf.d/10-master.conf
service imap-login {
inet_listener imap {
}
inet_listener imaps {
}
}
service pop3-login {
inet_listener pop3 {
}
inet_listener pop3s {
}
}
service lmtp {
unix_listener lmtp {
}
}
service imap {
}
service pop3 {
}
service auth {
unix_listener auth-userdb {
mode = 0600
user = vmail
group = vmail
}
#新加下面一段,为smtp做认证
unix_listener auth-client {
mode = 0600
user = postfix
group = postfix
}
}
service auth-worker {
}
service dict {
unix_listener dict {
mode = 0600
user = vmail
group = vmail
}
}
修改/etc/dovecot/conf.d/15-lda.conf
[root@home ~]# vim /etc/dovecot/conf.d/15-lda.conf
protocol lda {
mail_plugins = quota
postmaster_address = [email protected] #管理员邮箱
}
修改/etc/dovecot/conf.d/20-imap.conf
[root@home ~]# vim /etc/dovecot/conf.d/20-imap.conf
protocol imap {
mail_plugins = quota imap_quota
}
修改/etc/dovecot/conf.d/20-pop3.conf
[root@home ~]# vim /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv
protocol pop3 {
mail_plugins = quota
}
修改/etc/dovecot/conf.d/90-quota.conf
[root@home ~]# vim /etc/dovecot/conf.d/90-quota.conf
plugin {
quota_rule = *:storage=1G
}
plugin {
}
plugin {
quota = dict:User quota::proxy::quota
}
plugin {
}
添加配置
增加新文件/etc/dovecot/dovecot-sql.conf.ext
[root@home ~]# vim /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix
default_pass_scheme = CRAM-MD5
user_query = SELECT CONCAT('/var/vmail/', maildir) AS home, 5000 AS uid, 5000 AS gid, CONCAT('*:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u' AND active='1'
password_query = SELECT username AS user, password, CONCAT('/var/vmail/', maildir) AS userdb_home, 2000 AS userdb_uid, 2000 AS userdb_gid, CONCAT('*:bytes=', quota) as userdb_quota_rule FROM mailbox WHERE username = '%u' AND active='1'
注意: 这里的uid及gid也是使用当前系统vmail用户的信息。
增加新文件/etc/dovecot/dovecot-dict-sql.conf.ext
[root@home ~]# vim /etc/dovecot/dovecot-dict-sql.conf.ext
connect = host=localhost dbname=postfix user=postfix password=postfix
map {
pattern = priv/quota/storage
table = quota2
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = quota2
username_field = username
value_field = messages
}
三、配置Roundcubemail
下载Roundcubemail
下载Roundcubemail(注意下载roundcubmail版本与php版本的兼容问题,本例使用的是roundcubemail-1.2.9.tar.gz),地址:https://roundcube.net,并且解压到nginx目录中(chroot/www/webmail)
创建数据库
mysql> CREATE DATABASE roundcubemail;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcubemail@localhost IDENTIFIED BY 'roundcubemail';
FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
安装配置
在浏览器中访问roundcubemail的安装界面,
地址:http://ip地址/webmail/installer/index.php?_step=1
根据界面提示配置相关信息…
根据界面提示需要打开php相关配置、添加相关扩展,生成相关数据配置信息即可。
如果在第三步中验证没有问题,那说明基本通信是正常了。
进入管理界面
根据在postfixadmin中创建的邮箱及密码,在以下地址登录。
地址: http://ip地址/webmail/?_task=mail&_err=session
四、测试验证
内部邮件
向外邮件
接收邮件
总结
前前后后也花费了不少时间,心疼的两个周末,不过总算结果是好的。主要问题出现在对email发送的流程不够理解,修改配置文件不够小心。当前只是demo走通,距离正式投入使用还有一些距离,例如SSL加密协议证书配置、数据备份机制、安全问题等有待解决。
Postfix+Dovecot+PostfixAdmin+Roundcube配置调试源码可在以下地址下载:
https://download.csdn.net/download/xianglingchuan/10993649