-------------------环境准备一--------------------
lamp环境:
rpm -ivh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum -y install --enablerepo=remi --enablerepo=remi-php56 mysql-server mysql mysql-devel php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
systemctl start mysqld
mysqladmin -u root password '123456'
mysql -uroot -p
mysql> create database postfix default character set utf8 collate utf8_bin;
mysql> grant all on postfix.* to 'postfix'@'%' identified by 'postfix';
mysql> grant all on postfix.* to 'postfix'@'localhost' identified by 'postfix';
chkconfig mysqld on
systemctl enable httpd
hostnamectl set-hostname mail.abc.com
groupadd -g 5000 vmail
useradd -g vmail -u 5000 -s /sbin/nologin vmail
-------------------环境准备二--------------------
yum -y install cyrus-sasl
vim /etc/sysconfig/saslauthd
SOCKETDIR=/var/run/saslauthd
MECH=shadow
FLAGS=
vim /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
log_level: 3
saslauthd_path:/var/run/saslauthd/mux
useradd linux &&echo 'linux'| passwd --stdin linux
systemctl start saslauthd
systemctl enable saslauthd
testsaslauthd -u linux -p 'linux' #测试
yum -y install postfix
vim /etc/postfix/main.cf
myhostname = mail.abc.com
mydomain = abc.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
local_recipient_maps =
virtual_mailbox_base = /home/vmail/
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
message_size_limit = 10485760
mailbox_size_limit = 1073741824
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_application_name = smtpd
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination,reject_unknown_sender_domain
smtpd_sasl_security_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
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_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_alias_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_mailbox_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = dovecot
systemctl start postfix
systemctl enable postfix
yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
vim /etc/dovecot/dovecot.conf
protocols = imap pop3
listen = *
login_trusted_networks = 192.168.0.0/24
passdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
driver = static
args = uid=5000 gid=5000 home=/home/vmail/%d/%n
}
auth_debug_passwords=yes
mail_debug=yes
auth_verbose=yes
auth_verbose_passwords=plain
vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login cram-md5
vim /etc/dovecot/conf.d/10-ssl.conf
ssl = no
systemctl start dovecot
systemctl enable dovecot
#看有没有以下服务,如果没有则忽略一下两步
/etc/init.d/portreserve stop
chkconfig portreserve off
vim /etc/postfix/master.cf
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient} #此处必须有两个空格
mkdir /etc/postfix/sql/
cd /etc/postfix/sql/
vim mysql_virtual_alias_domain_catchall_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
vim mysql_virtual_alias_domain_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u','@',alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
vim mysql_virtual_alias_domain_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
vim mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
vim mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
vim 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'
vim mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/home/vmail/%d/%n/Maildir
vim /etc/dovecot/conf.d/10-master.conf
service imap-login {
inet_listener imap {
port = 143
}
}
service pop3-login {
inet_listener pop3 {
port = 110
}
}
service auth {
unix_listener auth-userdb {
mode = 0600
user = vmail
group = vmail
}
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
}
}
vim /etc/dovecot/conf.d/15-lda.conf
postmaster_address = [email protected]
vim /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix
default_pass_scheme = MD5-CRYPT
password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'
user_query = SELECT maildir, 5000 AS uid, 5000 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'
wget http://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.93/postfixadmin-2.93.tar.gz
tar -xf postfixadmin-2.93.tar.gz
mv postfixadmin-2.93 /var/www/html/postfixadmin
chown -R apache:apache /var/www/html/postfixadmin
chmod -R 755 /var/www/html/postfixadmin
vim /var/www/html/postfixadmin/config.inc.php
$CONF['configured'] = true;
$CONF['default_language'] = 'cn';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix';
$CONF['database_name'] = 'postfix';
$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';
systemctl start httpd
systemctl enable httpd
生产环境记得放开80端口
vim /var/www/html/postfixadmin/setup.php
#修改
if ( $f_imap_open == 0)
#创建管理员账户
http://mail.abc.com/postfixadmin/setup.php
#登陆管理用户账户
http://mail.abc.com/postfixadmin/login.php
总结启动的服务:
systemctl start dovecot
systemctl start postfix
systemctl start mysqld
systemctl start httpd
systemctl start saslauthd
如果在创建邮箱时,vmail目录没有生成,需要自己创建
mkdir /home/vmail
chown -R vmail:vmail /home/vmail
chmod 755 /home/vmail
-------------------环境准备三--------------------
启用ssl加密
cd /etc/pki/tls/certs
make server.key #输入个密码
openssl rsa -in server.key -out server.key
make server.csr
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
chmod 400 server.*
vim /etc/postfix/main.cf
#添加到最后
smtpd_use_tls= yes
smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt
smtpd_tls_key_file = /etc/pki/tls/certs/server.key
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_loglevel = 0
smtpd_tls_auth_only = yes
vim /etc/postfix/master.cf
#去掉注释
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
vim /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
# 第12,13行:
ssl_cert =
vim /etc/postfix/master.cf
#取消注释
submission inet n - n - - smtpd
#重启服务
systemctl restart dovecot
systemctl restart postfix