在DEBIAN下搭建一台postfix+mysql+extmail+extman服务器
国庆节前,我们自行又搭建了一套简易的mail测试服务器,在此我参考过三位朋友的操作文章:
1,冯勇《在DEBIAN 下安装POSTFIX 邮件系统》出自:http://www.pc51.net/c_read13628.html
2,鸟哥《简易 Mail Server 架设 -- Postfix 设定》出自:http://www.wucity.com/vbird/linux_server/0390postfix.php
3,anstan 《postfix邮件系统》出自:http://anti-spam.org.cn/forums/index.php?showtopic=3357
4,DEBIAN参考文档 http://www.debian.org/doc/manuals/debian-reference/
现在我们开始安装:
一,安装DEBIAN
相关资料:
DEBIAN有三个发行版本:
stable:最广泛的用于架设产品化服务器,因为它只包含安全更新。
testing:推荐工作站用户使用的发行版,因为它包含有最近发布的桌面软件,这些软件已经接受了少量测试。
unstable: 处在悬崖边缘的版本,供 Debian 开发者选用。
官方文档地址:http://www.debian.org/doc/manuals/debian-reference/
安装方法:
>下载:http://www.debian.org/CD,http://www.us.debian.org,http://debian.cn99.com
>拿10G 左右的空间;或是选择自动默认安装来完成DEBIAN的安装过程;
>安装时可以输入主机名,或者编辑/etc/host.conf 修改你的主机名:例如:mail.wader.com
>更改IP
debian @mail:/#vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo eth0
iface lo inet loopback
# The primary network interface
#allow-hotplug eth0
iface eth0 inet static
address *.*.*.*
netmask 255.255.255.0
gateway *.*.*.*
>配置DNS
debian @mail:/#vi /etc/resolv.conf
search wader.com
nameserver 202.106.196.115
>更新你的软件包:
debian @mail:/#vi /etc/apt/sources.list
deb http://127.0.0.1/debian etch main -> ftp.linuxforum.net 或是 debian.cn99.com
>注:“->”在后文表示修改成的意思。
>安装SSH:
debian @mail:/#apt-get install ssh
>注:如果有命令不清楚,可以查阅以上提到的相关参考文档。
安装相关软件:
在此需要安装的软件有:
1,先下载extmail,extman
>Extmail 0.20 下载地址:http://www.extmail.org/cgi-bin/download.cgi
>Extman 0.15 下载地址:http://www.extmail.org/cgi-bin/download.cgi
>上传extmail-0[1].23-20060219.tar.gz,extman-0[1].15-20060518.tar.gz到服务器上/tmp下,
>用提升root身份,解开包
debian @mail:#cd /tmpdebian @mail:/tmp#tar zxvf extmail-0[1].23-20060219.tar.gz
debian @mail:/tmp#tar zxvf extman-0[1].15-20060518.tar.gz
debian @mail:/tmp#mv extmail-0[1].23-20060219 /usr/lib/cgi-bin/extmail
debian @mail:/tmp#mv extman-0[1].15-20060518 /usr/lib/cgi-bin/extman
>分别配置两个webmail.cf,将其中的路径全部改成你的安装路径;
debian @mail:/tmp#vi /usr/lib/cgi-bin/extmail/webmail.cf
SYS_USER_LANG=zh_CN
SYS_USER_CHRSET = gb2312
SYS_AUTH_TYPE = mysql
SYS_MAILDIR_BASE = /home/data/domains
SYS_CRYPT_TYPE = crypt
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = 127.0.0.1
SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock
>打开浏览器输入: http://yourip/extmail/即可看到extmail 的登陆窗口
>测试的用户名:test 密码:test 域:extmail.org
>修改extman下的配置文件,如果有和以上相同的配置可以参考以上配置
debian @mail:/tmp#vi /usr/lib/cgi-bin/extman/webman.cf
SYS_MIN_UID = 1001
SYS_MIN_GID = 1001
SYS_DEFAULT_UID = 1001
SYS_DEFAULT_GID = 1001
SYS_MAILDIR_BASE = /home/data/domains
SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock
>创建extman 的临时目录
mail:/var/www/cgi-bin/extman# mkdir /tmp/extman
mail:/var/www/cgi-bin/extman# chmod 777 /tmp/extman/
>创建extman 与extmail 软件包的连接(因为某些包在extmail 的目录里,所以要做链接)
mail:/var/www/cgi-bin/extman/libs/Ext# ./buildlink.sh build /var/www/cgi-bin/extmail/libs/Ext/
>打开浏览器输入http://yourip/extman/
>用户名为:root@extmail.org 密码:extmail
>注:我习惯于将名字简化,因为一会测试时也是默认目录名是extmail,extman
>等数据库安装完全之后再做登录测试。
2,安装mysql
debian @mail:#apt-get install mysql-server
>将extman 的数据导入到mysql 中;
>导入表结构:
debian @mail:#mysql -uroot <extman-0[1].15-20060518/docs/extmail.sql
>初始化测试数据:
debian @mail:#mysql -uroot <extman-0[1].15-20060518/docs/init.sql
>注:打开extman-0[1].15-20060518/docs/init.sql 将里{crypt} 这些字符串删除,否则pop3可能无法登陆。(注我没有删除,但可以通过,我没有测试)
3,安装apache 2
debian @mail:#apt-get install apache2
>修改配置
>添加用户(指操作postfix的系统级用户)
debian @mail:#useradd postfix
debian @mail:#id postfix
uid=1001(postfix) gid=1001(postfix) groups=1001(postfix)
debian @mail:#vi /etc/apache2/apache2.conf
#指定邮件系统的操作用户,因为我们的apache只提供邮件服务,所以就指定postfix用户了。行:101
User www-data -> User postfix
Group www-data -> Group postfix
#在第一个<Directory></Directory>节点后添加如下虚拟站点:
#打开目录/usr/lib/cgi-bin/extmail/cgi的索引,链接,播放视频流,执行cgi程序的功能。
<Directory "/usr/lib/cgi-bin/extmail/cgi">
Options Indexes FollowSymLinks MultiViews ExecCGI
Allow from all
</Directory>
#虚拟主机
#你的外网IP
<VirtualHost 127.0.0.1>
ServerAdmin webmaster@wader.com
DocumentRoot /usr/lib/cgi-bin/extmail/html
Alias /extmail/cgi/ /usr/lib/cgi-bin/extmail/cgi/
Alias /extmail/ /usr/lib/cgi-bin/extmail/html/
Alias /extman/cgi/ /usr/lib/cgi-bin/extman/cgi/
Alias /extman/ /usr/lib/cgi-bin/extman/html/
ServerName mail.wader.com
ErrorLog /var/log/extmail/mail.nusports.cn-error_log.log
CustomLog /var/log/extmail/mail.nusports.cn-access_log common
</VirtualHost>
#修改你的编码方式,大概在333行
AddDefaultCharset iso-8859-1 -> AddDefaultCharset GB2312
>保存配置文件后,添加两空日志文件
debian @mail:/tmp/#vi /var/log/extmail/mail.nusports.cn-error_log.log
debian @mail:/tmp/#vi /var/log/extmail/mail.nusports.cn-access_log
>重启apache
debian @mail:/tmp/#/etc/init.d/apache2 restart
Forcing reload of apache 2.0 web server....
4,安装postfix
debian @mail:/tmp/#apt-get install postfix postfix-mysql postfix-tls postfix-doc
>在弹出的对话框中选择No configuration,我们选择手动配置
>将/usr/lib/cgi-gin/extman目录下所有 mysql_virtul_*.cf 复制到/etc/postfix 目录下
debian @mail:/tmp/#cp /usr/lib/cgi-bin/extman/mysql_virtul_*.cf /etc/postfix/
>配置 /etc/postfix/main.cf,加入下面内容:可先备份一下,仔细观察
debian @mail:/tmp/#cd /etc/postfix
debian @mail:/tmp/#cp main.cf main.cf.bak
debian @mail:/tmp/#vi main.cf
##########BASE#######################
myhostname = mai.wader.com
mydomain = wader.com
mydestination = $myhostname
local_recipient_maps =
smtpd_banner = wader.com ESMTP Mail System
message_size_limit = 14680064
######################MySQL##############
#注意postfix id (uid=1001(postfix) gid=1001(postfix) groups=1001(postfix))
virtual_gid_maps=static:1001
virtual_uid_maps=static:1001
virtual_transport = virtual
virtual_alias_maps =mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_base = /home/data/domains
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
####################Quota##################
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 tray again later
virtual_overquota_bounce = yes
###############SASL#####################
smtpd_sasl_auth_enable = yes
smtpd_helo_required = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination, reject_unauth_pipelining
smtp_client_restrictions = permit_sasl_authenticated
#系统相关配置如果相同则不用修改
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mynetworks = 127.0.0.0/32
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
>保存配置
#将 /etc/postfix/目录下面以mysql_virtul_*.cf 开头的文件,将里面的hosts=localhost 改为hosts=127.0.0.1 ,否则postfix 连接mysql 会出现问题
>配置/etc/postfix/master.cf,之前的参数按如下修改,其它不变
smtp inet n - n - - smtpd
#submission inet n - - - - smtpd
# -o smtpd_enforce_tls=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#smtps inet n - - - - smtpd
#smtp inet n - n - - smtpd
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#628 inet n - - - - qmqpd
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
#qmgr fifo n - n 300 1 qmgr
qmgr fifo n - - 300 1 oqmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
smtp unix - - - - - smtp
5,安装cyrus-sasl2
debian@mail/tmp#apt-get install libsasl2 libsasl2-modules libsasl2-modules-sql
>创建/etc/postfix/sasl/smtpd.conf 加入下面的内容
debian@mail/tmp#vi /etc/postfix/sasl/smtpd.conf
pwcheck_method:authdaemond
log_level:3
password_format:crypt
mech_list:plain login
authdaemond_path:/var/run/courier/authdaemon/socket
>注意:在进行smtpd 认证测试时,maillog 提示找不到 /var/run/courier/authdaemon/socket
srwxrwxrwx 1 root root 0 2006-09-28 19:27 /var/run/courier/authdaemon/socket
6,安装courier-imap
debian @ mail/tmp# apt-get install courier-authdaemon courier-authmysql courier-base courier-imap courier-pop courier-pop-ssl courier-imap-ssl
>配置/etc/courier/authdaemonrc ,你可以先cp authdaemonrc authdemonrc.bak备份一下
debian @ mail/tmp#vi /etc/courier/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
version="authdaemond.mysql"
daemons=5
authdaemover=/var/run/courier/authdaemon
subsystem=mail
DEBUG_LOGIN=2
DEFAULTOPTIONS="wbnodsn=1"
>
>配置/etc/courier/authmysqlrc ,你可以先cp authmysqlrc authmysqlrc .bak备份一下
debian @ mail/tmp#vi /etc/courier/authmysqlrc
MYSQL_SERVER 127.0.0.1
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_DATABASE extmail
MYSQL_USER_TABLE passwd
MYSQL_USER_PWFIELD crypt
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,CONCAT('/home/data/domains/',homedir),CONCAT('/home/data/domains/',maildir),quota,name FROM mailbox WHERE username = '$(local_part)@$(domain)'
>修改authdaemond 的权限,让其它程序有权限访问他,重启authdaemond
chmod -R +x /var/run/courier/authdaemon
/etc/init.d/courier-authdaemon restart
7,测试系统
>创建测试用户的目录
debian @ mail/tmp#mkdir -p /home/data/domain/extmail.org/test
debian @ mail/tmp#/usr/bin/maildirmake /home/data/domains/extmail.org/test/Maildir
debian @ mail/tmp# chown -R 1001:1001 /home/data/domains
>打开一个窗口,输入 tail -f /var/log/mail.log
debian @ mail/tmp# perl -MMIME::Base64 -e 'print encode_base64("test\@extmail.org");'
dGVzdEBleHRtYWlsLm9yZw==
debian @ mail/tmp# perl -MMIME::Base64 -e 'print encode_base64("test");'
dGVzdA==
debian @ mail/tmp#telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 wader.com ESMTP Mail System
ehlo test
250-mai.wader.com
250-PIPELINING
250-SIZE 14680064
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
dGVzdEBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
dGVzdA==
235 2.0.0 Authentication successful
mail from:<test@wader.com>
250 2.1.0 Ok
rcpt to:<test@extmail.org>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 7185892C
quit
221 2.0.0 Bye
Connection closed by foreign host.
debian @mail/tmp#telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user test@extmail.org
+OK Password required.
pass test
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
1 413
.
retr 1
+OK 413 octets follow.
Return-Path: <test@wader.com>
X-Original-To: test@extmail.org
Delivered-To: test@extmail.org
Received: from test (localhost [127.0.0.1])
by mai.wader.com (Postfix) with ESMTP id 7185892C
for <test@extmail.org>; Sat, 30 Sep 2006 13:10:44 +0000 (UTC)
Message-Id: <20060930131111.7185892C@mai.wader.com>
Date: Sat, 30 Sep 2006 13:10:44 +0000 (UTC)
From: test@wader.com
To: undisclosed-recipients:;
test
.
>打开IE,输入你的域名比如:http://mai.wader.com/ 用户名:test 密码:test 域:extmai.org
>打开IE,输入你的域名比如:http://mai.wader.com/extman 用户名:root@extmail.org 密码:extmail
>新建域:mail.wader.com,新建用户:user,选择域:mail.wader.com,密码:user
>打开foxmail 建立新邮箱 比如:smtp服务器:mail.wader.com pop3服务器:mail.wader.com ,用户名:user@mail.wader.com,密码:user
收发成功!
至此,一个支持虚似域的邮件系统已配置完成