文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>支持虚拟域名的邮件服务器

支持虚拟域名的邮件服务器

时间:2006-09-30  来源:novmcgrady

支持虚拟域名的邮件服务器
用到的软件列表:
1、POP3服务
  courier-authlib-0.58.tar.bz2
  courier-imap-4.1.0.tar.bz2

2、SMTP服务
  cyrus-sasl-2.1.21.tar.gz
  postfix-2.2.9.tar.gz

3、附加软件
  pam_mysql-0.7RC1.tar.gz (MySQL的PAM验证程序)
  mysql-4.0.26.tar.gz (MySQL数据库,存储域名、用户登录等信息) 注:所有软件都放在“/root/soft/mail/”目录下,所以安装相关的软件时均在该目录下进行操作,当然也可以放在“/tmp”等其它目录下。
1、安装MySQL并启动
#tar xzvf mysql-4.0.26.tar.gz
#cd mysql-4.0.26
#groupadd mysql
#useradd mysql
#./configure --prefix=/usr/local/mysql  --with-mysqld-user=mysql --enable-big-tables --with-charset=gbk --with-extra-charsets=all
#make && make install
#scripts/mysql_install_db
#cp support-files/my-large.cnf /etc/my.cnf
#ln -s /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
#/etc/init.d/mysqld start

共享MySQL的公共库文件
#echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf

#ldconfig

2、导入MySQL数据
建立postfix数据库,并建立帐号“postfix”,密码也是“postfix”。
CREATE DATABASE postfix;
GRANT ALL ON postfix.* TO postfix@localhost IDENTIFIED BY 'postfix';

use postfix;

CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
PRIMARY KEY (address)
)TYPE=MyISAM;

CREATE TABLE domain (
domain varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
PRIMARY KEY (domain)
)TYPE=MyISAM;

CREATE TABLE mailbox (
username varchar(255) NOT NULL default '',
password varchar(255) NOT NULL default '',
transport varchar(9) NOT NULL default 'virtual',
PRIMARY KEY (username)
)TYPE=MyISAM;



插入测试数据
INSERT INTO domain VALUES('mail.cnzxh.net', '...');
INSERT INTO mailbox(username, password) VALUES('[email protected]', ENCRYPT('123'));



3、安装公共库文件(若已经装好则无需安装)
#apt-get install libpam0g-dev
#apt-get install libdb4.3-dev

4、安装cyrus-sasl-2.1.21.tar.gz
#tar xzvf cyrus-sasl-2.1.21.tar.gz
#cd cyrus-sasl-2.1.21
#./configure --prefix=/usr/local/sasl2 --with-mysql=/usr/local/mysql --enable-sql --enable-plain --enable-login --with-saslauthd=/var/run --with-pam
#make && make install
#ln -sf /usr/local/sasl2/lib/* /usr/lib/

5、安装pam_mysql-0.7RC1.tar.gz
#tar xzvf pam_mysql-0.7RC1.tar.gz
#cd pam_mysql-0.7RC1
#./configure --with-mysql=/usr/local/mysql --with-cyrus-sasl2=/usr/local/sasl2
#make && make install

6、安装postfix-2.2.9.tar.gz
#tar xzvf postfix-2.2.9.tar.gz
#cd postfix-2.2.9
#make makefiles AUXLIBS="-L/usr/lib -lsasl2 -L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm" CCARGS="-DUSE_SASL_AUTH -I/usr/local/sasl2/include/sasl -DHAS_MYSQL -I/usr/local/mysql/include/mysql"
#make && make install
(注:安装时一路回车即可)
#postalias /etc/postfix/alias
#postmap /etc/postfix/virtual

7、配置smtpd.conf及MySQL的PAM验证文件
#cat /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login

注:在sasl2的新版本中可以直接使用SQL查询,如“/usr/lib/sasl2/smtpd.conf”文件中可以写上:
sasl_pwcheck_method: auxprop
sasl_auxprop_plugin: sql
sasl_mech_list: plain login

sql_engine: mysql
sql_hostnames: localhost
sql_database: postfix
sql_user: postfix
sql_passwd: postfix
sql_select: SELECT password FROM mailbox WHERE username='%u@%r';
再删除“/usr/lib/sasl2/libotp*”即可。

#cat /etc/pam.d/smtp
auth sufficient pam_mysql.so user=postfix passwd=postfix host=localhost db=postfix table=mailbox usercolumn=username passwdcolumn=password crypt=1

auth sufficient pam_unix_auth.so

account required pam_mysql.so user=postfix passwd=postfix host=localhost db=postfix table=mailbox usercolumn=username passwdcolumn=password crypt=1

