CentOS7 最小化安装,基于 LAMP,安装环境:CENTOS Mysql Apache Postfix Dovecot.

web 模块是最先需要确定的,因为它决定了邮箱系统最核心的数据结构,这里选用国产的 extmail,其他所有模块都按照 extmail 的结构进行配置修改。

如果在 main.cf 里设置 virtual_transport = virtual,就表示对于包含在 virtual_mailbox_domains域名里的邮件,都使用virtual进行投递。

用户信息存储方式也有很多可选的,比如 mysql, ldap 等。这里选 mysql,原因是各个模块,包括extmail 等对这个支持最好最方便最简单。在投递邮件的时候,需要确定一些数据,比如收件用户的Maildir 的路径,保存邮件用的 uid,gid,邮箱容量等,这些数据需要 courier-authlib 来提供。

整个系统模块间的作用和关系是:

postfix 作为 MTA(Mail Transfer Agent), 负责创建 smtp 服务(smtpd)接收本域用户或其他域名服务器投递来的邮件,负责向其他服务器投递(发送)邮件,管理邮件队列;

courier-authlib 为 maildrop 提供与用户相关的信息查询;

dovecot 提供系统的 POP3 和 IMAP 服务,同时给 postfix 提供 SMTP 的 SASL 认证服务。

一、 装备工作

1、防止不必要的麻烦关闭 Selinux

setenforce 0

2、关闭防火墙

systemctl stop firewalld

3、添加 MySQL 和 epel 源

yum install -y wget

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -ivh epel-release-latest-7.noarch.rpm

二、安装postfix

1、安装编译及其他所需要的包

yum install nginx vim gcc gcc-c++ openssl openssl-devel db4-devel ntpdate mysql mysql-devel mysql-server bzip2 php-mysql cyrus-sasl-md5 perl-GD perl-DBD-MySQL perl-GD perl-CPAN perl-CGI perl-CGI-Session cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel libtool-ltdl-devel telnet mail libicu-devel -y

2、编译安装postfix

i. 卸载系统自带的postfix,删除postfix用户,重新指定uid、gid创建新用户postfix,postdrop

yum remove postfix -y

userdel postfix

groupdel postdrop

groupadd -g 2525 postfix

useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

groupadd -g 2526 postdrop

useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

ii. 下载源码包并解压编译

wget http://mirrors.go-parts.com/postfix/source/official/postfix-3.0.1.tar.gz

tar xf postfix-3.0.1.tar.gz

cd postfix-3.0.1

make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS '

'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lrt -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'

make && make install

make install 的时候会有个交互式的界面,自定义一些目录,我们这里只更改第二项临时文件目录,其他的全部默认。

Please specify the prefix for installed file names. Specify this ONLY

if you are building ready-to-install packages for distribution to OTHER

machines. See PACKAGE_README for instructions.

install_root: [/]

Please specify a directory for scratch files while installing Postfix. You

must have write permission in this directory.

tempdir: [/root/postfix-3.0.1] /tmp/extmail

…………………………

…………………………

shlib_directory: [no]

Please specify the final destination directory for non-executable files

that are shared among multiple Postfix instances, such as postfix-files,

dynamicmaps.cf, as well as the multi-instance template files main.cf.proto

and master.cf.proto.

meta_directory: [/etc/postfix]

3、更改目录属主属组

chown -R postfix:postdrop /var/spool/postfix

chown -R postfix:postdrop /var/lib/postfix/

chown root /var/spool/postfix

chown -R root /var/spool/postfix/pid

4,修改postfix的配置文件

[root@localhost ~]# vim /etc/postfix/main.cf

myhostname = {hostname} //设置主机名

mydomain = {domain} //指定域名

myorigin = $mydomain //指明发件人所在的域名

inet_interfaces = //all指定postfix系统监听的网络接口

mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain //指定postfix接收邮件时收件人的域名 [使用虚拟域需要禁用]

mynetworks_style = host //指定信任网段类型

mynetworks = 192.168.1.0/24, 127.0.0.0/8 //指定信任的客户端

relay_domains = $mydestination //指定允许中转邮件的域名

alias_maps = hash:/etc/aliases //设置邮件的别名

