centos下Extmail的搭建
本帖最后由 sky 于 2014-7-4 10:24 编辑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 安装相关软件包
# yum --disablerepo=\* --enablerepo=c6-media install httpd mysqlmysql-servermysql-developenssl-develdovecotperl-DBD-MySQLtcltcl-devellibart_lgpllibart_lgpl-devel libtool-ltdllibtool-ltdl-develexpect
安装开发工具包
# yum --disablerepo=\* --enablerepo=c6-media grouplist 查看
"Development Libraries""Development Tools""Server Platform Development"
3.2 启动httpdmysqld服务# service httpd start
# service mysqld restart
# chkconfig httpd on
# chkconfig mysqld on 设置开机启动
# netstat -tupln |grep httpd
# netstat -tupln |grep mysqld
# mysqladmin -u root -p password '123'为数据库设置密码
3.3 安装Postfix(1)删除原有postfix 新建用户
# rpm -qapostfix查看已安装postfix
postfix-2.6.6-2.2.el6_1.i686
# yum --disablerepo=\* --enablerepo=c6-media remove postfix 卸载postfix
# rpm -qapostfix 删除用户和组
# groupdel postfix
# rm -rf /var/spool/postfix 删除用户目录
# groupadd -g 2525 postfix 创建用户组
# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
# groupdel postdrop
# groupadd -g 2526 postdrop
# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
查看/etc/passwd/
(2)安装postfix
# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/
# cd postfix-2.8.2/
已有makefile文件,不需要./configure
# 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
make && make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] /
tempdir: /tmp
config_directory: /etc/postfix
daemon_directory:
command_directory:
queue_directory:
sendmail_path:
newaliases_path:
mailq_path:
mail_owner:
setgid_group:
html_directory: /var/www/postfix_html
manpages:
readme_directory:
(4)postfix的启动
# newaliases 生成别名二进制文件步骤如果忽略,会造成postfix效率低
创建临时目录,把光盘上的postfix rpm软件包拷到临时目录下,这个包里面有postfix的控制脚本
# cp /media/cdrom/Packages/postfix-2.6.6-2.2.el6_1.i686.rpm/tmp/abc/
# cd /tmp/abc/
# rpm2cpio postfix-2.6.6-2.2.el6_1.i686.rpm |cpio -id拆解rpm包
# cp -p postfix /etc/init.d/
# service postfix start
# tail -f /var/log/maillog 查看日志
warning: not owned by postfix: /var/lib/postfix/./master.lock 文件无所有者
# chown -R postfix /var/lib/postfix/ 修改权限
# chkconfig --add postfix
# chkconfig postfix on 开机自启
(5)postfix配置
#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)验证
#servicepostfix restart
错误:
# mail user1
-bash: mail: command not found
# yum install mailx安装mailx
# mail user1
Subject: 177
qqqqqccccc
. 以点结束
EOT
# tail -f /var/log/maillog查看邮件日志
也可以
# cd /var/spool/mail/
# vim user1
3.4 postfix开启基于cyrus-sasl的认证功能(1)查看已安装sasl有关的软件包
# 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 没有安装
# ll |grep sasl 查看sasl安装软件包
# yum install cyrus-sasl-plain-2.1.23-13.el6_3.1.i686.rpm
(2)postfix与sasl结合,编辑Postfix文件
# 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)验证
# service postfix restart
# 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配置
#mkdir /usr/local/lib/sasl2
# vim /usr/local/sasl2smtpd.conf
# service saslauthd start
# chkconfig --add saslauthd
# chkconfig saslauthd on
3.5安装Courier authentication library(1)解压安装
# tar -jxvf courier-authlib-0.63.0.tar.bz2-C/usr/local/src/
# cd /usr/local/src/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
# make && make install 安装
(2)配置SMTP
vim /usr/local/lib/sasl2/smtpd.conf
(3)修改配置
# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
# cp /etc/authdaemonrc.dist /etc/authdaemonrc
# cp /etc/authmysqlrc.dist/etc/authmysqlrc
# vim /etc/authdaemonrc
vim /etc/authdaemonrc
authmodulelist="authmysql" 修改
authmodulelistorig="authmysql"
daemons=10
# vim /etc/authmysqlrc
MYSQL_SERVER localhost
MYSQL_PORT 3306 (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAMEextmail (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail (密码)
MYSQL_SOCKET/var/lib/mysql/mysql.sock
MYSQL_DATABASEextmail
MYSQL_USER_TABLEmailbox
MYSQL_CRYPT_PWFIELDpassword
MYSQL_UID_FIELD'2525'
MYSQL_GID_FIELD'2525'
MYSQL_LOGIN_FIELDusername
MYSQL_HOME_FIELDconcat('/var/mailbox/',homedir)
MYSQL_NAME_FIELDname
MYSQL_MAILDIR_FIELDconcat('/var/mailbox/',maildir)
产生启动控制脚本
# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
# chmod 755 /etc/init.d/courier-authlib增加可执行权限
# chkconfig --add courier-authlib
# chkconfig --level 2345 courier-authlib on
# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
# ldconfig -v启动courier-authlib服务
# mkdir -pv /var/mailbox 新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户
# 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建立数据库:
# cd extman-1.1/docs
# cp mysql_virtual_* /etc/postfix/
//导入数据库
# mysql -u root -p <extmail.sql
# mysql -u root -p <init.sql
(3)授予用户extmail访问extmail数据库的权限
# 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;
# service postfix restart
3.6 配置dovecot(1)编辑dovecot配置文件
# cd /etc/dovecot/conf.d
vim 10-mail.conf
24mail_location = maildir:/var/mailbox/%d/%n/Maildir
# vim /etc/postfix/main.cf
415 home_mailbox = Maildir/
#mv auth-sql.conf.ext auth-sql.conf
# vim auth-sql.conf
# 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'
# service dovecot start
Starting Dovecot Imap:
# chkconfig dovecot on
3.7 安装Extmail-1.2(1)安装
# tar -zxvf extmail-1.2.tar.gz
# mkdir -pv /var/www/extsuite
mkdir: created directory `/var/www/extsuite'
# mv extmail-1.2 /var/www/extsuite/extmail
# cd /var/www/extsuite/extmail/
# cp webmail.cf.default webmail.cf
(2)修改主配置文件
#vi /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相关配置
#vim/etc/httpd/conf/httpd.conf
1010 <VirtualHost *:80>
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 </VirtualHost>
# service httpd restart 重启httpd服务
#yum install perl-CGI*
(4)依赖关系的解决
extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。
# 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服务
# service httpd start
# chkconfig httpd on
3.8安装Extman-1.1# mv extman-1.1 /var/www/extsuite/extman
# cd /var/www/extsuite/extman
# mv webman.cf.default webman.cf
# vim webman.cf
# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
# 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搭建完毕
页:
[1]