标签:
本文介绍Centos6 Postfix+Dovecot+Postfixadmin+Roundcube 搭建过程,使用的是阿里云ESC CentOS 6.5 64位,
配置hostname
[code]#修改network文件
vim /etc/sysconfig/network
HOSTNAME=mail.ali.com
#添加本地hosts
vim /etc/hosts
112.74.28.201 mail.ali.com[/code]
[code]yum update[/code]
创建一个vmail用户,用作管理虚拟邮箱的文件夹
[code]useradd -u 2000 -d /var/vmail -m -s /sbin/nologin vmail[/code]
安装LAMP环境
[code]yum -y install httpd mysql mysql-devel mysql-server php php-pecl-Fileinfo php-mcrypt php-devel php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc pcre pcre-devel[/code]
整合Apache和PHP
[code]#vim /etc/httpd/conf/httpd.conf[/code]
[code]#增加以下参数
AddType application/x-httpd-php .php
PHPIniDir "/etc/php.ini"
#修改以下参数
DirectoryIndex index.php index.html index.html.var
User vmail
Group vmail[/code]
测试
[code]vim /var/www/html/index.php[/code]
[code]<?php
phpinfo();
?>
[/code]
[code]#重启Apache
/etc/init.d/httpd restart[/code]
[code]chkconfig httpd on #加入开机自启动[/code]
配置postfixadmin
[code]cd /var/www/html && wget http://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.93/postfixadmin-2.93.tar.gz && tar xvf postfixadmin-2.93.tar.gz && mv postfixadmin-2.93 postfixadmin[/code]
[code]配置postfixadmin需要用到
yum install -y dovecot dovecot-devel dovecot-mysql[/code]
#修改配置文件中以下参数
[code]vim config.inc.php[/code]
[code]$CONF[‘configured‘] = true;
$CONF[‘database_type‘] = ‘mysql‘;
$CONF[‘database_host‘] = ‘localhost‘;
$CONF[‘database_user‘] = ‘postfix‘;
$CONF[‘database_password‘] = ‘postfix‘;
$CONF[‘database_name‘] = ‘postfix‘;
$CONF[‘admin_email‘] = ‘postmaster@sst888.com‘;
$CONF[‘encrypt‘] = ‘dovecot:CRAM-MD5‘;
$CONF[‘dovecotpw‘] = "/usr/bin/doveadm pw";
$CONF[‘domain_path‘] = ‘YES‘;
$CONF[‘domain_in_mailbox‘] = ‘NO‘;
$CONF[‘aliases‘] = ‘1000‘;
$CONF[‘mailboxes‘] = ‘1000‘;
$CONF[‘maxquota‘] = ‘1000‘;
$CONF[‘fetchmail‘] = ‘NO‘;
$CONF[‘quota‘] = ‘YES‘;
$CONF[‘used_quotas‘] = ‘YES‘;
$CONF[‘new_quota_table‘] = ‘YES‘;[/code]
为postfixadmin创建Mysql数据库与权限
[code]service mysqld start[/code]
[code]chkconfig mysqld on[/code]
[code]mysql
mysql> create database postfix;
mysql> grant all on postfix.* to postfix@‘localhost‘ identified by ‘postfix‘;
mysql> flush privileges;[/code]
#修改所有者和所有组
[code]chown -R vmail.vmail /var/www/html/postfixadmin/
chown -R vmail.vmail /var/lib/php/session/[/code]
配置Postfix
[code]#yum安装postfix
yum remove -y sendmail && yum install postfix
更新MTA为Postfix
/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix[/code]
修改postfix配置文件
[code]vim /etc/postfix/main.cf[/code]
修改参数
[code]myhostname = mail.free.com
mydomain = free.com
myorigin = $mydomain
inet_interfaces = all
mynetworks_style = host
mynetworks = 192.168.18/24, 127.0.0.0/8
#添加以下参数
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:2000
virtual_gid_maps = static:2000
#Specifies which tables proxymap can read: http://www.postfix.org/postconf.5.html#proxy_read_maps
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
#SASL SUPPORT FOR CLIENTS
# Turns on sasl authorization
smtpd_sasl_auth_enable = yes
#Use dovecot for authentication
smtpd_sasl_type = dovecot
# Path to UNIX socket for SASL
smtpd_sasl_path = /var/run/dovecot/auth-client
#Disable anonymous login. We don‘t want to run an open relay for spammers.
smtpd_sasl_security_options = noanonymous
#Adds support for email software that doesn‘t follow RFC 4954.
#This includes most versions of Microsoft Outlook before 2007.
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
# TRANSPORT MAP
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1[/code]
使用Dovecot做为投递
[code]vim /etc/postfix/master.cf
#在最后增加这两行,注意flags前面有两个空格,不然会报错[/code]
[code]dovecot unix - n n - - pipe,
flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}[/code]
创建MySQL脚本
请注意user password dbname 要和上面配置postfixadmin中授权的一致。
创建/etc/postfix/mysql_virtual_domains_maps.cf文件
[code]vim /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain=‘%s‘ AND active = ‘1‘
#optional query to use when relaying for backup MX
#query = SELECT domain FROM domain WHERE domain=‘%s‘ AND backupmx = ‘0‘ AND active = ‘1‘[/code]
创建/etc/postfix/mysql_virtual_alias_maps.cf文件
[code]vim /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address=‘%s‘ AND active = ‘1‘[/code]
创建/etc/postfix/mysql_virtual_mailbox_maps.cf文件
[code]vim /etc/postfix/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT CONCAT(domain,‘/‘,maildir) FROM mailbox WHERE username=‘%s‘ AND active = ‘1‘[/code]
创建/etc/postfix/mysql_virtual_mailbox_limit_maps.cf文件
[code]vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username=‘%s‘ AND active = ‘1‘[/code]
配置Dovecot
修改dovecot配置文件
以下配置都是在原文件基础上修改
修改/etc/dovecot/dovecot.conf #主配置文件
[code]vim /etc/dovecot/dovecot.conf[/code]
[code]protocols = imap pop3
listen = *
dict {
quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf[/code]
修改/etc/dovecot/conf.d/10-auth.conf
[code]vim /etc/dovecot/conf.d/10-auth.conf[/code]
[code]disable_plaintext_auth = no
auth_mechanisms = plain login cram-md5
!include auth-sql.conf.ext[/code]
修改/etc/dovecot/conf.d/10-mail.conf
[code]vim /etc/dovecot/conf.d/10-mail.conf[/code]
[code]mail_location = maildir:%hMaildir
mbox_write_locks = fcntl[/code]
修改/etc/dovecot/conf.d/10-master.conf
[code]vim /etc/dovecot/conf.d/10-master.conf[/code]
[code]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
}
}[/code]
修改/etc/dovecot/conf.d/15-lda.conf
[code]vim /etc/dovecot/conf.d/15-lda.conf[/code]
[code]protocol lda {
mail_plugins = quota
postmaster_address = postmaster@free.com #管理员邮箱
}[/code]
修改/etc/dovecot/conf.d/20-imap.conf
[code]vim /etc/dovecot/conf.d/20-imap.conf[/code]
[code]protocol imap {
mail_plugins = quota imap_quota
}[/code]
修改/etc/dovecot/conf.d/20-pop3.conf
[code]protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
mail_plugins = quota
}[/code]
修改/etc/dovecot/conf.d/90-quota.conf
[code]vim /etc/dovecot/conf.d/90-quota.conf[/code]
[code]plugin {
quota_rule = *:storage=1G
}
plugin {
}
plugin {
quota = dict:User quota::proxy::quota
}
plugin {
}[/code]
以下配置文件为新添加文件
增加/etc/dovecot/dovecot-sql.conf.ext
[code]vim /etc/dovecot/dovecot-sql.conf.ext[/code]
[code]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, 2000 AS uid, 2000 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‘[/code]
增加/etc/dovecot/dovecot-dict-sql.conf.ext
[code]vim /etc/dovecot/dovecot-dict-sql.conf.ext[/code]
[code]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
}[/code]
重新启动服务
[code]service postfix restart
service dovecot restart[/code]
开启相关服务
[code]#开机启动
chkconfig httpd on
chkconfig mysqld on
chkconfig dovecot on
chkconfig postfix on[/code]
Centos6 Postfix+Dovecot+Postfixadmin
标签:
原文地址:http://www.cnblogs.com/HsiaX/p/5573685.html