收藏 分销(赏)

邮件服务器搭建.doc

上传人:pc****0 文档编号:9211354 上传时间:2025-03-17 格式:DOC 页数:51 大小:2.83MB
下载 相关 举报
邮件服务器搭建.doc_第1页
第1页 / 共51页
邮件服务器搭建.doc_第2页
第2页 / 共51页
点击查看更多>>
资源描述
搭建邮件服务器 大纲 一、mail 协议 二、mail 组件 三、mail 工作原理(两种对比) 四、安装前的准备工作 五、安装并配置LAMP环境 六、安装并配置postfixadmin 七、安装并配置phpmyadmin 八、配置postfix邮件发送代理 九、安装并配置dovecot邮件检索代理 十、测试SMTP与POP3服务 十一、安装并配置WebMail(Roundcubemail) 十二、安装并配置病毒扫描与垃圾邮件过滤 十三、安装并配置managesieve插件 十四、常见问题分析 注:系统,CentOS 6.4 X86_64 。软件,全部都是RPM包,有兴趣的博友可以尝试一下全部源码包安装!(所安装的主要软件如下,LAMP+Postfix+Dovecot+PostfixAdmin+Roundcubemail+Amavisd-new+ClamAV+SpamAssassin+Managesieve) 软件包下载 一、mail 协议 mail使用的协议有, 协议名称 协议类型 端口号 smtp tcp 25 pop3 tcp 110 smtps tcp 465 pop3s tcp 995 imap tcp 143 imaps tcp 993 二、mail 组件 1.MTA:mail transfer agent 邮件传输代理 常见软件, 1 2 3 4 5 Exchange(微软) Sendmail 开源的软件 目前有50%的邮件服务器使用这个软件 Postfix 现在用的挺多 Qmail 昙花一现 Exim(英国剑桥大学开发的) 2.MRA:mail retravial agent 邮件检索代理 常见软件, 1 2 courier-imap:pop3,imap4,imaps,pop3s (俄罗斯开发) dovecot (主流) 3.MDA:mail delivery agent 邮件投递代理 常见软件, 1 2 procmail (postfix默认) maildrop (功能强大,效率高) 4.MUA:mail user agent 邮件用户代理 常见软件, 1 2 3 4 outlook express Foxmail pine(linux) mutt(linux,经常用到的) 5.Mailbox 信箱 1 2 3 mailbox maildir (主流) 两者的主要区别,mailbox是把所有邮件放在同一个文件中,maildir把每个用户的邮件都单独存放 三、mail 工作原理 1.常规架构 如下图, 各组件具体说明 (1).常用的客户端 1 2 Mail Client:outlook,foxmail等 Web Browser:IE,Firefox,Chrome等 (2).Postfix,最常用的MTA,我们通过postfix来发送邮件 (3).Dovecot,最常用的MRA,我们通过dovecot来收发邮件 (4).amavisd-new,可以理解成一个代理,Postfix把邮件交给他,他负责联系杀毒和反垃圾 (5).SpamAssassin,防垃圾邮件,是邮件系统的基本功能,SpamAssassin,是最有名的,尤其是和Amavisd ClamAV结合起来,这是一个经得起考虑的组合 (6).ClamAV,对邮件进行病毒扫描 (7).Cyrus-SASL,认证函数库 (8).Courier-Authlib,调用mysql数据库进行认证 (9).WebMail,通过浏览器来管理收发邮件 (10).OpenLDAP或MySQL,虚拟用户或虚拟域的存放数据库 (11).Maildir或Mailbox,用来存放用户邮件,两者的区别在于maildir为每个用户单独存放邮件,mailbox是所有邮件都存放在同一文件 (12).phpLDAPadmin,管理LDAP工具,用来管理虚拟用户与虚拟域 2.具体工作流程 (1). 当邮件通过outlook或foxmail发送到服务器的25端口,postfix接受连接,它会做一些基本检查 发送者是否在黑名单或者实时黑名单,如果在黑名单,马上拒绝 是否是授权用户,是授权可以进行转发 接收者是否是服务器的用户,在这里postfix调用Cyrus-SASL认证函数库,并通过Courier-Authlib去mysql数据中验证用户,如果不是,马上拒绝 如果我们启用了灰名单,会进行判断是否会拒绝邮件或者接收 (2).postfix 把邮件通过10024端口交给amavis来处理,注意amavis,只会检查邮件而不会丢弃或者拒绝邮件(如上图) (3).amavis调用SpamAssassin检查邮件是否是spam,如果SpamAssassin认为邮件是垃圾邮件,会给邮件打上标记spam(如下图) (注:大家会看到,只会给邮件打上spam标记,我们还是可以收到这个邮件的) (4).amavis调用ClamAV,看邮件是否含有病毒 (5).amavis把检查完的邮件,通过10025端口重新把邮件交回给postfix (6).postfix把邮件交给LDA(local delivery agent),LDA是负责本地邮件投放到用户的邮箱,postfix默认使用 procmail 投递邮件(我们也可以使用其它投递代理如,maildrop)到 用户的邮箱并以maildir的方式存放在硬盘上 (7).用户使用邮件客户端,通过pop3或imap协议进行连接并管理邮件,webmail 是通过imap的方式来读取或管理邮件 总结,从上面的工作流程我们可以看到用Cyrus-SASL,Courier-authlib,Maildrop太麻烦了。一大堆组件,邮件系统本来就很杂。我以能简单则简单的原则进行了精简而且效率更高,Dovecot目前已经实现了SASL,而且Dovecot的SASL能够自动CACHE查询结果,这个是比较好的。并且Dovecot还可以当LDA使用。而Postfix也支持Dovecot的SASL验证。Postfix可以直接使用Dovecot的后台认证,不需要分开配置。(如果使用Courier,我们必须安装配置额外的认证软件,比如Saslauthd,配置这个,会是一个恶梦,如果出现问题,很难排错),并且Dovecot,可以很方便实现磁盘配额的功能。Dovecot作为Courier的可替换组件,Dovecot在磁盘读写量上比Courier减少25%左右,内存占用也比Courier节省10%到70%不等。好了,说了这么多下面我们来看一下,我们的精简架构! 3.精简架构 经过与上面的对比我们明显看到简单了许多,嘿嘿!下面我们说一下具体的工作流程, (1).当邮件发送到服务器的25端口,postfix接受连接,它会做一些基本检查 发送者是否在黑名单或者实时黑名单,如果在黑名单,马上拒绝 是否是授权用户,是授权用户可以进行转发 接收者是否是服务器的用户,Postfix通Dovecot提供的SASL进行认证,如果不是,马上拒绝 如果我们启用了灰名单,会进行判断是否会拒绝邮件或者接收 (2).postfix 把邮件通过10024端口交给amavis来处理,注意amavis,只会检查邮件而不会丢弃或者拒绝邮件 (3).amavis调用SpamAssassin检查邮件是否是spam,如果SpamAssassin认为邮件是垃圾邮件,会给邮件打上标记spam(同上) (4).amavis调用ClamAV,看邮件是否含有病毒 (5).amavis把检查完的邮件,通过10025端口重新把邮件交回给postfix (6).postfix把邮件交给LDA(local delivery agent),LDA是负责本地邮件投放到用户的邮箱,(我们这里使用dovecot提供的LDA功能,而不是postfix提供的LDA)邮件会进入用户的邮箱,Dovecot会执行用户设置的filter,也就是Dovecot通过调用Sieve,放到相关的文件夹 (7).Dovecot 把邮件以maildir的方式存放在硬盘上。 (8).用户使用邮件客户端,通过pop3或imap协议进行连接。Webmail(RoundCubeMail),是通过imap的方式来读取邮件。 总结,经过上面的简单说明你应该知道整个邮件系统的工作流程了,下面我们将完整的搭建这套企业级的邮件系统!^_^…… 四、安装前的准备工作 1.关闭防火墙与SELinux 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [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 2.修改主机名 1 2 3 4 [root@mail ~]# vim /etc/sysconfig/network NETWORKING=yes HOSTNAME= [root@mail ~]# reboot 3.下载并安装yum源 (1).163的yum源 (2).rpmforge软件仓库 1 2 3 4 [root@mail ~]# wget [root@mail ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm [root@mail ~]# ls anaconda-ks.cfg CentOS6-Base-163.repo install.log install.log.syslog rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm (3).备份原有的yum源 1 2 3 4 5 6 7 8 [root@mail ~]# cd /etc/yum.repos.d/ [root@mail yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo [root@mail yum.repos.d]# mkdir backup [root@mail yum.repos.d]# mv CentOS-* backup/ [root@mail yum.repos.d]# ls backup [root@mail yum.repos.d]# (4). 增加新的yum源 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [root@mail ~]# cp CentOS6-Base-163.repo /etc/yum.repos.d/ [root@mail ~]# rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm warning: rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY Preparing... ########################################### [100%] 1:rpmforge-release ########################################### [100%] [root@mail ~]# ll /etc/yum.repos.d/ 总用量 24 drwxr-xr-x 2 root root 4096 7月 10 22:00 backup -rw-r--r-- 1 root root 2006 7月 10 22:01 CentOS6-Base-163.repo -rw-r--r-- 1 root root 739 11月 13 2010 mirrors-rpmforge -rw-r--r-- 1 root root 717 11月 13 2010 mirrors-rpmforge-extras -rw-r--r-- 1 root root 728 11月 13 2010 mirrors-rpmforge-testing -rw-r--r-- 1 root root 1113 11月 13 2010 rpmforge.repo [root@mail ~]# (5).清理yum缓存并更新系统 1 2 3 4 5 6 [root@mail ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras rpmforge updates Cleaning up Everything Cleaning up list of fastest mirrors [root@mail ~]# yum update 4.创建一个vmail用户,用作管理虚拟邮箱的文件夹 1 useradd -u 2000 -d /var/vmail -m -s /sbin/nologin vmail 五、安装并配置LAMP环境 说明:最新的PostfixAdmin2.3.6+Roundcubemail0.92的PHP环境要求是最低是PHP5.2,我这里RPM安装的是5.3.3 1.安装LAMP环境 1 [root@mail ~]#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 2.整合Apache与PHP 1 2 3 4 5 6 7 8 9 [root@mail ~]# vim /etc/httpd/conf/httpd.conf #增加下面现行 AddType application/x-httpd-php .php #apache解析php程序 PHPIniDir "/etc/php.ini" #指定php.ini配置文件路径 #修改这一行增加index.php DirectoryIndex index.php index.html index.html.var #修改apache运行的用户和组 User vmail Group vmail 3.测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [root@mail ~]# vim /var/www/html/index.php <? phpinfo(); ?> [root@mail ~]# service httpd start 正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName [确定] [root@mail ~]# 注:会有个警告 [root@mail ~]# vim /etc/httpd/conf/httpd.conf #增加一行 ServerName localhost:80 [root@mail ~]# service httpd restart #重新启动不会再有警告 停止 httpd: [确定] 正在启动 httpd: [确定] [root@mail html]# chkconfig httpd on #加入开机自启动 [root@mail html]# chkconfig httpd --list httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [root@mail html]# 测试效果如下, 看到这个图说明LAMP环境安装成功了,嘿嘿!顺便可以看一下imap这个很重要,嘿嘿! 六、安装并配置postfixadmin 1.查看所需软件 1 2 3 4 5 6 7 8 9 10 11 [root@mail ~]# ll 总用量 12804 -rw-------. 1 root root 970 6月 20 05:03 anaconda-ks.cfg -rw-r--r-- 1 root root 2006 9月 1 2011 CentOS6-Base-163.repo -rw-r--r--. 1 root root 15709 6月 20 05:03 install.log -rw-r--r--. 1 root root 4178 6月 20 05:01 install.log.syslog -rw-r--r-- 1 root root 7728693 7月 7 18:48 phpMyAdmin-4.0.4.1-all-languages.zip -rw-r--r-- 1 root root 1597001 7月 7 12:56 postfixadmin-2.3.6.tar.gz -rw-r--r-- 1 root root 3735505 7月 7 12:57 roundcubemail-0.9.2.tar.gz -rw-r--r-- 1 root root 12700 11月 13 2010 rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm [root@mail ~]# 2.解压并修改文件名 1 2 3 4 5 6 7 8 [root@mail ~]# tar xf postfixadmin-2.3.6.tar.gz -C /var/www/html/ [root@mail ~]# cd /var/www/html/ [root@mail html]# ls index.php postfixadmin-2.3.6 [root@mail html]# mv postfixadmin-2.3.6 postfixadmin [root@mail html]# ls index.php postfixadmin [root@mail html]# 3.配置并测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [root@mail html]# cd postfixadmin/ #修改前先备份一下配置文件 [root@mail postfixadmin]# cp config.inc.php config.inc.php.bak [root@mail postfixadmin]# cp setup.php setup.php.bak [root@mail postfixadmin]# vim config.inc.php #找到下面几行并修改 $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@'; $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'; 4.为postfixadmin创建Mysql数据库与权限 1 2 3 4 5 6 7 8 9 [root@mail html]# service mysqld start [root@mail html]# chkconfig mysqld on #加入开机自启动 [root@mail html]# chkconfig mysqld --list mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [root@mail html]# [root@mail ~]# mysql mysql> create database postfix; mysql> grant all on postfix.* to postfix@'localhost' identified by 'postfix'; mysql> flush privileges; 测试一下能不能登录, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [root@mail html]# mysql -upostfix -ppostfix Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.69 Source distribution 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> 测试成功可能登录! 5.修改所有者与所有组 1 2 3 4 5 6 [root@mail html]# chown -R vmail.vmail postfixadmin/ [root@mail html]# ll 总用量 8 -rw-r--r-- 1 root root 18 7月 10 22:18 index.php drwxrwxr-x 14 vmail vmail 4096 7月 10 22:57 postfixadmin [root@mail html]# 6.具体配置过程如下图 (1).http://192.168.18.187/postfixadmin/setup.php 注:检查PHP环境,并初始化数据库 (2).创建设置密码并修改配置文件(我这里的密码是123456) [root@mail postfixadmin]# vim config.inc.php $CONF['setup_password'] = '6471f6462d427bf547c07fb2a08fdecf:09a43f1679223 4050d298b7d0333c101d4bbd48e'; (3) .创建管理员密码 先输入你刚才设置的密码,我这里是123456,然后输入管理员邮箱,我管理员密码! 问题:can't proc_open /usr/bin/doveadm pw 答案:必须打开php的proc_open函数支持 出现错误,说没有dovecotpw,是因为我们还没安装dovecot,我们这里先来安装一下dovecot,后面再进行配置! 1 2 3 4 5 [root@mail postfixadmin]# yum install -y dovecot dovecot-devel dovecot-mysql [root@mail postfixadmin]# chkconfig dovecot on #加入开机自启动 [root@mail postfixadmin]# chkconfig dovecot --list dovecot 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [root@mail postfixadmin]# 我们再来设置一下管理员的账户与密码,(我这里设置是postmaster@ 密码:admin) 看这次设置成功,下面我们管理账户登录一下 7.postfxiadmin不能自动创建目录,所以我们得增加自动建立目录的功能 (1).建立创建虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-creation.sh,脚本内容如下: [root@mail ~]#vim /usr/local/bin/maildir-creation.sh #!/bin/bash # HOME_DIR="/var/vmail" USER_NAME="vmail" GROUP_NAME="vmail" if [ ! -d ${HOME_DIR}/$1 ] ; then mkdir ${HOME_DIR}/$1 chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1 fi mkdir ${HOME_DIR}/$1/$2 chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2 (2).建立删除虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-deletion.sh ,脚本内容如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [root@mail ~]#vim /usr/local/bin/maildir-deletion.sh #!/bin/bash # # vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh # if [ $# -ne 2 ] ; then exit 127 fi DOMAIN="$1" USER="$2" HOME_DIR="/var/vmail" USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}" TRASH_DIR="${HOME_DIR}/deleted-maildirs" DATE=`date "+%Y%m%d_%H%M%S"` if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then mkdir -p "${TRASH_DIR}/${DOMAIN}" fi if [ -d "${USER_DIR}" ] ; then mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE} fi 8.建立删除目录 1 2 [root@mail ~]# mkdir /var/vmail/deleted-maildirs [root@mail ~]# chown -R vmail.vmail /var/vmail/deleted-maildirs/ 9.赋予脚本可执行权限 1 2 [root@mail ~]# chmod 750 /usr/local/bin/maildir-* [root@mail ~]# chown vmail.vmail /usr/local/bin/maildir-* 10.配置sudo 1 2 3 4 5 6 7 [root@mail ~]#vim /etc/sudoers #在 /etc/sudoers 最后增加两行 vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh #在/etc/sudoers 注释掉下面内容 #Defaults requiretty :wq! #由于这个文件是只读的,所以得强制保存并退出 11.修改postfixadmin的相关文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [root@mail ~]# cd /var/www/html/postfixadmin/ [root@mail postfixadmin]# vim create-mailbox.php 修改create-mailbox.php 文件,229行内容应该是: db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername"); 在该行前面增加下面一行, system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']); [root@mail postfixadmin]# vim delete.php 修改delete.php 文件,146行内容应该是, db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete); 在该行下面增加下面4行, $userarray=explode("@",$fDelete); $user=$userarray[0]; $domain=$userarray[1]; system("sudo /usr/local/bin/maildir-deletion.sh $domain $user"); 好了至此postfixadmin配置全部完成,^_^…… 七、安装并配置phpmyadmin 1.解压并重命令 1 2 3 4 5 6 7 8 9 [root@mail ~]# unzip phpMyAdmin-4.0.4.1-
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 百科休闲 > 社会民生

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服