三、安装dovecot

1、yum安装

yum install -y dovecot dovecot-mysql

2、配置dovecot

[root@localhost ~]# cd /etc/dovecot/

[root@localhost dovecot]# vim dovecot.conf //直接在配置文件最后添加即可

protocols = imap pop3

!include conf.d/*.conf

listen = *

base_dir = /var/run/dovecot/

[root@localhost dovecot]# cd conf.d/

[root@localhost conf.d]# vim 10-auth.conf

disable_plaintext_auth = no

[root@localhost conf.d]# vim 10-mail.conf

mail_location = maildir:~/Maildir

mail_location = maildir:/var/mailbox/%d/%n/Maildir

mail_privileged_group = mail

[root@localhost conf.d]# vim 10-ssl.conf

ssl = no

[root@localhost conf.d]# vim 10-logging.conf

log_path = /var/log/dovecot.log

info_log_path = /var/log/dovecot.info

log_timestamp = "%Y-%m-%d %H:%M:%S "

[root@localhost conf.d]# cp auth-sql.conf.ext auth-sql.conf

[root@localhost conf.d]# vim auth-sql.conf

passdb {

driver = sql # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext

args = /etc/dovecot/dovecot-sql.conf

}

userdb {

driver = sql

args = /etc/dovecot/dovecot-sql.conf

}

3、编辑dovecot通过mysql认证的配置文件

[root@localhost conf.d]# 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'

四、安装courier-authlib

1、下载解压并并编译

[root@localhost ~]# wget https://sourceforge.net/projects/courier/files/authlib/0.66.2/courier-authlib-0.66.2.tar.bz2

[root@localhost ~]# tar xf courier-authlib-0.66.2.tar.bz2

[root@localhost ~]# cd courier-authlib-0.66.2

[root@localhost ~]# ./configure \

--prefix=/usr/local/courier-authlib \

--sysconfdir=/etc \

--without-authpam \

--without-authshadow \

--without-authvchkpw \

--without-authpgsql \

--with-authmysql \

--with-mysql-libs=/usr/lib64/mysql \

--with-mysql-includes=/usr/include/mysql \

--with-redhat \

--with-authmysqlrc=/etc/authmysqlrc \

--with-authdaemonrc=/etc/authdaemonrc \

--with-mailuser=postfix

这里会报错,configure: error: The Courier Unicode Library 1.2 appears not to be installed.提示 Courier Unicode Library 没有安装,下载 courier-unicode-1.2 并编译安装。

[root@localhost ~]# wget https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-1.2.tar.bz2

[root@localhost ~]# tar xf courier-unicode-1.2.tar.bz2

[root@localhost ~]# cd courier-unicode-1.2

[root@localhost courier-unicode-1.2]# ./configure

[root@localhost courier-unicode-1.2]# make && make install

再次编译 courier-authlib,最后 make && makeinstall

2、配置 courier-authlib

[root@localhost courier-authlib-0.66.2]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

[root@localhost courier-authlib-0.66.2]# cp /etc/authdaemonrc.dist /etc/authdaemonrc

[root@localhost courier-authlib-0.66.2]# cp /etc/authmysqlrc.dist /etc/authmysqlrc

验证方法使用authmysql

[root@localhost courier-authlib-0.66.2]# vim /etc/authdaemonrc

authmodulelist="authmysql"

authmodulelistorig="authmysql"

[root@localhost courier-authlib-0.66.2]# vim /etc/authmysqlrc //直接添加到配置文件尾部,然后去上面将响应系统默认的注视掉,或者删除即可

MYSQL_SERVER localhost

MYSQL_USERNAME extmail

MYSQL_PASSWORD extmail

MYSQL_SOCKET /var/lib/mysql/mysql.sock

MYSQL_PORT 3306

MYSQL_DATABASE extmail

MYSQL_USER_TABLE mailbox

MYSQL_CRYPT_PWFIELD password

DEFAULT_DOMAIN test.com

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)

3、 courier-authlib 添加服务启动脚本及其他

[root@localhost courier-authlib-0.66.2]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib

[root@localhost courier-authlib-0.66.2]# chmod +x /etc/init.d/courier-authlib

[root@localhost courier-authlib-0.66.2]# chkconfig --add courier-authlib

[root@localhost courier-authlib-0.66.2]# chkconfig courier-authlib on

[root@localhost courier-authlib-0.66.2]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf

[root@localhost courier-authlib-0.66.1]# ldconfig

[root@localhost courier-authlib-0.66.1]# service courier-authlib start

Starting Courier authentication services: authdaemond

4、smtp以及虚拟用户相关的设置

[root@localhost ~]# vim /usr/lib64/sasl2/smtpd.conf //文件不存在,要自己创建

pwcheck_method: authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

[root@localhost ~]# vim /etc/postfix/main.cf

##postfix支持SMTP##

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = ''

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

broken_sasl_auth_clients=yes

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_sasl_security_options = noanonymous

##postfix支持虚拟用户##

virtual_mailbox_base = /var/mailbox

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf //这里的配置文件需在后面extman

里复制过来

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_uid_maps = static:2525

virtual_gid_maps = static:2525

virtual_transport = virtual

五、安装extmail

下载包

wget http://7xivyw.com1.z0.glb.clouddn.com/extmail-1.2.tar.gz

wget http://7xivyw.com1.z0.glb.clouddn.com/extman-1.2.tar.gz

1、创建目录并解压

[root@localhost ~]# mkdir -p /var/www/extsuite

[root@localhost ~]# tar xf extmail-1.2.tar.gz -C /var/www/extsuite/

[root@localhost ~]# mv /var/www/extsuite/extmail-1.2/ /var/www/extsuite/extmail

2、更改extmail的配置文件

[root@localhost ~]# cd /var/www/extsuite/extmail

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

[root@localhost extmail]# vim webmail.cf

SYS_SESS_DIR = /tmp/extmail

SYS_UPLOAD_TMPDIR = /tmp/extmail/upload

SYS_USER_LANG = zh_CN

SYS_MIN_PASS_LEN = 8

SYS_MAILDIR_BASE = /var/mailbox

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = extmail

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock

SYS_MYSQL_TABLE = mailbox

SYS_MYSQL_ATTR_USERNAME = username

SYS_MYSQL_ATTR_DOMAIN = domain

SYS_MYSQL_ATTR_PASSWD = password

SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

3、建立临时文件目录与session目录

[root@localhost extmail]# mkdir -p /tmp/extmail/upload

[root@localhost extmail]# chown -R postfix.postfix /tmp/extmail/

六、安装extman

1、解压extman

[root@localhost ~]# tar xf extman-1.1.tar.gz -C /var/www/extsuite/

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

[root@localhost extsuite]# mv extman-1.1/ extman

2、更改extman配置文件

[root@localhost extsuite]# cd extman/

[root@localhost extman]# cp webman.cf.default webman.cf

3、更改cgi目录属主属组

[root@localhost extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/

[root@localhost extman]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/

4、导入数据库

由于数据库不能识别TYPE= MyISAM ,所以这里直接导入会出错,先编辑extmail.sql数据库文件,将TYPE=MyISAM更改为ENGINE=MyISAM

[root@localhost extman]# vim docs/extmail.sql

:% s/TYPE/ENGINE/g

导入还会报错:

[root@localhost extman]# mysql -uroot < docs/extmail.sql

ERROR 1364 (HY000) at line 31: Field 'ssl_cipher' doesn't have a default value

修改my.cnf配置文件

[root@localhost extman]# vim /etc/my.cnf

# Recommended in standard MySQL setup

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES //将这行注视掉,重启mysql,这里需要注意的是,等数据库导入成功后,这项是不可以去掉注释的,不然mysql就启动不起来了。

再次导入数据库

mysql -uroot < docs/extmail.sql

mysql -uroot < docs/init.sql

5、创建数据库用户extmail并授予权限

mysql> GRANT ALL ON extmail.* to extmail@'localhost' identified by 'extmail'; //只允许本地登录

刷新权限

FLUSH PRIVILEGES;

6、复制四-4提到的配置文件

[root@localhost ~]# cd /var/www/extsuite/extman/docs/

[root@localhost docs]# cp mysql_virtual_* /etc/postfix/

为extman创建临时目录

[root@localhost extman]# mkdir /tmp/extman

[root@localhost extman]# chown -R postfix.postfix /tmp/extman/

7、启动postfix、dovecot、saslauthd

七、测试

1、测试虚拟用户

[root@localhost courier-authlib-0.66.2]# /usr/local/courier-authlib/sbin/authtest -s login postmaster@extmail.org extmail

Authentication succeeded. //显示这个表示成功,测试时使用的是postmaster@extmail.org,因为我们导入的数据库init.sql里面自带了这个。

Authenticated: postmaster@extmail.org (uid 2525, gid 2525)

Home Directory: /var/mailbox/extmail.org/postmaster //这里需要注意/var/mailbox这个目录现在我们还没有创建,后面web访问的时候如果没有会报错,所以提前创建。

Maildir: /var/mailbox/extmail.org/postmaster/Maildir/

Quota: (none)

Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0

Cleartext Password: extmail

Options: (none)

创建 目录

[root@localhost courier-authlib-0.66.2]# mkdir /var/mailbox

[root@localhost courier-authlib-0.66.2]# chown -R postfix.postfix /var/mailbox/

不创建的话会报错

2、测试smtp发信

[root@localhost ~]# printf "postmaster@extmail.org" | openssl base64

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

[root@localhost ~]# printf "extmail" | openssl base64

ZXh0bWFpbA==

[root@localhost ~]# telnet localhost 25

Trying ::1...

telnet: connect to address ::1: Connection refused

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

220 mail.daen.com ESMTP Postfix

auth login

334 VXNlcm5hbWU6

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

334 UGFzc3dvcmQ6

ZXh0bWFpbA==

235 2.7.0 Authentication successful //成功

quit

221 2.0.0 Bye

Connection closed by foreign host.

3.启动cmdserver

[root@localhost ~]# /var/www/extsuite/extman/daemon/cmdserver -v -d

loaded ok

不启动会出现 Connection refused

八、配置Apache

1、编辑httpd.conf文件

vim httpd.conf //直接在末尾添加

NameVirtualHost *.80

Include conf/vhost_extmail.conf

2、编辑 vhost_extmail.conf

# VirtualHost for ExtMail Solution

ServerName mail.extmail.org

DocumentRoot /var/www/extsuite/extmail/html/

ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/

Alias /extmail /var/www/extsuite/extmail/html/

ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/

Alias /extman /var/www/extsuite/extman/html/

# Suexec config

SuexecUserGroup vuser vgroup

3.启动 Apache

systemctl start httpd

extman的登录账户为root@extmail.org密码为extmail123,首次使用需要先添加域,添加之后再修改域,改为可自由注册,再注册用户就可以登录发邮件了

linux7.4邮件服务器,CentOS7 基于Postfix Dovecot Extmail 搭建邮件服务器相关推荐

  1. 【验】Postfix+Dovecot+MySQL搭建邮件服务器

    网上有很多使用Postfix搭建邮件服务器的文章,但目前貌似没有看到较为完整的一篇.本例将尝试在Ubuntu系统中使用Postfix+Dovecot+MySQL搭建邮件服务器. 说到邮件服务器,网上有 ...

  2. postfix+dovecot+SSL 搭建邮件服务器

    一.配置postfix 首先,我们关闭防火墙 systemctl disable iptables 接下来我们安装postfix yum install postfix 然后我们修改下postfix的 ...

  3. LAMP+Postfix+Dovecot+Postfixadmin搭建邮件管理系统(六)

    接上期,我们部署完了Postfix服务,下面开始部署Dovecot服务. 七.部署Dovecot服务 1.下载dovecot安装包 [root@Mail ~]# wget -c https://dov ...

  4. Centos7下postfix+Dovecot+cyrus-sasl搭建个人局域网邮件服务器(测试使用)

    1.环境准备,Centos 7 机器一台(选择vsphere环境下的一台虚拟机),虚拟机进行环境配置: a):IP配置,最后能够访问Inetnet,主要能够访问yum源,也可配置可访问的局域网源: b ...

  5. LAMP+Postfix+Dovecot+Postfixadmin搭建邮件管理系统(四)

    接上期,我们已经部署完了MySQL.Apache两个服务,下面我们开始部署PHP服务. 五.部署PHP服务 1.安装PHP所必须的依赖包 [root@Mail ~]# yum -y install g ...

  6. 基于Docker和Golang搭建Web服务器

    1 场景描述 基于centos7的docker镜像搭建golang开发环境 在docker容器内,使用golang实现一个Web服务器 启动docker容器,并在容器内启动Web服务器 我购买了一个最 ...

  7. arm Linux 低成本方案,参赛作品《低成本基于ARM+Linux平台搭建web服务器的物联网学习板》...

    [报名阶段需要填写的内容] 1. 参赛者姓名(必填项): 王徕泽 2. 单位或学校名称(选填项): 徕泽电子工作室 3. 当前职务或职称(选填项): 室长 4. 参赛作品的名字(必填项): 低成本基于 ...

  8. 基于ARM开发板搭建物联网服务器

    基于ARM开发板搭建物联网服务器 一.项目需求 1.1设备需求 1.2知识需求 1.3项目介绍 二.开发环境搭建 2.1阿里云服务器配置 2.2虚拟机交叉编译环境搭建 2.3下载相关应用压缩文件 三. ...

  9. 打造企业级应用--邮件服务器postfix+dovecot+extmail

    最近一直忙着找工作,很久没有写博客了,这不最近老大说为公司建个邮件服务器吧,统一一下同事们的邮箱,笔者第一反应就是:postfix+mysql+extmail 解决方案,解决方案有了咱就开始着手干吧~ ...

  10. 虚拟机安装postfix服务器,CentOS 7 下搭建邮件服务器(bind+postfix+dovecot)

    CentOS 7下搭建邮件服务器 前提环境:CentOS 7虚拟机IP为192.168.43.124 主机名为mail.zxp.com 修改主机名:hostnamectl set-hostname m ...

最新文章

  1. spark_updateStateByKey
  2. 亚里士多德千年前的猜想,被这群MIT本科生向前推进了一步
  3. 6 个“吓人”的 Linux 命令
  4. J20170524-hm
  5. C语言二级指针内存模型建立
  6. boot spring test 文档_SpringBoot入门建站全系列(五)使用Spring-data-jpa操作数据库
  7. 【转】HTML5第一人称射击游戏发布
  8. cad缩放工具怎么用_小米电视怎么投屏?这个投屏工具真的太好用啦!
  9. java数据存在ie中_[Java教程]解决在IE中获取数据的缓存问题,运行环境为node.js
  10. 二级MYSQL的语法整理_MySQL 常用命令及语法整理
  11. 2. jQuery 语法
  12. linux iphone 存储空间,iOS 11 将会自动删除低使用率 App来释放 iPhone 存储空间
  13. 如何去除小程序button的边框
  14. 使用python实现简单网页图片抓取
  15. 临别给《生活大爆炸》做个台词数据分析,你猜谢耳朵最爱说什么?
  16. 苹果手机怎么在照片上添加文字_手机美图秀秀怎么给图片添加文字
  17. android 个人云存储,个人云储存appv1.3
  18. 华为5G CPE是做什么用的?
  19. JDBC中executeQuery、executeUpdate和execute之间的区别
  20. 腾讯后端面试题python_python技术面试题(十九)--腾讯

热门文章

  1. 企业oa系统是什么,有什么好用的办公软件推荐?
  2. python程序设计课程设计二级减速器_机械设计课程设计(二级减速器)-二级齿轮减速器课程设计...
  3. Nmap扫描工具介绍
  4. python 将webp的图片格式转换为jpg格式
  5. AutoJS4.1.0实战教程---一键签到
  6. Windows游戏加速外挂-变速齿轮 学习笔记-【第一篇】
  7. 河南计算机职称不考了,河南省评定中级工程师职称是否还要求计算机应用能..._职称英语考试_帮考网...
  8. 【无人机】【2011.04】【含源码】四旋翼无人机的仿真与控制
  9. STM32内部FLASH介绍
  10. 联想G480改装固态硬盘、光驱变机械硬盘以及装系统(上)