ITPub博客

首页 > Linux操作系统 > Linux操作系统 > CentOS 6.7下源码包搭建Postfix+Extmail+Dovecot

CentOS 6.7下源码包搭建Postfix+Extmail+Dovecot

Linux操作系统 作者:luashin 时间:2016-04-06 12:22:29 0 删除 编辑
1 Extmail概述
   ExtMail Solution 是一个基于优秀开源软件的电子邮件系统解决方案,核心部件包括了Postfix、Amavisd-new、ClamAV、ExtMail、ExtMan、Courier系列软件。是一个功能相对比较齐全的免费电子邮件系统。
   而其中Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件,主要包括ExtMail、Extman两个部分的程序套件。ExtMail套件用于提供从浏览器中登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。

2 Extmail工作原理

  Extmail的核心部分是postfix,是一种web页面,可以创建账号,可以收发邮件。extman可以账号注册。账号存放在mysql里面。postfix发信件,dovecot收信件。利用outlook收信件(docecot)和发信件(postfix)都要通过mysql查询。发信件(postfix)要提取mysql账号信息要通过courier-authlib。是基于虚拟帐号的邮件系统。

3 Extmail服务器搭建
3.1 安装相关软件包 
[root@Qserver ~]# yum --disablerepo=\* --enablerepo=c6-media install httpd mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect

安装开发工具包
[root@Qserver ~]# yum --disablerepo=\* --enablerepo=c6-media grouplist 查看
"Development Libraries""Development Tools""Server Platform Development"

3.2 启动httpd mysqld服务
[root@Qserver ~]# service httpd start
[root@Qserver ~]# service mysqld restart
[root@Qserver ~]# chkconfig httpd on
[root@Qserver ~]# chkconfig mysqld on 设置开机启动
[root@Qserver ~]# netstat -tupln |grep httpd
[root@Qserver ~]# netstat -tupln |grep mysqld
[root@Qserver ~]# mysqladmin -u root -p password '123' 为数据库设置密码

