基于虚拟账号的邮件系统

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

按照如下图所以创建基于虚拟账号的邮件系统:

 image

如上图所示:客户端登录邮件系统需要经过cyrus-sasl函数库账号的认证,但是cyrus-sasl无法调用mysql,所以必须安装courier-authlib来调用mysql。

发送邮件时使用dovecot来进行接收。extmail为用户提供web界面的方式来进行邮件的接收或发送。extman是为管理员提供管理的web界面。

postfix默认无法支持mysql数据库,所以在此必须使用源码按安装postfix

修改主机名:

[root@lyt ~]# vim /etc/sysconfig/network

image

[root@lyt ~]# vim /etc/hosts

image

[root@lyt named]# init 6      #重启,使新建立的主机名生效

[root@lyt ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo      #编辑本地yum

image

搭建dns服务器:

[root@lyt ~]# mkdir /mnt/cdrom

[root@lyt ~]# mount /dev/cdrom /mnt/cdrom/

[root@lyt ~]# cd /mnt/cdrom/Server/

[root@lyt Server]# yum install bind -y

[root@lyt Server]# yum install bind-chroot -y

[root@lyt Server]# yum install caching -y

[root@lyt Server]# yum install caching-nameserver -y

[root@lyt Server]# cd /var/named/chroot/etc/

[root@lyt etc]# cp -p named.caching-nameserver.conf named.conf

[root@lyt etc]# vim named.conf

image

[root@lyt etc]# vim named.rfc1912.zones

image

[root@lyt etc]# cd ../var/named/

[root@lyt named]# cp -p localhost.zone a.com.db

[root@lyt named]# vim a.com.db

image

[root@lyt named]# vim /etc/resolv.conf

image

[root@lyt named]# service named start

[root@mail ~]# chkconfig named on

[root@mail ~]# service sendmail stop       #使用postfix接收邮件,所以此处关闭sendmail

[root@mail ~]# chkconfig sendmail off       #设置开机关闭该服务器

[root@mail ~]# yum install httpd  php  php-mysql  mysql  mysql-server  mysql-devel  openssl-devel  dovecot  perl-DBD-MySQL  tcl  tcl-devel  libart_lgpl       #使用yum安装这些软件包

libart_lgpl-devel libtool-ltdl  libtool-ltdl-devel  expect      #使用yum安装响应的rpm软件包

[root@mail Server]# yum grouplist      #查看安装以下开发所用到的rpm包组

image 

[root@mail Server]# service mysqld start      #启动mysql服务

[root@mail Server]# chkconfig mysqld on        #开机自动启动mysql

[root@mail Server]# mysql      #进入mysql

image

image

image

搭建postfix:

[root@mail ~]# groupadd -g 2525 postfix       #创建组postfix,组的id号2525

[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix       #创建用户postfix,-u表示用户,id号为2525,-M表示不为该用户创建家目录;并将该用户postfix加入到组postfix中。-s  /sbin/nologin表示不可登录

[root@mail ~]# groupadd -g 2526 postdrop    #创建组postdrop,组的id号为2526

[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop      #创建用户postdrop,-u表示用户,id号为2526,-M表示不为该用户创建家目录;并将该用户postdrop加入到组postdrop中。使用/bin/false表示不能登录,-s表示shell。

[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/        #拆包

[root@mail ~]# cd /usr/local/src/

[root@mail src]# cd postfix-2.8.2/

[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl –lcrypto'      #CCARGS表示gcc的一些变量,-DHAS_MYSQL表示调用mysql       -I/usr/include/mysql 由于mysql是用rpm包装的,是标准路径下的头文件,-DUSE_SASL_AUTH表示要结合sasl验证,-DUSE_CYRUS_SASL表示结合sasl 验证,-I/usr/include/sasl 表示sasl的头文件,-DUSE_TLS表示使用tls安全传输层协议,AUXLIBS=-L/usr/lib/mysql表示辅助库文件,也即mysql的库文件,(在源码安装中,包后生成的文件中都含有./configure文件,此文件中没有./configure文件,则使用此方法代替./configure文件)

[root@mail postfix-2.8.2]# make     #编译

[root@mail postfix-2.8.2]# make   install     #安装。按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值))

image

image

[root@mail postfix-2.8.2]# newaliases     #生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:

[root@mail postfix-2.8.2]# postfix start     #启动postfix

[root@mail postfix-2.8.2]# netstat -tupln |less    

image

[root@mail postfix-2.8.2]# postconf -m      #查看postfix可以调用的模块,-m表示模块

image

[root@mail postfix-2.8.2]# postconf –a       #查看使用以下命令验正postfix是否支持cyrus风格的sasl认证

image

启用postfix可以使用命令postfix  start ,如果想要用service postfix start,可以作如下修改: 
[root@mail postfix-2.8.2]# mkdir /tmp/abc

[root@mail postfix-2.8.2]# cd /tmp/abc/

[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./     #拷贝rpm包

[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio –id        #使用rpm2cpio将postfix拆包

[root@mail abc]# cd etc/rc.d/init.d/

[root@mail init.d]# cp postfix /etc/init.d/     #将该postfix文件拷贝到开机脚本中(开机脚本有/etc/init.d或者/etc/rc.d/init.d)

[root@mail init.d]# service postfix restart      #已经可以使用此命令

[root@mail init.d]# chkconfig --add postfix      #将postfix加入到chkconfig中,可以使用chkconfig管理postfix的进程

[root@mail init.d]# chkconfig postfix on      #将postfix设置为开机自动启动

[root@mail init.d]# useradd user1    #创建user1

[root@mail init.d]# passwd user1     #为user1创建密码

[root@mail init.d]# telnet 127.0.0.1 25     #使用telnet登录本地邮件服务器

image

[root@mail init.d]# vim /etc/postfix/main.cf      #编辑postfix的主配置文件

image

image

image

image

image

[root@mail init.d]# postfix check       #检测postfix的配置文件的语法

[root@mail init.d]# service postfix restart     #重启该服务

[root@mail init.d]# vim /etc/postfix/main.cf          #添加以下内容

image

[root@mail init.d]# cd /usr/lib/sasl2/

[root@mail sasl2]# cp -p Sendmail.conf smtpd.conf

[root@mail sasl2]# vim smtpd.conf

image

[root@mail sasl2]# service saslauthd start       #启用sasl验证服务

[root@mail sasl2]# chkconfig saslauthd on      #开机自动启动

image

安装Courier authentication library

[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/local/src/

[root@mail ~]# cd /usr/local/src/

[root@mail src]# cd courier-authlib-0.63.1.20111230/

[root@mail courier-authlib-0.63.1.20111230]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include       #--prefix表示安装路径、sysconfdir表示配置文件路径、--with-authmysql表示要验证账号调用mysql数据库、--with-mysql-libs表示mysql的库文件、--with-mysql-include表示头文件、--with-redhat表示红帽

[root@mail courier-authlib-0.63.1.20111230]# make

[root@mail courier-authlib-0.63.1.20111230]# make install

[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/      #更改该文件权限

[root@mail courier-authlib-0.63.1.20111230]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc

[root@mail courier-authlib-0.63.1.20111230]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/authdaemonrc

image

image

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/authmysqlrc     #编辑/etc/authmysqlrc 为以下内容,其中2525,2525 为postfix 用户的UID和GID。

MYSQL_SERVER localhost 
MYSQL_PORT 3306                   (指定你的mysql监听的端口,这里使用默认的3306) 
MYSQL_USERNAME  extmail      (这时为后文要用的数据库的所有者的用户名) 
MYSQL_PASSWORD extmail        (密码) 
MYSQL_SOCKET  /var/lib/mysql/mysql.sock 
MYSQL_DATABASE  extmail 
MYSQL_USER_TABLE  mailbox   (mysql用户表格mailbox) 
MYSQL_CRYPT_PWFIELD  password   
MYSQL_UID_FIELD  '2525'      (虚拟账号映射的真实账号) 
MYSQL_GID_FIELD  '2525' 
MYSQL_LOGIN_FIELD  username 
MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)    (虚拟用户的主目录) 
MYSQL_NAME_FIELD  name 
MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)    (虚拟用户的邮箱)

[root@mail courier-authlib-0.63.1.20111230]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib      #将该文件拷贝到开机脚本中,以便使用service进行控制

[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /etc/init.d/courier-authlib     #为该脚本赋予可执行权限

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart     #此时已经可以使用service控制该服务

[root@mail courier-authlib-0.63.1.20111230]# chkconfig --add courier-authlib    #将该服务加入到chkconfig中,以便使用chkconfig进行控制

[root@mail courier-authlib-0.63.1.20111230]# chkconfig courier-authlib on     #设置开机自动启动

[root@mail courier-authlib-0.63.1.20111230]# chkconfig --list |grep authlib        #使用--list查看authlib服务已经在那些级别中启

[root@mail courier-authlib-0.63.1.20111230]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf       #由于courier-authlib是源码安装,其库文件不是标准路径,系统无法调用,所以将库文件/usr/local/courier-authlib重定向到标准路径/etc/ld.so.conf.d/中,并新建立一个文件名叫做courier-authlib.conf。

[root@mail courier-authlib-0.63.1.20111230]# ldconfig –v     #重新加载库文件调用

[root@mail courier-authlib-0.63.1.20111230]# ldconfig -pv |grep authlib       #查看对库文件authlib的调用能否成功

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart     #重启一下该服务

[root@mail courier-authlib-0.63.1.20111230]# mkdir -pv /var/mailbox      #新建虚拟用户邮箱所在的目录

[root@mail courier-authlib-0.63.1.20111230]# chown  -R postfix /var/mailbox      #将其权限赋予postfix用户

[root@mail courier-authlib-0.63.1.20111230]# vim /usr/lib/sasl2/smtpd.conf       #编辑该文件保证有一下行:

pwcheck_method: authdaemond 
mech_list:PLAIN LOGIN 
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

[root@mail courier-authlib-0.63.1.20111230]# service saslauthd restart       #重启

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart      #重启

让postfix支持虚拟域和虚拟用户

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/postfix/main.cf        #编辑该文件,保证有以下行:

安装extmail(访问)和extman(管理)

[root@mail courier-authlib-0.63.1.20111230]# cd

[root@mail ~]# tar -zxvf  extman-1.1.tar.gz        #只需拆包即可,他是一个导入文件

[root@mail ~]# cd extman-1.1

[root@mail extman-1.1]# cd docs/

image

[root@mail docs]# mysql -u root –p      #登录mysql数据库

image

image

[root@mail docs]#  cp mysql*  /etc/postfix/         #将mysql_virtual文件拷贝到/etc/postfix中

[root@mail docs]# mysql -u root –p       #登录数据库,授予用户extmail访问extmail数据库的权限

mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail'; 
mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail'; 
mysql>FLUSH PRIVILEGES;   让设置的内容生效 
mysql> quit;

[root@mail docs]# service postfix restart      #重启postfix服务

搭建dovecot

[root@mail docs]# vim /etc/dovecot.conf

image

image

image

image

image

image

[root@mail docs]# vim /etc/dovecot-mysql.conf       #编辑该文件,保证有以下行

driver = mysql 
connect = host=localhost dbname=extmail user=extmail password=extmail 
default_pass_scheme = CRYPT 
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'                            
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'

[root@mail docs]# vim /etc/postfix/main.cf

image

[root@mail docs]# service postfix restart

[root@mail docs]# service dovecot start

[root@mail docs]# chkconfig dovecot on     #设置开机自动启动

安装Extmail-1.2 

[root@mail ~]# tar -zxvf extmail-1.2

[root@mail ~]# mkdir -pv /var/www/extsuite     #该目录是extmail的固定目录

[root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail       #移动并改名

[root@mail ~]# mv extman-1.1 /var/www/extsuite/extman

[root@mail ~]# cd /var/www/extsuite/

[root@mail extsuite]# cd extmail/

[root@mail extmail]# cp webmail.cf.default webmail.cf

[root@mail extmail]# vim webmail.cf

image

image

image

image

apache相关配置

[root@mail extmail]# service httpd start

[root@mail extmail]# chkconfig httpd on

[root@mail extmail]# vim /etc/httpd/conf/httpd.conf

image 

image

[root@mail extmail]# chown -R postfix.postfix   /var/www/extsuite/extmail/cgi/    #修改extmail下cgi目录的用户和组

安装Extman-1.1

[root@mail extmail]# cd /var/www/extsuite/

[root@mail extsuite]# cd extman/

[root@mail extman]# cp  webman.cf.default webman.cf       #拷贝该模板文件并改名

[root@mail extman]# vim webman.cf

image

image

[root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/     #修改extman目录下cgi目录的用户和组

[root@mail extman]# vim /etc/httpd/conf/httpd.conf

image

[root@mail extman]# mkdir  -pv  /tmp/extman      #创建extman运行时所需的临时目录

[root@mail extman]# chown postfix.postfix  /tmp/extman      #修改其用户和组权限

[root@mail extman]# cd

依赖关系的解决

[root@mail ~]# tar  -zxvf Unix-Syslog-1.1.tar.gz

[root@mail ~]# cd Unix-Syslog-1.1

[root@mail Unix-Syslog-1.1]# perl Makefile.PL

[root@mail Unix-Syslog-1.1]#  make

[root@mail Unix-Syslog-1.1]#  make install

[root@mail Unix-Syslog-1.1]# service httpd restart

测试:

此时邮件还不能发送,作如下修改即可:

[root@mail Unix-Syslog-1.1]# vim /etc/postfix/main.cf

image

[root@mail Unix-Syslog-1.1]# service postfix restart

首先要进入后台管理:

image

image

image

image

image

image

注册域:

image

注册用户test1:

image

image

image

image

注册用户test2与test1方法一样,这里不再赘述

test2向test1发送邮件:

image 

image

test1向test2发送邮件:

image

image










本文转自 liuyatao666 51CTO博客,原文链接:http://blog.51cto.com/5503845/991092,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
数据安全/隐私保护
邮箱搬家(上) -- 管理员统一搬家
最近在使用阿里的企业邮箱,虽然我没有企业,只是单纯的个人使用,但是把自己的域名作为邮箱后缀,感觉逼格比@qq、@163等等高太多了。比如gg@yiangg.com对比我的2348**38@qq.com。
3469 0
|
关系型数据库 MySQL 数据库
|
测试技术 网络安全 数据库
|
Apache 数据库 数据安全/隐私保护

热门文章

最新文章