小编:前几天给大家给大家介绍了基于虚拟账号的邮件系统(rpm篇),这几天做了我的第一个实训小项目,正好用到了源码环境下虚拟账号的邮件互发.今天给大家把我搭建邮件服务器的过程详细说下,希望能给大家一些启发,自己也可以没事练一下,也许会有用哦!!!
系统环境
Red Hat Enterprise Linux Server release 5.4
内核版本(2.6.18-164.e15)
基本环境
源码搭建LAMP【Linux+Apache+MySQL+PHP(可选)】
参考博客:http://tywangpanpan.blog.51cto.com/6264315/1177325
准备工作
下载Postfix最新源码包:http://www.postfix.org/
(postfix-2.10.0.tar.gz)
下载Extmail最新源码包:http://www.extmail.org/
(extmail-1.2.tar.gz)
下载Extman最新源码包:http://wiki.extmail.org/extman/
(extman-1.1.tar.gz)
下载Courier-Authlib最新源码包:http://www.courier-mta.org/authlib/
(courier-authlib-0.62.4.tar)
下载Unix-Syslog最新源码包:http://search.cpan.org/dist/Unix-Syslog/
(Unix-Syslog-1.1.tar.gz)
项目模拟拓扑图
项目说明
①模拟北京总公司、上海(分公司)、广州(分公司)之间邮件互发.
②由于只是对Mail邮件服务器的跨区域转发进行测试,为了不涉及设备的描述,本次测试用Linux模拟ISP环境,使用三块网卡,分别配置地址,作为3个地区内网服务器网关参数,进行测试.
模拟ISP环境的Router参数配置
网卡参数设定(作为邮件服务器网关参数)
开启路由器ipv4路由转发功能,并查看路由表.
服务器环境配置详述
一、北京区域
1.基本网络参数配置.
依据项目拓扑修改网络参数.
修改服务器主机名.
配置本地yum源.
2 .DNS服务器.
本地yum安装DNS服务器需要的软件包.
yum install bind bind-chroot caching-nameserver
进行DNS相关配置
为了实现邮件转发中继加速,需要配置反向解析区域.
DNS解析测试
正向
反向
3.虚拟账号Mail服务器(Postfix+Dovecot+Extmail+Extman)
yum安装实现虚拟邮件系统需要的rpm软件包
yum install mysql mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
关闭SendMail邮件服务器,并修改其开机启动级别.
service sendmail stop
chkconfig sendmail off
启动saslauthd认证服务,并修改其开机启动级别.
service saslauthdstart
chkconfig saslauthd on
源码安装postfix发送邮件服务器.
groupadd -g 2525 postfix
useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
groupadd -g 2526 postdrop
useradd -g postdrop -u 2526 -s /bin/nologin -M postdrop
tar zxvf postfix-2.10.0.tar.gz
cd postfix-2.6.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/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
make && make install
生成别名2进制文件,提高postfix的运行效率.
newaliases
进行postfix的相关配置.
vim /etc/postfix/main.cf
为postfix开启基于rycus-sasl认证功能.
vim /etc/postfix/main.cf
源码安装Courier Authentication Library(链接数据库的库文件)
tar xvf courier-authlib-0.62.4.tar -C /usr/local/src/
cd /usr/local/src/courier-authlib-0.62.4
./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
make && make install
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/authmysqlrc
拷贝生成courier-authlib服务启动脚本,并修改权限为可执行开机启动级别.
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
service courier-authlib start (启动服务)
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
mkdir -pv /var/mailbox
chown �CR postfix /var/mailbox
编辑postfix的主配置文件,添加虚拟域和虚拟用户参数.
使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库.
mkdir -pv /var/www/extsuite(注意:这个目录名字必须是这个)
tar zxvf extmail-1.2.tar.gz
mv extmail-1.2 /var/www/extsuite/extmail
tar zxvf extman-1.1.tar.gz
mv extman-1.1/var/www/extsuite/extman
cd /var/www/extsuite/extman/docs/
mysql -u root -p < extmail.sql
注意:导入extmail.sql前需要对文件进行一些字段的修改.(MySQL引擎不匹配)
下面是修改以后的效果:
USE mysql;
delete FROM user where User in ('extmail','webman');
delete FROM db where User in ('extmail','webman');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','extmail',password('extmail'),'Y','Y','Y');
INSERT INTO db (Host, Db, User, Select_priv) VALUES ('localhost','extmail','extmail','Y');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','webman',password('webman'),'Y','Y','Y');
FLUSH PRIVILEGES;
GRANT USAGE ON extmail.* TO extmail@localhost;
GRANT SELECT, UPDATE ON extmail.* TO extmail@localhost;
GRANT USAGE ON extmail.* TO webman@localhost;
GRANT SELECT, INSERT, DELETE, UPDATE ON extmail.* TO webman@localhost;
CREATE DATABASE extmail;
USE extmail;
CREATE TABLE manager (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
type varchar(64) NOT NULL default 'postmaster',
uid varchar(255) NOT NULL default '',
name varchar(255) NOT NULL default '',
question text NOT NULL ,
answer text NOT NULL ,
disablepwdchange smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (username),
KEY username (username)
);
CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (address),
KEY address (address)
);
CREATE TABLE domain (
domain varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
hashdirpath varchar(255) NOT NULL default '',
maxalias int(10) NOT NULL default '0',
maxusers int(10) NOT NULL default '0',
maxquota varchar(16) NOT NULL default '0',
maxnetdiskquota varchar(16) NOT NULL default '0',
transport varchar(255) default NULL,
can_signup tinyint(1) NOT NULL default '0',
default_quota varchar(255) default NULL,
default_netdiskquota varchar(255) default NULL,
default_expire varchar(12) default NULL,
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (domain),
KEY domain (domain)
);
CREATE TABLE domain_manager (
username varchar(255) NOT NULL default '',
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
KEY username (username)
) ;
CREATE TABLE mailbox (
username varchar(255) NOT NULL default '',
uid varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
clearpwd varchar(128) NOT NULL default '',
name varchar(255) NOT NULL default '',
mailhost varchar(255) NOT NULL default '',
maildir varchar(255) NOT NULL default '',
homedir varchar(255) NOT NULL default '',
quota varchar(16) NOT NULL default '0',
netdiskquota varchar(16) NOT NULL default '0',
domain varchar(255) NOT NULL default '',
uidnumber int(6) NOT NULL default '1000',
gidnumber int(6) NOT NULL default '1000',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active smallint(1) NOT NULL default '1',
disablepwdchange smallint(1),
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
question text NOT NULL ,
answer text NOT NULL ,
PRIMARY KEY (username),
KEY username (username)
) ;
向MySQL数据库导入初始化文件init.sql脚本.
mysql -u root -p < init.sql
导入成功后的验证:
授予用户extmail访问extmail数据库的权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql>FLUSH PRIVILEGES; 让设置的内容生效
mysql>\q
cp mysql_virtual_* /etc/postfix/
启动Postfix服务,并修改开机启动级别.
service postfix start
chkconfig postfix on
配置邮件接收服务器Dovecot.
vim /etc/dovecot.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
……
auth default {
mechanisms = plain
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
……
把userdb的其他相关禁用
编辑dovecot链接数据库的配置文件.
启动dovecot服务,并修改开机启动级别.
service dovecot start
chkconfig dovecot on
配置Extmail
拷贝生成Extmail的主配置文件,并编辑相关参数.
cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
vim /var/www/extsuite/extmail/webmail.cf
修改如下:
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_TABLE = mailbox
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
编辑Apache的配置文件,添加物理目录.
源码安装Unix-Syslog解决依赖关系.
tar zxvf Unix-Syslog-1.1.tar.gz -C /usr/local/src/
cd /usr/local/src/Unix-Syslog-1.1
perl Makefile.PL
make && make install
配置Extman
拷贝生成Extman的主配置文件,并配置相关参数.
cd /var/www/extsuite/extman/
cp webman.cf.default webman.cf
vim webman.cf
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extman/cgi/
创建其运行时所需的临时目录,并修改其相应的权限.
mkdir -pv /tmp/extman
chown postfix.postfix /tmp/extman
浏览器登陆测试(后台管理账号:[email protected] 密码:extmail*123*)
http://10.1.1.100/
二、上海区域
1.基本网络参数配置
依据项目拓扑修改网络参数.
修改服务器主机名.
配置本地yum源.
2.DNS服务器
本地yum安装DNS服务器需要的软件包.
yum install bind bind-chroot caching-nameserver
进行DNS相关配置
为了实现邮件转发中继加速,需要配置反向解析区域.
DNS解析测试
正向
反向
3.Mail服务器(Postfix+Dovecot+Extmail+Extman基于虚拟账号)
yum安装实现虚拟邮件系统需要的rpm软件包
yum install mysql mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
关闭SendMail邮件服务器,并修改其开机启动级别.
service sendmail stop
chkconfig sendmail off
启动saslauthd认证服务,并修改其开机启动级别.
service saslauthdstart
chkconfig saslauthd on
源码安装postfix发送邮件服务器.
groupadd -g 2525 postfix
useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
groupadd -g 2526 postdrop
useradd -g postdrop -u 2526 -s /bin/nologin -M postdrop
tar zxvf postfix-2.10.0.tar.gz
cd postfix-2.6.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/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
make && make install
生成别名2进制文件,提高postfix的运行效率.
newaliases
进行postfix的相关配置.
vim /etc/postfix/main.cf
为postfix开启基于rycus-sasl认证功能.
vim /etc/postfix/main.cf
源码安装Courier Authentication Library(链接数据库的库文件)
tar xvf courier-authlib-0.62.4.tar -C /usr/local/src/
cd /usr/local/src/courier-authlib-0.62.4
./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
make && make install
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/authmysqlrc
拷贝生成courier-authlib服务启动脚本,并修改权限为可执行开机启动级别.
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
service courier-authlib start (启动服务)
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
mkdir -pv /var/mailbox
chown �CR postfix /var/mailbox
编辑postfix的主配置文件,添加虚拟域和虚拟用户参数.
使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库.
mkdir -pv /var/www/extsuite(注意:这个目录名字必须是这个)
tar zxvf extmail-1.2.tar.gz
mv extmail-1.2 /var/www/extsuite/extmail
tar zxvf extman-1.1.tar.gz
mv extman-1.1/var/www/extsuite/extman
cd /var/www/extsuite/extman/docs/
mysql -u root -p < extmail.sql
注意:导入extmail.sql前需要对文件进行一些字段的修改.(MySQL引擎不匹配)
下面是修改以后的效果:
USE mysql;
delete FROM user where User in ('extmail','webman');
delete FROM db where User in ('extmail','webman');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','extmail',password('extmail'),'Y','Y','Y');
INSERT INTO db (Host, Db, User, Select_priv) VALUES ('localhost','extmail','extmail','Y');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','webman',password('webman'),'Y','Y','Y');
FLUSH PRIVILEGES;
GRANT USAGE ON extmail.* TO extmail@localhost;
GRANT SELECT, UPDATE ON extmail.* TO extmail@localhost;
GRANT USAGE ON extmail.* TO webman@localhost;
GRANT SELECT, INSERT, DELETE, UPDATE ON extmail.* TO webman@localhost;
CREATE DATABASE extmail;
USE extmail;
CREATE TABLE manager (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
type varchar(64) NOT NULL default 'postmaster',
uid varchar(255) NOT NULL default '',
name varchar(255) NOT NULL default '',
question text NOT NULL ,
answer text NOT NULL ,
disablepwdchange smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (username),
KEY username (username)
);
CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (address),
KEY address (address)
);
CREATE TABLE domain (
domain varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
hashdirpath varchar(255) NOT NULL default '',
maxalias int(10) NOT NULL default '0',
maxusers int(10) NOT NULL default '0',
maxquota varchar(16) NOT NULL default '0',
maxnetdiskquota varchar(16) NOT NULL default '0',
transport varchar(255) default NULL,
can_signup tinyint(1) NOT NULL default '0',
default_quota varchar(255) default NULL,
default_netdiskquota varchar(255) default NULL,
default_expire varchar(12) default NULL,
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (domain),
KEY domain (domain)
);
CREATE TABLE domain_manager (
username varchar(255) NOT NULL default '',
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
KEY username (username)
) ;
CREATE TABLE mailbox (
username varchar(255) NOT NULL default '',
uid varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
clearpwd varchar(128) NOT NULL default '',
name varchar(255) NOT NULL default '',
mailhost varchar(255) NOT NULL default '',
maildir varchar(255) NOT NULL default '',
homedir varchar(255) NOT NULL default '',
quota varchar(16) NOT NULL default '0',
netdiskquota varchar(16) NOT NULL default '0',
domain varchar(255) NOT NULL default '',
uidnumber int(6) NOT NULL default '1000',
gidnumber int(6) NOT NULL default '1000',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active smallint(1) NOT NULL default '1',
disablepwdchange smallint(1),
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
question text NOT NULL ,
answer text NOT NULL ,
PRIMARY KEY (username),
KEY username (username)
) ;
向MySQL数据库导入初始化文件init.sql脚本.
mysql -u root -p < init.sql
导入成功后的验证:
授予用户extmail访问extmail数据库的权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql>FLUSH PRIVILEGES; 让设置的内容生效
mysql>\q
cp mysql_virtual_* /etc/postfix/
启动Postfix服务,并修改开机启动级别.
service postfix start
chkconfig postfix on
配置邮件接收服务器Dovecot.
vim /etc/dovecot.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
……
auth default {
mechanisms = plain
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
……
把userdb的其他相关禁用
编辑dovecot链接数据库的配置文件.
启动dovecot服务,并修改开机启动级别.
service dovecot start
chkconfig dovecot on
配置Extmail
拷贝生成Extmail的主配置文件,并编辑相关参数.
cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
vim /var/www/extsuite/extmail/webmail.cf
修改如下:
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_TABLE = mailbox
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
编辑Apache的配置文件,添加物理目录.
源码安装Unix-Syslog解决依赖关系.
tar zxvf Unix-Syslog-1.1.tar.gz -C /usr/local/src/
cd /usr/local/src/Unix-Syslog-1.1
perl Makefile.PL
make && make install
配置Extman
拷贝生成Extman的主配置文件,并配置相关参数.
cd /var/www/extsuite/extman/
cp webman.cf.default webman.cf
vim webman.cf
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extman/cgi/
创建其运行时所需的临时目录,并修改其相应的权限.
mkdir -pv /tmp/extman
chown postfix.postfix /tmp/extman
浏览器登陆测试(后台管理账号:[email protected] 密码:extmail*123*)
http://10.2.1.100/
三、广州区域
1.基本网络参数配置.
依据项目拓扑修改网络参数.
修改服务器主机名.
配置本地yum源.
2.DNS服务器
本地yum安装DNS服务器需要的软件包.
yum install bind bind-chroot caching-nameserver
进行DNS相关配置
为了实现邮件转发中继加速,需要配置反向解析区域.
DNS解析测试
正向
反向
3.Mail服务器(Postfix+Dovecot+Extmail+Extman基于虚拟账号)
yum安装实现虚拟邮件系统需要的rpm软件包
yum install mysql mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
关闭SendMail邮件服务器,并修改其开机启动级别.
service sendmail stop
chkconfig sendmail off
启动saslauthd认证服务,并修改其开机启动级别.
service saslauthdstart
chkconfig saslauthd on
源码安装postfix发送邮件服务器.
groupadd -g 2525 postfix
useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
groupadd -g 2526 postdrop
useradd -g postdrop -u 2526 -s /bin/nologin -M postdrop
tar zxvf postfix-2.10.0.tar.gz
cd postfix-2.6.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/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
make && make install
生成别名2进制文件,提高postfix的运行效率.
newaliases
进行postfix的相关配置.
vim /etc/postfix/main.cf
为postfix开启基于rycus-sasl认证功能.
vim /etc/postfix/main.cf
源码安装Courier Authentication Library(链接数据库的库文件)
tar xvf courier-authlib-0.62.4.tar -C /usr/local/src/
cd /usr/local/src/courier-authlib-0.62.4
./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
make && make install
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/authmysqlrc
拷贝生成courier-authlib服务启动脚本,并修改权限为可执行开机启动级别.
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
service courier-authlib start (启动服务)
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
mkdir -pv /var/mailbox
chown �CR postfix /var/mailbox
编辑postfix的主配置文件,添加虚拟域和虚拟用户参数.
使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库.
mkdir -pv /var/www/extsuite(注意:这个目录名字必须是这个)
tar zxvf extmail-1.2.tar.gz
mv extmail-1.2 /var/www/extsuite/extmail
tar zxvf extman-1.1.tar.gz
mv extman-1.1/var/www/extsuite/extman
cd /var/www/extsuite/extman/docs/
mysql -u root -p < extmail.sql
注意:导入extmail.sql前需要对文件进行一些字段的修改.(MySQL引擎不匹配)
下面是修改以后的效果:
USE mysql;
delete FROM user where User in ('extmail','webman');
delete FROM db where User in ('extmail','webman');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','extmail',password('extmail'),'Y','Y','Y');
INSERT INTO db (Host, Db, User, Select_priv) VALUES ('localhost','extmail','extmail','Y');
INSERT INTO user (Host, User, Password,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','webman',password('webman'),'Y','Y','Y');
FLUSH PRIVILEGES;
GRANT USAGE ON extmail.* TO extmail@localhost;
GRANT SELECT, UPDATE ON extmail.* TO extmail@localhost;
GRANT USAGE ON extmail.* TO webman@localhost;
GRANT SELECT, INSERT, DELETE, UPDATE ON extmail.* TO webman@localhost;
CREATE DATABASE extmail;
USE extmail;
CREATE TABLE manager (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
type varchar(64) NOT NULL default 'postmaster',
uid varchar(255) NOT NULL default '',
name varchar(255) NOT NULL default '',
question text NOT NULL ,
answer text NOT NULL ,
disablepwdchange smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (username),
KEY username (username)
);
CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (address),
KEY address (address)
);
CREATE TABLE domain (
domain varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
hashdirpath varchar(255) NOT NULL default '',
maxalias int(10) NOT NULL default '0',
maxusers int(10) NOT NULL default '0',
maxquota varchar(16) NOT NULL default '0',
maxnetdiskquota varchar(16) NOT NULL default '0',
transport varchar(255) default NULL,
can_signup tinyint(1) NOT NULL default '0',
default_quota varchar(255) default NULL,
default_netdiskquota varchar(255) default NULL,
default_expire varchar(12) default NULL,
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active tinyint(1) NOT NULL default '1',
PRIMARY KEY (domain),
KEY domain (domain)
);
CREATE TABLE domain_manager (
username varchar(255) NOT NULL default '',
domain varchar(255) NOT NULL default '',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
KEY username (username)
) ;
CREATE TABLE mailbox (
username varchar(255) NOT NULL default '',
uid varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
clearpwd varchar(128) NOT NULL default '',
name varchar(255) NOT NULL default '',
mailhost varchar(255) NOT NULL default '',
maildir varchar(255) NOT NULL default '',
homedir varchar(255) NOT NULL default '',
quota varchar(16) NOT NULL default '0',
netdiskquota varchar(16) NOT NULL default '0',
domain varchar(255) NOT NULL default '',
uidnumber int(6) NOT NULL default '1000',
gidnumber int(6) NOT NULL default '1000',
createdate datetime NOT NULL default '0000-00-00 00:00:00',
expiredate DATE NOT NULL default '0000-00-00',
active smallint(1) NOT NULL default '1',
disablepwdchange smallint(1),
disablesmtpd smallint(1),
disablesmtp smallint(1),
disablewebmail smallint(1),
disablenetdisk smallint(1),
disableimap smallint(1),
disablepop3 smallint(1),
question text NOT NULL ,
answer text NOT NULL ,
PRIMARY KEY (username),
KEY username (username)
) ;
向MySQL数据库导入初始化文件init.sql脚本.
mysql -u root -p < init.sql
导入成功后的验证:
授予用户extmail访问extmail数据库的权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql>FLUSH PRIVILEGES; 让设置的内容生效
mysql>\q
cp mysql_virtual_* /etc/postfix/
启动Postfix服务,并修改开机启动级别.
service postfix start
chkconfig postfix on
配置邮件接收服务器Dovecot.
vim /etc/dovecot.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
……
auth default {
mechanisms = plain
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
……
把userdb的其他相关禁用
编辑dovecot链接数据库的配置文件.
启动dovecot服务,并修改开机启动级别.
service dovecot start
chkconfig dovecot on
配置Extmail
拷贝生成Extmail的主配置文件,并编辑相关参数.
cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
vim /var/www/extsuite/extmail/webmail.cf
修改如下:
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_TABLE = mailbox
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
编辑Apache的配置文件,添加物理目录.
源码安装Unix-Syslog解决依赖关系.
tar zxvf Unix-Syslog-1.1.tar.gz -C /usr/local/src/
cd /usr/local/src/Unix-Syslog-1.1
perl Makefile.PL
make && make install
配置Extman
拷贝生成Extman的主配置文件,并配置相关参数.
cd /var/www/extsuite/extman/
cp webman.cf.default webman.cf
vim webman.cf
修改 cgi执行文件属主为apache运行身份用户
chown -R postfix.postfix /var/www/extsuite/extman/cgi/
创建其运行时所需的临时目录,并修改其相应的权限.
mkdir -pv /tmp/extman
chown postfix.postfix /tmp/extman
浏览器登陆测试(后台管理账号:[email protected] 密码:extmail*123*)
http://10.3.1.100/
邮件互发测试
北京―>广州
广州接收邮件
广州回复北京邮件,北京接收.
上海-―>北京
上海接收北京的回信.
上海―>广州
总结分析
经过测试分析,我们实现了不同区域的邮件中继互发,简单的模拟了现实环境中的邮件应用,完成了总部与分部之间的邮件传递,还是比较实用的,在本次做的项目中也发挥了很好的效果。有兴趣的同学可以自己搭建个环境测试一下效果。。。。。。。。。。。