account sufficient pam_unix_acct.so

#ln -s /etc/pam.d/smtp /etc/pam.d/pop3

8、配置postfix
#cat /etc/postfix/main.cf
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = postfix.virtual.com
mydomain = virtual.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $mydomain,$myhostname
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.0.0/24, 127.0.0.0/8

alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases

header_checks = regexp:/etc/postfix/header_checks
smtpd_banner = $myhostname ESMTP $mail_name

sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq

home_mailbox = Maildir/

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:105
virtual_gid_maps = static:111
virtual_minimum_uid = 105

virtual_mailbox_base = /var/spool/mail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,reject_unauth_destination

注:其中的“105”和“110”分别是帐号“postfix”及组“postdrop”的ID号,需要根据情况自行设定。若机器里面已经存在相应的组和帐号则不必新建,否则需要新建组“postdrop”和帐号“postfix”,并记录下他们的ID号。

#cat /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address


#cat /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain


#cat /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = concat(username, '/')
where_field = username


9、启动sasl2及postfix测试smtp服务是否正常
#/usr/local/sasl2/saslauthd -r -a pam
#postfix start
#perl -MMIME::Base64 -e 'print encode_base64("web\@mail.cnzxh.net\000web\@mail.cnzxh.net\000123");'
d2ViQG1haWwuY256eGgubmV0AHdlYkBtYWlsLmNuenhoLm5ldAAxMjM=
#telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 postfix.im.ac.cn ESMTP Postfix
ehlo localhost
250-postfix.im.ac.cn
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
AUTH PLAIN d2ViQG1haWwuY256eGgubmV0AHdlYkBtYWlsLmNuenhoLm5ldAAxMjM=
235 Authentication successful
quit
221 Bye
Connection closed by foreign host.


10、安装courier-authlib-0.58.tar.bz2
#tar xjvf courier-authlib-0.58.tar.bz2
#cd courier-authlib-0.58
#./configure --prefix=/usr/local/authlib --with-mailuser=postfix --with-mailgroup=postfix --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql --with-authmysqlrc=/usr/local/authlib/etc/authmysqlrc --with-authdaemonrc=/usr/local/authlib/etc/authdaemonrc
#make && make install
#cd /usr/local/authlib/etc/
#cp authdaemonrc.dist authdaemonrc
#cp authmysqlrc.dist authmysqlrc
#vi authdaemonrc
authmodulelist="authmysql authpam"

#cat authmysqlrc
MYSQL_SERVER            localhost
MYSQL_USERNAME          postfix
MYSQL_PASSWORD          postfix
MYSQL_PORT              0
MYSQL_OPT               0
MYSQL_DATABASE          postfix
MYSQL_USER_TABLE        mailbox
MYSQL_CRYPT_PWFIELD     password
MYSQL_UID_FIELD         105
MYSQL_GID_FIELD         111
MYSQL_LOGIN_FIELD       username
MYSQL_HOME_FIELD        '/var/spool/mail/'
MYSQL_NAME_FIELD        username
MYSQL_MAILDIR_FIELD     CONCAT('/var/spool/mail/', username, '/')


11、安装ourier-imap-4.1.0.tar.bz2
#tar xjvf ourier-imap-4.1.0.tar.bz2
#cd ourier-imap-4.1.0
#./configure --prefix=/usr/local/imap --enable-unicode=utf-8,iso-8859-1,gb2312,big5 --disable-root-check --with-trashquota --without-ipv6 CPPFLAGS='-I/usr/local/authlib/include' LDFLAGS='-L/usr/local/authlib/lib/authlib -L/usr/lib' COURIERAUTHCONFIG='/usr/local/authlib/bin/courierauthconfig'
#make
#make install
#make install-configure
#cd /usr/local/imap/etc/
#vi pop3d
POP3DSTART=YES


12、测试POP3服务
#/usr/local/authlib/libexec/courier-authlib/authdaemond&
#/usr/local/imap/libexec/pop3d.rc start
#telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Hello there.
user [email protected]
+OK Password required.
pass 123
+OK logged in.
quit
+OK Bye-bye.
Connection closed by foreign host.


13、到此结束,这只是基本的安装步骤,没有太多说明。若出现了一些无法解释的错误,可以查看/var/log/mail.*或/usr/log/auth.log等日志文件,一般都可以从中找到问题的根原。
排行榜 更多 +
Office转换器

Office转换器

商务办公 下载
牛杂网

牛杂网

购物比价 下载
极上红颜

极上红颜

角色扮演 下载