邮件服务器部署文档V1.0版本
服务器配置:centos 6.5 x86_64
所需配套环境:mysql、php
所需插件:postfix-3.0.5.tar.gz、courier-unicode-1.2.tar.bz2、courier-authlib-0.66.4.tar.bz2、extmail-1.2.tar.gz、extman-1.1.tar.gz、Unix-Syslog-1.1.tar.gz
一、 安装所需依赖包
yum install httpd gcc gcc-c++ openssl openssl-devel db4-devel ntpdatebzip2 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
二、 安装postfix
1、 卸载系统自带的postfix,删除postfix用户,重新指定uid、gid创建新用户postfix,postdro
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
2、 下载源码包并解压编译(插件里面提供有postfix源码包,略过下载,直接安装即可)
tar xf postfix-3.0.5.tar.gz
cd postfix-3.0.5
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'
注意:此处中引入的mysql和sasl需要查看具体路径,如果路径不一致,需要更换
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:postfix /var/spool/postfix/
chown root:root /var/spool/postfix
chown root:root /var/spool/postfix/pid
chown postfix:postdrop /var/spool/postfix/public
chown postfix:postdrop /var/spool/postfix/maildrop
4、 修改postfix的配置文件
vim /etc/postfix/main.cf
myhostname = mail.4399om.com //邮箱服务器地址
mydomain = 4399om.com //指定域名
myorigin = $mydomain //指明发件人所在的域名
inet_interfaces = all //all指定postfix系统监听的网络接口
mydestination = $myhostname,localhost.$mydomain,localhost //指定postfix接收邮件时收件人的域名 [使用虚拟域需要禁用]
mynetworks = 172.16.1.0/24, 127.0.0.0/8 //指定信任的客户端
alias_maps = hash:/etc/aliases //设置邮件的别名
local_recipient_maps= //取消改行注释,=后不填写内容,如果不设置extmail在测试发信的时候会失败,这个一定要注意设置
在文件最后增加如下配置:
##限制邮件附件大小####
message_size_limit = 5242880 //这里是5*1024*1024(5M)
##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
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
讲postfix 加入到service启动项
cp/etc/init.d/dovecot postfix
参照dovecot修改为postfix自己的启动脚本(参照网上)
chmod +x/ect/init.d/postfix
chkconfig –addpostfix
chkconfig postfix on
三、 安装dovecot
1、 dovecot采用yum安装即可
yum install -y dovecot dovecot-mysql
2、 配置dovecot
cd /etc/dovecot/
vim dovecot.conf
protocols = imap pop3
!include conf.d/*.conf
listen = *
mail_location = maildir:/var/mailbox/%d/%n/Maildir
mail_privileged_group = mail
cd conf.d/
vim 10-auth.conf
disable_plaintext_auth = no
vim 10-ssl.conf
ssl = no
cp auth-sql.conf.ext auth-sql.conf
vim auth-sql.conf
passdb {
driver = sql
args = /etc/dovecot/dovecot-mysql.conf}
userdb {
driver = sql
args = /etc/dovecot/dovecot-mysql.conf}
3、 编辑dovecot通过mysql认证的配置文件
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、 先安装courier-unicode
tar xf courier-unicode-1.2.tar.bz2
cd courier-unicode-1.2
./configure
make && make install
2、 再安装courier-authlib
tar xfcourier-authlib-0.66.4.tar.bz2
cd courier-authlib-0.66.4.tar.bz2
./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
注意:配置项中mysql需要根据实际路径修改.
make && make install
3、 配置courier-authlib
chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
cp /etc/authdaemonrc.dist /etc/authdaemonrc
cp /etc/authmysqlrc.dist /etc/authmysqlrc
vim /etc/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
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 4399om.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)
4、 courier-authlib添加服务启动脚本及其他
cd courier-authlib-0.66.2
cp courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod +x /etc/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig courier-authlib on
echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
ldconfig
service courier-authlib start
注意:启动成功后应该显示,错误需要检查配置
Starting Courier authentication services: authdaemond
5、
smtp
以及虚拟用户相关的设置
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
五、 安装extmail
1、 创建目录并解压
mkdir -p /var/www/html/extsuite
tar xf extmail-1.2.tar.gz -C /var/www/html/extsuite/
mv /var/www/html/extsuite/extmail-1.2/ /var/www/html/extsuite/extmail
2、 更改extmail的配置文件
cd /var/www/html/extsuite/extmail
cp webmail.cf.default webmail.cf
vim webmail.cf
SYS_CONFIG= /var/www/html/extsuite/extmail
SYS_LANGDIR= /var/www/html/extsuite/extmail/lang
SYS_TEMPDIR= /var/www/html/extsuite/extmail/html
SYS_SESS_DIR = /tmp
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
SYS_MESSAGE_SIZE_LIMIT= 5242880 //和postfix的配置/ect/postfix/mail.cf的message_size_limit对应
3、 建立临时文件目录与session目录
mkdir -p /tmp/extmail/upload
chown -R postfix.postfix /tmp/extmail/
六、 安装extman
1、 解压extman
tar xf extman-1.1.tar.gz -C /var/www/html/extsuite/
cd /var/www/html/extsuite/
mv extman-1.1/ extman
cd extman/
cp webman.cf.default webman.cf
vimwebman.cf
SYS_CONFIG= /var/www/html/extsuite/extman
SYS_LANGDIR= /var/www/html/extsuite/extman/lang
SYS_MAILDIR= /var/mailbox
SYS_SESS_DIR= /tmp
SYS_CAPTCHA_ON= 0
SYS_DEFAULT_UID= 2525 //postfix的用户id
SYS_DEFAULT_GID= 2525 //postfix的组id
mkdir–p /tmp/extman
chown–R postfix:postfix /tmp/extman
2、 更改cgi目录属主属组
chown -R postfix.postfix /var/www/extsuite/extman/cgi/
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
执行如下命令:
/var/www/html/extsuite/extman/daemon/cmdserver–d
目的是为了extman管理系统系统信息页面显示正常
七、 导入数据库
cd extman/
mysql -uroot < docs/extmail.sql
mysql -uroot < docs/init.sql
注意:mysql需要启动并且能正常登陆,切换成自己mysql对应的登陆角色操作
进入mysql操作页面,增加相应账号和权限
GRANT ALL ON extmail.* to extmail@'%' identified by 'extmail';
FLUSH PRIVILEGES;
cd /var/www/html/extsuite/extman/docs/
cp mysql_virtual_* /etc/postfix/
mkdir /tmp/extman
chown-R postfix.postfix /tmp/extman/
mkdir /var/mailbox
chown -R postfix.postfix /var/mailbox/
八、 启动相应服务
postfix start
service dovecot start
service saslauthd start
注意:保证服务启动成功,错误需要检查配置
九、 测试
1、测试虚拟用户
/usr/local/courier-authlib/sbin/authtest -s login [email protected] extmail
出现如下内容表示启动成功
Authentication succeeded. //页面出现有这个表示启动成功,后面还有内容,此处省略
2、测试smtp发信
printf "[email protected]" | openssl base64
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
printf "extmail" | openssl base64
ZXh0bWFpbA==
telnet localhost 25
在出现界面输入
auth login //(回车)
然后输入加密的账号
cG9zdG1hc3RlckBleHRtYWlsLm9yZw== //(回车)
ZXh0bWFpbA== //(回车)
出现235 2.7.0 Authentication successful //
表示成功
十、 配置httpd服务
vi/etc/httdp/conf/httdp.conf
User postfix
Group postfix
Listen 8080
配置文件最后增加
Includevhost-conf.d/*.conf
mkdir/etc/httdp/vhost-conf.d
vimvhost-name.conf
ServerName mail.4399om.com
DocumentRoot /var/www/html/extsuite
ScriptAlias /extmail/cgi/var/www/html/extsuite/extmail/cgi
Alias /extmail/var/www/html/extsuite/extmail/html
ScriptAlias /extman/cgi/var/www/html/extsuite/extman/cgi
Alias /extman /var/www/html/extsuite/extman/html
ErrorLog logs/apache_error.log
CustomLog logs/apache_access.log
chown–R postfix:postfix /etc/httpd
启动httpd
servicehttpd start
十一、 安装Unix-Syslog
tar xfUnix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL
make && make install
执行setenforce 0 //为了防止foxmail链接报错
十二、 访问web
首先需要停止防火墙:serviceiptables stop
在web输入http:ip:8080/extman访问邮件管理系统,初始化用户名为[email protected],密码为extmail*123*