3.3 安装Postfix
(1)删除原有postfix 新建用户
[root@Qserver ~]# rpm -qa postfix 查看已安装postfix
postfix-2.6.6-2.2.el6_1.i686
[root@Qserver ~]# yum --disablerepo=\* --enablerepo=c6-media remove postfix 卸载postfix
[root@Qserver ~]# rpm -qa postfix 删除用户和组
[root@Qserver ~]# groupdel postfix
[root@Qserver ~]# rm -rf /var/spool/postfix 删除用户目录
[root@Qserver ~]# groupadd -g 2525 postfix 创建用户组
[root@Qserver ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[root@Qserver ~]# groupdel postdrop
[root@Qserver ~]# groupadd -g 2526 postdrop
[root@Qserver ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
查看/etc/passwd/


(2)安装postfix
[root@Qserver src]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/
[root@Qserver src]# cd postfix-2.8.2/
已有makefile文件,不需要./configure
[root@Qserver 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'
错误 :

安装 db4-devel 和gcc
[root@Qserver postfix-2.8.2]make && make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] /
tempdir: [/usr/local/src/ postfix-2.6.5] /tmp
config_directory: [/etc/postfix] /etc/postfix
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]
html_directory: [no] /var/www/postfix_html
manpages: [/usr/local/man]
readme_directory: [no]

(4)postfix的启动
[root@Qserver postfix-2.8.2]# newaliases 生成别名二进制文件步骤如果忽略,会造成postfix效率低
创建临时目录,把光盘上的postfix rpm软件包拷到临时目录下,这个包里面有postfix的控制脚本
[root@Qserver cdrom]# cp /media/cdrom/Packages/postfix-2.6.6-2.2.el6_1.i686.rpm /tmp/abc/
[root@Qserver cdrom]# cd /tmp/abc/
[root@Qserver abc]# rpm2cpio postfix-2.6.6-2.2.el6_1.i686.rpm |cpio -id 拆解rpm包

[root@Qserver init.d]# cp -p postfix /etc/init.d/
[root@Qserver init.d]# service postfix start

[root@Qserver ~]# tail -f /var/log/maillog 查看日志
warning: not owned by postfix: /var/lib/postfix/./master.lock 文件无所有者
[root@Qserver ~]# chown -R postfix /var/lib/postfix/ 修改权限
[root@Qserver ~]# chkconfig --add postfix
[root@Qserver ~]# chkconfig postfix on 开机自启

(5)postfix配置
[root@Qserver ~]# vim /etc/postfix/main.cf
75 myhostname = mail.cj.com
83 mydomain = cj.com
98 myorigin = $myhostname
99 myorigin = $mydomain
113 inet_interfaces = all
161 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
260 mynetworks = 192.168.30.0/24, 127.0.0.0/8 网络为本机网络

(6)验证
[root@Qserver ~]# service postfix restart
错误:
[root@Qserver ~]# mail user1
-bash: mail: command not found
[root@Qserver ~]# yum install mailx 安装mailx
[root@Qserver ~]# mail user1
Subject: 177
qqqqqccccc
. 以点结束
EOT

[root@Qserver ~]# tail -f /var/log/maillog 查看邮件日志

也可以
[root@Qserver ~]# cd /var/spool/mail/
[root@Qserver mail]# vim user1

3.4 postfix开启基于cyrus-sasl的认证功能
(1)查看已安装sasl有关的软件包
[root@Qserver mail]# rpm -qa |grep sasl
cyrus-sasl-lib-2.1.23-13.el6_3.1.i686
cyrus-sasl-2.1.23-13.el6_3.1.i686
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686
cyrus-sasl-plain 没有安装
[root@Qserver Packages]# ll |grep sasl 查看sasl安装软件包
[root@Qserver Packages]# yum install cyrus-sasl-plain-2.1.23-13.el6_3.1.i686.rpm

(2)postfix与sasl结合,编辑Postfix文件
[root@Qserver ~]# vim /etc/postfix/main.cf

以下是文本
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

(3)验证
[root@Qserver ~]# service postfix restart
[root@Qserver ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 Welcome to our mail.cj.com ESMTP,Warning: Version not Available!


(4)sasl配置
[root@Qserver ~]# mkdir /usr/local/lib/sasl2
[root@Qserver ~]# vim /usr/local/sasl2smtpd.conf
[root@Qserver ~]# service saslauthd start
[root@Qserver ~]# chkconfig --add saslauthd
[root@Qserver ~]# chkconfig saslauthd on

3.5安装Courier authentication library
(1)解压安装
[root@Qserver ~]# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/
[root@Qserver ~]# cd /usr/local/src/courier-authlib-0.63.0/
[root@Qserver courier-authlib-0.63.0]# 编译
./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
[root@Qserver courier-authlib-0.63.0]# make && make install 安装

(2)配置SMTP
[root@Qserver ~]# vim /usr/local/lib/sasl2/smtpd.conf


(3)修改配置
[root@Qserver ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@Qserver ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@Qserver ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[root@Qserver ~]# vim /etc/authdaemonrc
authmodulelist="authmysql" 修改
authmodulelistorig="authmysql"
daemons=10
[root@Qserver ~]# vim /etc/authmysqlrc
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_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@Qserver courier-authlib-0.63.0]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@Qserver courier-authlib-0.63.0]# chmod 755 /etc/init.d/courier-authlib 增加可执行权限
[root@Qserver courier-authlib-0.63.0]# chkconfig --add courier-authlib
[root@Qserver courier-authlib-0.63.0]# chkconfig --level 2345 courier-authlib on
[root@Qserver courier-authlib-0.63.0]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@Qserver courier-authlib-0.63.0]# ldconfig -v 启动courier-authlib服务
[root@Qserver courier-authlib-0.63.0]# mkdir -pv /var/mailbox 新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户
[root@Qserver courier-authlib-0.63.0]# chown -R postfix /var/mailbox

