- 论坛徽章:
- 0
|
本帖最后由 who8383 于 2014-12-04 17:45 编辑
安装前的准备工作
关闭防火墙与SELinux
- [root@mail ~]# service iptables stop
- iptables:清除防火墙规则: [确定]
- iptables:将链设置为政策 ACCEPT:filter [确定]
- iptables:正在卸载模块: [确定]
- [root@mail ~]# service ip6tables stop
- ip6tables:清除防火墙规则: [确定]
- ip6tables:将 chains 设置为 ACCEPT 策略:filter [确定]
- :正在卸载模块: [确定]
- [root@mail ~]# chkconfig iptables off
- [root@mail ~]# chkconfig ip6tables off
- [root@mail ~]# vim /etc/selinux/config
- # This file controls the state of SELinux on the system.
- # SELINUX= can take one of these three values:
- # enforcing - SELinux security policy is enforced.
- # permissive - SELinux prints warnings instead of enforcing.
- # disabled - No SELinux policy is loaded.
- SELINUX=disabled
- # SELINUXTYPE= can take one of these two values:
- # targeted - Targeted processes are protected,
- # mls - Multi Level Security protection.
- SELINUXTYPE=targeted
复制代码
[root@mail ~]# reboot (要重启生效)
修改主机名
- [root@mail ~]# vim /etc/sysconfig/network
- NETWORKING=yes
- HOSTNAME=mail.brahmaol.com
- [root@mail ~]# reboot
- [root@mail mail]# cat /etc/hosts
- 10.0.0.253 mail.brahmaol.com
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- [root@mail mail]#
复制代码
创建一个vmail用户,用作管理虚拟邮箱的文件夹
- [root@mail mail]#useradd -u 2000 -d /var/vmail -m -s /sbin/nologin vmail
复制代码
安装mysql/dovecot/httpd/php,由于RPM存在依赖关系采用YUM安装(这个安装非常的方便 ),
- [root@mail mail]# yum install mysql mysql-server msyql-devel dovecot dovecot-mysql php php-imap php-mbstring httpd
复制代码
安装完之后把mysqld dovecot httpd 设置为开机自启动 命令为:chkconfig xxxx on
启动数据库:
service mysqld start
- [root@mail mail]# /usr/bin/mysqladmin -u root password 'root'
复制代码
然后为postfixadmin建立相关数据
接下来配置postfixadmin ,这个到官网去下载,然后将其解压到‘html’目录下。 下载链接可以到网上找
- [root@mail ~]# tar zxvf postfixadmin-2.92.tar.gz
- [root@mail ~]# mv postfixadmin-2.92.tar.gz adminmail
- [root@mail ~]# cp -r adminmail /var/www/html/
复制代码
编辑postfixadmin配置文件
- [root@mail ~]# vim /var/www/html/adminmail/config.inc.php
- $CONF['configured'] = fslah; #改为true
- $CONF['default_language'] = 'en'; #改为cn
- $CONF['database_type'] = 'mysql'; #这里改为你的数据库类型,按版本区分
- $CONF['database_host'] = 'localhost';
- $CONF['database_user'] = 'postfix'; #这里改为数据库的用户名
- $CONF['database_password'] = 'postfix'; #这里改为数据库的密码
- $CONF['database_name'] = 'postfix'; #这里改为存放邮件数据库的名字
- $CONF['emailcheck_resolve_domain']='YES'; #如果你没做MX记录的话,将此项改为NO,
复制代码
修改文件权限
- [root@mail adminmail]# cd /var/www/html/adminmail/
- [root@mail adminmail]# chmod 777 templates_c
- [root@mail adminmail]# service httpd start
- [root@mail adminmail]# service dovecot start
复制代码
测试postfixadmin,进入:IP/adminmail/setup.php
创建postfixadmin后台管理密码并修改配置文件,我设置的密码是...秘密....
- [root@mail adminmail]# vim /var/www/html/adminmail/config.inc.php
- $CONF['setup_password'] = 'c6014f0e7adc2dc05bbfda1e3c83b1b9:506812960c3fe7cb8853e41923b11dc33b969983';
复制代码
输入你刚才设置的密码,在输入你新建的管理员的帐号密码
出现下图就是成功建立了帐号
在进入:ip/adminmail 登录postfixadmin,登录之后新建你的域名和邮件帐号
现在来配置postfix 了,它有俩个主要配置文件,在/etc/postfix目录下的main.cf master.cf
- [root@mail postfix]# vim main.cf 先修改基本的配置
- mydomain = brahmaol.com #改为你邮件的域名
- myhostname = mail.brahmaol.com #改为你的主机名
- mynetworks-style = subnet
- mynetworks = 172.168.96.0/24 #改为你的网段
- home_mailbox = Maildir
- inet_interfaces = all
- inet_protocols = all
- #--------------------以下内容为新添加-------------------------
- virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
- virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
- virtual_mailbox_maps = 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 #这是新建虚拟用户的ID
- virtual_gid_maps = static:2000 #这是新建虚拟组的ID
- virtual_mailbox_base = /var/vmail #邮件存放位置
- #----------------------smtp----------------------------------
- smtpd_sasl_auth_enable = yes #开启认证
- smtpd_sasl_type = dovecot #认证类型
- dovecot_destination_recipient_limit = 1
- 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
复制代码
新建postfix连接数据库查询的文件。 链接数据库的帐号密码请按照实际情况修改
-
- [root@mail postfix]# 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'
- [root@mail ~]# 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'
- [root@mail postfix]# 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'
- [root@mail postfix]# 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'
复制代码
dovecot 配置文件 (由于修改的文件太多,我就不一一列出,直接改/etc/dovecot/dovecot.conf 文件就可以)
- [root@mail postfix]# doveconf -n
- # 2.0.9: /etc/dovecot/dovecot.conf
- # OS: Linux 2.6.32-71.el6.x86_64 x86_64 CentOS Linux release 6.0 (Final) ext4
- protocols = imap pop3
- listen = *
- auth_mechanisms = plain login cram-md5
- dict {
- quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
- }
- disable_plaintext_auth = no
- listen = *
- mail_location = maildir:/var/vmail/%d/%d/%n #命令指定客户端接收邮件到哪个目录请按照实际情况修改
- mbox_write_locks = fcntl
- passdb {
- args = /etc/dovecot/dovecot-sql.conf.ext
- driver = sql
- }
- protocols = imap pop3
- service auth {
- unix_listener auth-client {
- group = postfix
- mode = 0600
- user = postfix
- }
- unix_listener auth-userdb {
- group = vmail
- mode = 0600
- user = vmail
- }
- }
- service dict {
- unix_listener dict {
- group = vmail
- mode = 0600
- user = vmail
- }
- }
- ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
- ssl_key = </etc/pki/dovecot/private/dovecot.pem
- userdb {
- args = /etc/dovecot/dovecot-sql.conf.ext
- driver = sql
- }
- [root@mail postfix]#
复制代码
新建dovecot-sql.conf.ext与dovecot-dict-sql.conf.ext 文件
- [root@mail postfix]# vim /etc/dovecot/dovecot-sql.conf.ext
- driver = mysql
- connect = host=localhost dbname=postfix user=postfix password=postfix
- default_pass_scheme = 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'
- [root@mail postfix]# 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
- }
复制代码
到此,配置结束。现在可以进行测试邮件服务器是否正常工作 由于该文档是在我搭建了服务器之后才写的,有些地方可能没写到位,如果有报错的地方多看日志,
下面说下我在测试时遇到的问题。可以pop3/IMAP登录,发信也没问题,可对方收不到邮件,对方发给我的邮件也收不到,查看日志没有报错,在/var/vmail/域名/域名/user/new 可以看到对方发过来的邮件。可是客户端获取不到邮件,这种情况的话就要修改配置文件
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/var/vmail/%d/%d/%n 》根据邮件位置修改
然后在保存重启dovecot 服务后一切正常!!! 有问题欢迎联系我,大家一起讨论
|
|