原邮件服务器硬盘损害,已经无法工作,需要转移到新服务器上。
原来的服务器是debian etch,新服务器是ubuntu feisty。
首先安装:
sudo aptitude install postfix postfix-mysql courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql sasl2-bin openssl libpam-mysql amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 unzoo libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax razor pyzor dcc-client
首先创建mysql数据库,因为原来已经创建,直接导入就可以了。
把原来的mysql-virtual*文件拷贝到/etc/postfix/目录下,注意若mysql用户密码发生变化,要进行相应的修改。
然后修改文件权限:
chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf
创建vmail用户:
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m
对/etc/postfix/main.cf进行修改定制:
postconf -e ‘myhostname = server1.example.com’
postconf -e ‘mydestination = server1.example.com, localhost, localhost.localdomain’
postconf -e ‘mynetworks = 127.0.0.0/8′
postconf -e ‘virtual_alias_domains =’
postconf -e ‘ virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf’
postconf -e ‘virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf’
postconf -e ‘virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf’
postconf -e ‘virtual_mailbox_base = /home/vmail’
postconf -e ‘virtual_uid_maps = static:5000′
postconf -e ‘virtual_gid_maps = static:5000′
postconf -e ‘smtpd_sasl_auth_enable = yes’
postconf -e ‘broken_sasl_auth_clients = yes’
postconf -e ‘smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination’
postconf -e ‘transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf’
postconf -e ‘content_filter = amavis:[127.0.0.1]:10024′
postconf -e ‘receive_override_options = no_address_mappings’
这部分需要具体检查,我把myorigin这个给注释掉了,对于多域名的邮件列表有影响。
saslauthd相关设置,和DEBIAN不大一样,和UBUNTU EDGY也不尽相同:
sudo rm -fdr /var/spool/postfix/var/run/saslauthd
sudo mv /var/run/saslauthd /var/spool/postfix/var/run/saslauthd
sudo ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
sudo adduser postfix sasl
修改/etc/default/saslauthd文件,把START修改为yes。
修改/etc/pam.d/smtp文件:
auth required pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1
对应的用户名密码数据库要进行替换。
修改/etc/courier/authdaemonrc文件,把authmodulelist的值变为”authmysql”。
修改/etc/init.d/postfix文件,在FILES部分:
FILES=”etc/localtime etc/services etc/resolv.conf etc/hosts \
etc/nsswitch.conf etc/nss_mdns.config etc/postfix/sasl/smtpd.conf etc/sasldb2″
这个原来是有sasldb2文件的,但是在ubuntu feisty下没有这个文件,但执行起来没有问题,比较奇怪。
修改/etc/courier/authmysqlrc文件:
MYSQL_SERVER localhost
MYSQL_USERNAME mail_admin
MYSQL_PASSWORD mail_admin_password
MYSQL_PORT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE users
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD 5000
MYSQL_GID_FIELD 5000
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD “/home/vmail”
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,’@',-1),’/',SUBSTRING_INDEX(email,’@',1),’/')
重新启动服务:
/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
修改/etc/aliases文件,可以根据自己的需要进行修改。
修改vi /etc/amavis/conf.d/15-content_filter_mode文件,去掉几个注释:
use strict;
# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.
#
# Default antivirus checking mode
# Uncomment the two lines below to enable it back
#
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
#
# Default SPAM checking mode
# Uncomment the two lines below to enable it back
#
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
1; # insure a defined return
修改 /etc/amavis/conf.d/50-user文件,添加:
$pax=’pax’;
修改/etc/postfix/master.cf文件,添加:
[...]
amavis unix – - – - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
127.0.0.1:10025 inet n – - – - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
-o smtpd_bind_address=127.0.0.1
修改/etc/spamassassin/local.cf,添加:
[...]
# dcc
use_dcc 1
dcc_path /usr/bin/dccproc
dcc_add_header 1
dcc_dccifd_path /usr/sbin/dccifd
#pyzor
use_pyzor 1
pyzor_path /usr/bin/pyzor
pyzor_add_header 1
#razor
use_razor2 1
razor_config /etc/razor/razor-agent.conf
#bayes
use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1
启动服务:
adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-daemon restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/postfix restart
参考:
http://www.howtoforge.com/virtual_postfix_mysql_quota_courier_ubuntu_edgy
http://wlx.westgis.ac.cn/322/
在sasl部分,注意还要修改/etc/default/saslauthd文件:
在最后添加:
OPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”
PIDFILE=”/var/spool/postfix/var/run/${NAME}/saslauthd.pid”
此前,因为这个问题导致不能对外发送邮件。
我看了一份文档写的是PARAMS,应该是哪个?
还有,即使加了-r这个参数,用
testsaslauthd测试的时候,如果不加上域名的话,还是认证不过。请问这是为何?结果就是pam_mysql – SELECT returned no result.
params方法我没有试验过。
加上域名?你指的是在哪儿加上域名?
我这边的运行起来都没有问题。
谢谢回答。加上域名是说用testsaslauthd的时候不能只写用户名,要用用户名@域名 的形式才能认证通过。我后来看了你的另一篇,将DAEMON_ARGS=”"改成了=“-r”立马解决问题了。不理解为何在/etc/default/saslauthd里面加OPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”无效呢?-r的参数必须加在DAEMON_ARGS才有效的么?
另外还有两个问题,想请教一下
第一个,关于邮件存储路径的问题。Vmail目录下面对每个用户都有一个目录对吧,这个目录必须手工创建么?还是说发信的时候POSTFIX会自动创建呢?
第二个,关于邮件列表的问题。这个说法未必准确,呵呵。因为我不是很清楚邮件列表的定义。总之要做的事情就是定义一个部门的邮件地址,当想给这个部门所有人发邮件的时候,给这个部门的邮件地址发信就可以。
不知道我的问题描述清楚了没有,呵呵
最后还是谢谢你。
1、因为要支持多域名,所以必须用户名必须包括域名。-r参数的原因我也不太清楚,当时好像是试验出来的,这种是通的,另外一种不通。
2、邮件存贮路径是自动创建的。
3、邮件列表,你的理解是对的。
谢谢你这么快答复。关于邮件列表的问题,请问在当前环境下(完全参照这份指南安装的),需要安装什么,如何配置才能用邮件列表呢?
请参考:
http://wlx.westgis.ac.cn/44/
http://wlx.westgis.ac.cn/tag/mailman
warning: connect to transport smtp-amavis: Connection refused
我按你的配置了,出现了,这个,我查看了配置文件,查了很多网上资料,还是不行,请指点一下,谢谢,不知可否把答案发到我的邮箱,.谢谢