3.5 postfix支持虚拟域和虚拟用户
(1)编辑/etc/postfix/main.cf
##################Virtual Mailbox Settings#################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
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
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
####################QUOTA Settings######################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
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, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes

(2)使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
[root@Qserver ~]# cd extman-1.1/docs
[root@Qserver docs]# cp mysql_virtual_* /etc/postfix/
//导入数据库
[root@Qserver docs]# mysql -u root -p <extmail.sql
[root@Qserver docs]# mysql -u root -p <init.sql

(3)授予用户extmail访问extmail数据库的权限
[root@Qserver docs]# mysql -u root -p
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;
[root@Qserver docs]# service postfix restart

3.6 配置dovecot
(1)编辑dovecot配置文件
[root@Qserver ~]# cd /etc/dovecot/conf.d
24 mail_location = maildir:/var/mailbox/%d/%n/Maildir

[root@Qserver conf.d]# vim /etc/postfix/main.cf
415 home_mailbox = Maildir/
[root@Qserver conf.d]# mv auth-sql.conf.ext auth-sql.conf
[root@Qserver conf.d]# vim auth-sql.conf

[root@Qserver dovecot]# vim /etc/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail (如mysql源码安装,host=/tmp/mysql.sock)
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@Qserver dovecot]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@Qserver dovecot]# chkconfig dovecot on

3.7 安装Extmail-1.2
(1)安装
[root@Qserver ~]# tar -zxvf extmail-1.2.tar.gz
[root@Qserver ~]# mkdir -pv /var/www/extsuite
mkdir: created directory `/var/www/extsuite'
[root@Qserver ~]# mv extmail-1.2 /var/www/extsuite/extmail
[root@Qserver ~]# cd /var/www/extsuite/extmail/
[root@Qserver extmail]# cp webmail.cf.default webmail.cf

(2)修改主配置文件
#vim /var/www/extsuite/extmail/webmail.cf
部分修改选项的说明:
SYS_MESSAGE_SIZE_LIMIT = 5242880
用户可以发送的最大邮件
SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_HOST = localhost
指明数据库服务器主机名,这里默认即可
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password
以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

(3)apache相关配置
[root@Qserver extmail]# vim /etc/httpd/conf/httpd.conf

1010
1011 ServerName mail.test.com
1012 DocumentRoot /var/www/extsuite/extmail/html/
1013 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
1014 Alias /extmail /var/www/extsuite/extmail/html
1015 SuexecUserGroup postfix postfix
1016
[root@Qserver extmail]# service httpd restart 重启httpd服务
[root@Qserver extmail]#yum install perl-CGI*

(4)依赖关系的解决
extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。
[root@Qserver ~]# tar -zxvf Unix-Syslog-0.100.tar.gz -C /usr/local/src/
cd /usr/local/src/Unix-Syslog-0.100/
perl Makefile.PL
make && make install

(5)启动apache服务
[root@Qserver ~]# service httpd start
[root@Qserver ~]# chkconfig httpd on

3.8安装Extman-1.1
[root@Qserver ~]# mv extman-1.1 /var/www/extsuite/extman
[root@Qserver ~]# cd /var/www/extsuite/extman
[root@Qserver extman]# mv webman.cf.default webman.cf
[root@Qserver extman]# vim webman.cf

[root@Qserver extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
[root@Qserver extman]# vim /etc/httpd/conf/httpd.conf
加上这两行
1015 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
1016 Alias /extman /var/www/extsuite/extman/html

4 测试
(1)访问192.168.30.4


(2)进入后台管理
用户名root@extmail.org
密码extmail*123*

注册域


(3)注册邮箱uesr2@b.com 并发送邮件测试

至此 extmail搭建完毕
</init.sql<>
</extmail.sql<>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9034054/viewspace-2076052/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-02-18

  • 博文量
    290
  • 访问量
    1050269