最近一直在测试 postfix ,发现postfix + dovecot 配置简单不烦琐,dovecot 是后起之秀,下面就来操作,我是如何搭建的。
mai server系统 : ubuntu server 9.04
测试域名 : ludy.com
IP地址 : 192.168.6.121
测试机系统 : XP
##在自己的DNS服务器上添加
MX 映射: IN MX 10 mail.ludy.com.
mail IN A 192.168.6.121
安装步骤如下,bind9 部分你可以省略,因为我是内部测试,所以安装内部DNS。
一. 安装 DNS服务器,我安装的bind9.
shell $> apt-get install bind9
##### 修改域名解析主文件######
shell $> vim /etc/bind/named.conf.local
zone "ludy.com" {
type master;
file "/etc/bind/ludy.com";
};
type master;
file "/etc/bind/ludy.com";
};
####### 建立域名解析文件#######
shell $> vim /etc/bind/ludy.com
$TTL 86400
$ORIGIN ludy.com.
@ IN SOA ludy.com. root.ludy.com. (
2009072901 ;
68400 ;
86400 ;
3600000; ;
36000 ) ;
IN NS ns.ludy.com.
IN MX 10 mail.ludy.com.
www IN A 192.168.6.121
mail IN A 192.168.6.121
ns IN A 192.168.6.121
$ORIGIN ludy.com.
@ IN SOA ludy.com. root.ludy.com. (
2009072901 ;
68400 ;
86400 ;
3600000; ;
36000 ) ;
IN NS ns.ludy.com.
IN MX 10 mail.ludy.com.
www IN A 192.168.6.121
mail IN A 192.168.6.121
ns IN A 192.168.6.121
####重启DNS 服务器,让配置生效####
shell $> /etc/init.d/bind9 restart
shell $> /etc/init.d/bind9 restart
二.安装配置 apache+php+mysql
####我就节省时间利用apt-get来安装,如果你是高手,可以编译定制安装###
shell $> apt-get install apache2 php5 php5-mysql php5-imap php5-mcrypt php5-cli mysql-server libmysqlclient15-dev
#####在安装mysql-server 的时候会提示你配置mysql root 密码要记得#######
####添加postfix 数据库####
shell $> mysql -u root -p
###输入密码###
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 58
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 58
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
###添加 postfix 数据库 ####
mysql> create database postfix;
Query OK, 1 row affected (0.00 sec)
mysql> quit
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye
三.安装配置 postfixadmin
1.下载 postfixadmin
shell $> wget -c 'http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.2.1.1/postfixadmin-2.2.1.1.tar.gz?use_mirror=jaist'
2. 安装配置postfixadmin
shell $> tar zxvf postfixadmin-2.2.1.1.tar.gz
shell $> mv postfixadmin-2.2.1.1 /var/www/postfixadmin
shell $> cd /var/www/postfixadmin
shell $> vim config.inc.php
#### 查找 $CONF['configured'] = false; ###
改为
$CONF['configured'] = true;
###查找 $CONF['default_language'] = 'en'; ##
改为:
$CONF['default_language'] = 'cn';
####查找
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';
改为:
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'root';
$CONF['database_password'] = 'yourpassword';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'root';
$CONF['database_password'] = 'yourpassword';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';
3.安装 postfixadmin 数据表
##### 修改测试机器 DNS 为 192.168.6.121 这步我就略过了。####
##### 修改测试机器 DNS 为 192.168.6.121 这步我就略过了。####
打开浏览器输入 http://www.ludy.com/postfixadmin/setup
最后是 输入 管理员的油箱 和密码点击 Add Admin 按扭。
好,安装成功了!
###回到 maill server 服务器 ###
shell $> mv setup.php setup.php.bak
四. 安装配置 postfix
shell $> wget -c 'ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/official/postfix-2.6.3.tar.gz'
shell $> tar zxvf postfix-2.6.3.tar.gz
shell $> cd postfix-2.6.3
建立 postfix 用户
shell $> groupadd -g 1001 postfix
shell $> groupadd -g 1002 postdrop
shell $> useradd -u 1001 -g 1001 -G postfdrop -d /dev/null -s /usr/sbin/nologin postfix
shell $> make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm'
shell $> make
shell $> make install
###出现提示 一路回车就可以了 ######
shell $> cd /etc/postfix
##备份maincf主配置文件
shell $> mv main.cf main.cf.bak
### 创建新的 main.cf 配置文件
shell $> vim main.cf
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
################################################################################
myhostname = mail.ludy.com
mydomain = ludy.com
myorigin = $mydomain
mydestination =
mynetworks = 127.0.0.0/8
inet_interfaces = all
home_mailbox = Maildir/
############################################################################
virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:33
virtual_mailbox_base = /var/vmail ###虚拟用户目录
virtual_mailbox_domains = mysql:/etc/postfix/mysql/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 33 ### 给 apache 权限。
virtual_transport = virtual
virtual_uid_maps = static:33
#################################################################################
message_size_limit = 52428800
mailbox_size_limit = 209715200
virtual_mailbox_limit = 209715200
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_overquota_bounce = yes
#################################################################################
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot ###定义安装方式 dovecot
smtpd_sasl_path = private/auth-client ##### 路径要与 dovecot 一样,一会要讲到
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
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
################################################################################
myhostname = mail.ludy.com
mydomain = ludy.com
myorigin = $mydomain
mydestination =
mynetworks = 127.0.0.0/8
inet_interfaces = all
home_mailbox = Maildir/
############################################################################
virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:33
virtual_mailbox_base = /var/vmail ###虚拟用户目录
virtual_mailbox_domains = mysql:/etc/postfix/mysql/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 33 ### 给 apache 权限。
virtual_transport = virtual
virtual_uid_maps = static:33
#################################################################################
message_size_limit = 52428800
mailbox_size_limit = 209715200
virtual_mailbox_limit = 209715200
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_overquota_bounce = yes
#################################################################################
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot ###定义安装方式 dovecot
smtpd_sasl_path = private/auth-client ##### 路径要与 dovecot 一样,一会要讲到
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
###创建 mysql 通信文件
shell $> mkdir mysql
shell $> cd mysql
shell $> vim mysql_virtual_alias_maps.cf
user = root
password = yourpassword
password = yourpassword
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
shell $> vim mysql_virtual_domains_maps.cf
dbname = postfix
table = alias
select_field = goto
where_field = address
shell $> vim mysql_virtual_domains_maps.cf
user = root
password = yourpassword
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
shell $> vim mysql_virtual_mailbox_maps.cf
password = yourpassword
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
shell $> vim mysql_virtual_mailbox_maps.cf
user = root
password = yourpassword
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
shell $> vim mysql_virtual_mailbox_limit_maps.cf
password = yourpassword
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
shell $> vim mysql_virtual_mailbox_limit_maps.cf
user = root
password = yourpassword
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
password = yourpassword
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
五.安装配置 dovecot
shell $> apt-get install dovecot-pop3d
shell $> cd /etc/dovecot
shell $> mv dovecot.conf dovecot.conf.bak ##备份原有dovecot配置文件
shell $> vim dovecot.conf ## 创建新的 dovecot 配置文件
base_dir = /var/run/dovecot/
protocols = pop3 pop3s
listen = *
disable_plaintext_auth = no
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot.info
log_timestamp = "%Y-%m-%d %H:%M:%S "
ssl_disable = yes
mail_location = maildir:/var/vmail/%u
mail_privileged_group = mail
first_valid_uid = 33
protocol imap {
}
protocol pop3 {
pop3_uidl_format = %08Xu%08Xv
}
protocol managesieve {
sieve=~/.dovecot.sieve
sieve_storage=~/sieve
}
auth default {
mechanisms = plain login
passdb pam {
}
passdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
userdb passwd {
}
args = /etc/dovecot/dovecot-sql.conf
}
userdb passwd {
}
userdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
args = /etc/dovecot/dovecot-sql.conf
}
user = root
socket listen {
client {
path = /var/spool/postfix/private/auth-client ###这里对应 postfix smtpd_sasl_path
mode = 0660
user = postfix
group = postfix
}
}
}
socket listen {
client {
path = /var/spool/postfix/private/auth-client ###这里对应 postfix smtpd_sasl_path
mode = 0660
user = postfix
group = postfix
}
}
}
dict {
}
plugin {
}
shell $> mv dovecot-sql.conf dovecot-sql.conf.bak
shell $> vim dovecot-sql.conf
driver = mysql
connect = host=localhost dbname=postfix user=root password=yourpassword
default_pass_scheme = MD5-CRYPT
### 这里修改为 MD5-CRYPT 是为了与 postfixadmin 想符合,不然验证不过去总提示密码错误!
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 33 AS uid, 33 AS gid FROM mailbox WHERE username = '%u'
shell $> /etc/init.d/dovecot restart
六. 建立 postfix 虚拟用户目录
shell $> mkdir -p /var/vmail
## 赋给 apache 权限~~~
shell $> chown www-data:www-data /var/vmail -R
七,测试,其实呢测试我不想写了,因为我前边一篇文章有写,我还是写一下吧,让文章完整一些。
1.打开浏览器输入 http://www.ludy.com/postfixadmin
如图:
输入,我们刚刚建立的管理帐号和密码,点登陆。
2.登陆后,新建域名。如图:
填写完毕后点新增
3.添加完域名后,添加虚拟用户,如图:
点增加邮箱,后在添加一个用户 yang1,如图:
4.添加完毕后,打开 outlook,两个用户配置为:
一定要点上 我的服务器要求身份验证,不然不能发 email, 用用户 yang 发给 yang1一份 email测试下,如图:
点发送后,然后点 “发送/接收” 按扭。
收到了~~测试完毕!!
中途遇到什么问题,多看看dovecot,postfix 日志,和mysql 日志~