postfix配置

更新时间:2024-05-24 13:11:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Postfix配置

测试环境:操作系统:centos5 软件:postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm cyrus-sasl-lib-2.1.22-4

cyrus-sasl-devel-2.1.22-4

cyrus-sasl-sql-2.1.22-4 cyrus-sasl-plain-2.1.22-4 cyrus-sasl-2.1.22-4

cyrus-sasl-md5-2.1.22-4 cyrus-sasl-ntlm-2.1.22-4 cyrus-sasl-gssapi-2.1.22-4 mysql-server-5.0.22-2.1

courier-authlib-mysql-0.57-1hzq mysql-bench-5.0.22-2.1

libdbi-dbd-mysql-0.8.1a-1.2.2

postfix-2.3.3-2.el5.centos.mysql_pgsql mysql-devel-5.0.22-2.1 mysql-test-5.0.22-2.1 mysql-5.0.22-2.1

mysql-connector-odbc-3.51.12-2.2 libtool-libs-1.5.6-4.EL4.1.c4.3 courier-authlib-mysql-0.57-1hzq courier-authlib-devel-0.57-1hzq courier-authlib-0.57-1hzq maildrop-2.0.1-1hzq

maildrop-man-2.0.1-1hzq mod_perl-2.0.2-6.1 perl-5.8.8-10 perl-URI-1.35-3

perl-Convert-ASN1-0.20-1.1 perl-HTML-Parser-3.55-1.fc6 perl-Net-IP-1.25-2.fc6

perl-XML-LibXML-Common-0.13-8.2.2 perl-BSD-Resource-1.28-1.fc6.1 perl-DBD-MySQL-3.0007-1.fc6 perl-LDAP-0.33-3.fc6

perl-SGMLSpm-1.03ii-16.2.1

1

perl-XML-Grove-0.46alpha-29.1.1 perl-Time-HiRes-1.72-1hzq perl-Net-Server-0.93-1hzq perl-BerkeleyDB-0.31-1.el5.rf perl-Convert-TNEF-0.17-1hzq

perl-Compress-Zlib-1.42-1.fc6 perl-DBI-1.52-1.fc6

perl-XML-NamespaceSupport-1.09-1.2.1 perl-IO-Zlib-1.04-4.2.1

perl-Digest-SHA1-2.11-1.2.1 perl-HTML-Tagset-3.10-2.1.1 perl-libwww-perl-5.805-1.1.1 perl-libxml-perl-0.08-1.2.1 perl-Net-SSLeay-1.30-4.fc6 perl-Socket6-0.19-3.fc6 perl-Archive-Tar-1.30-1.fc6 perl-Bit-Vector-6.4-2.2.2.1 perl-Crypt-SSLeay-0.51-11.el5 perl-DateManip-5.44-1.2.1 perl-DBD-Pg-1.49-1.fc6 perl-IO-String-1.08-1.1.1 perl-Net-DNS-0.59-1.fc6 perl-NKF-2.07-1.1.fc6

perl-String-CRC32-1.4-2.fc6 perl-XML-Dumper-0.81-2.fc6 perl-XML-LibXML-1.58-5 perl-XML-Twig-3.26-1.fc6 perl-IO-Multiplex-1.08-1hzq perl-Unix-Syslog-0.100-1hzq perl-MailTools-1.67-1hzq perl-Convert-BinHex-1.119-1hzq perl-MIME-Base64-3.05-1hzq perl-Convert-UUlib-1.051-1hzq perl-Carp-Clan-5.3-1.2.1 perl-XML-SAX-0.14-5 perl-Digest-HMAC-1.01-15 perl-XML-Parser-2.34-6.1.2.2.1 perl-IO-Socket-SSL-1.01-1.fc6

2

perl-Archive-Zip-1.16-1.2.1 perl-Date-Calc-5.4-1.2.2.1

perl-IO-Socket-INET6-2.51-2.fc6 perl-Net-Telnet-3.03-5 perl-suidperl-5.8.8-10 perl-XML-Simple-2.14-4.fc6 perl-IO-stringy-2.110-1hzq perl-TimeDate-1.16-1hzq perl-MIME-tools-5.418-1hzq clamav-db-0.91.2-1.el5.rf clamd-0.91.2-1.el5.rf clamav-0.91.2-1.el5.rf 以上都是用RPM安装 php-5.2.4.tar.bz2

courier-imap-4.2.1.tar.bz2 postfixadmin.tar.gz

httpd-2.2.4.tar.gz squirrelmail-1.4.11.tar.gz

slockd-0.083 #源码安装

安装:首先要安装DNS。最好通过webmin安装 接着安装postfix

rpm -ivh RPMS/ postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm

把配置文件修改成以下内容: Vi /etc/postfix/main.cf

broken_sasl_auth_clients = yes command_directory = /usr/sbin config_directory = /etc/postfix

content_filter = smtp:[127.0.0.1]:10024 #集成amavisd-new daemon_directory = /usr/libexec/postfix debug_peer_level = 2 html_directory = no inet_interfaces = all

mail_name = Postfix - by sc.com mail_owner = postfix

mailq_path = /usr/bin/mailq

3

manpage_directory = /usr/local/man message_size_limit = 14336000 mydomain = sc.com

myhostname = mail.sc.com

mynetworks = 192.168.10.0/24, 127.0.0.0/8

myorigin = $mydomain

newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix readme_directory = no

receive_override_options = no_address_mappings #receive_override_options 这里必须增加,禁止地址展开/影射,否则如果遇到别名的时候会引起冗余邮件的产生 sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail setgid_group = postdrop

smtpd_banner = $myhostname ESMTP $mail_name

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, permit, check_policy_service inet:127.0.0.1:10030 #配置postfix以使其打开对slockd的支持 smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

#SMTP验证

unknown_local_recipient_reject_code = 550 virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf virtual_gid_maps = static:1000 #maildrop创建的组ID virtual_mailbox_base = /home/domains/ virtual_mailbox_domains =

mysql:/etc/postfix/mysql/mysql_virtual_domains_maps.cf virtual_mailbox_limit = 20971520

virtual_mailbox_maps = mysql:/etc/postfix/mysql/mysql_virtual_mailbox_maps.cf #支持mysql存储虚拟用户 virtual_transport = maildrop:

virtual_uid_maps = static:1000 #maildrop创建的用户ID 创建支持虚拟用户的mysql配置文件

mkdir /etc/postfix/mysql

4

1、vi /etc/postfix/mysql/mysql_virtual_alias_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = alias select_field = goto where_field = address

2、vi /etc/postfix/mysql/mysql_virtual_domains_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = domain

select_field = description where_field = domain

#additional_conditions = and backupmx = '0' and active = '1'

3、vi /etc/postfix/mysql/mysql_virtual_mailbox_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = maildir where_field = username

#additional_conditions = and active = '1'

4、vi /etc/postfix/mysql/mysql_virtual_mailbox_limit_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = quota where_field = username

#additional_conditions = and active = '1'

5

/etc/init.d/postfix start

安装Courier-Authlib

rpm -ivh libtool-libs-1.5.6-4.EL4.1.c4.3.i386.rpm rpm -ivh courier-authlib-0.57-1hzq.i386.rpm rpm -ivh courier-authlib-devel-0.57-1hzq.i386.rpm rpm -ivh courier-authlib-mysql-0.57-1hzq.i386.rpm 修改配置文件:改成如下内容 vi /etc/authlib/authmysqlrc

MYSQL_SERVER localhost MYSQL_USERNAME postfix

MYSQL_PASSWORD postfix

MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_DATABASE postfix MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password DEFAULT_DOMAIN sc.com MYSQL_UID_FIELD '1000' MYSQL_GID_FIELD '1000' MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD '/home/domains/' MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD maildir

MYSQL_QUOTA_FIELD concat(quota,'S') MYSQL_WHERE_CLAUSE active='1'

注意:确认在这个文件中不能用空格键(包括行尾),只能用tab键。

确认只使用单引号,比如:'/home/domains/','UID','GID'(本文为'1000') localhost不能用单引号

确认你的/etc/hosts文件中有localhost 编译时如果支持Ipv6可能导致错误

MYSQL_GID_FIELD 和MYSQL_UID_FIELD是maildrop的UID和GID,而不是MySQL的

修改authdaemon socket目录权限

如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证: chmod 755 /var/spool/authdaemon/

6

启动:/etc/init.d/Courier-Authlib start

Starting Courier authentication services: authdaemond 出现这个证明安装配置成功了

chkconfig --add courier-authlib #开机启动

安装Courier-IMAP

Tar xjvf courier-imap-4.2.1.tar.bz2 cd courier-imap-4.2.1

./configure \\

--prefix=/usr/local/imap \\ --with-redhat \\ --disable-root-check \\

--enable-unicode=utf-8,iso-8859-1,gb2312,gbk,gb18030,big5 \\ --with-trashquota \\ --with-dirsync make

make install-strip (先install-strip,如果失败,再make install) make install-configure

# vi /usr/local/imap/etc/imapd IMAPDSTART=YES

让imap自启动: 返回安装目录

cp courier-imap.sysvinit /etc/rc.d/init.d/courier-imap chmod 755 /etc/rc.d/init.d/courier-imap chkconfig --add courier-imap

安装maildrop

注意事项:

1.如果您需要重新编译maildrop软件包,首先必须获得其源码rpm包,其次必须先装好courier-authlib及其devel软件包,否则编译maildrop之后将无法打开authlib支持。 2.maildrop RPM包安装时,会自动创建vuser用户及vgroup用户组,专门用于邮件的存储,vuser:vgroup的uid/gid都是1000,这与一般的邮件文档中提及用postfix用户存邮件不一样。因为postfix用户的uid一般都低于500,而Suexec模块编译时对UID/GID的要求是要大于500,

7

因此显然用postfix用户不能满足,会导致报错。其次,如果用maildrop作为投递(MDA),以postfix身份投递的话,postfix mta也会报错的。

rpm -ivh maildrop-2.0.1-1hzq.i386.rpm rpm -ivh maildrop-man-2.0.1-1hzq.i386.rpm 它会自动创建两个用户:vuser和vgroup ID为1000 配置master.cf

为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,注释掉原来的maildrop的配置内容,并改为:

maildrop unix - n n - - pipe #flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient} flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop} 配置main.cf

由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加如下参数: maildrop_destination_recipient_limit = 1

由于maildrop没有建立及删除maildir的功能,因此由脚本实现

创建文件:vi /usr/sbin/maildirmake.sh # vi /usr/sbin/maildirmake.sh #!/bin/bash set -e

if [ ! -d /home/domains/$1 ] then

mkdir /home/domains/$1 fi

chown -R vuser:vgroup /home/domains/$1 cd \

/usr/local/imap/bin/maildirmake $2 chown -R 1000:89 /home/domains/$1/$2 chmod -R g=s /home/domains/$1/$2 删除文件:vi /usr/sbin/maildirdel.sh # vi /usr/sbin/maildirdel.sh #!/bin/bash

rm -rf /home/domains/$1/$2

8

给运行权限:

chmod 755 /usr/sbin/maildirmake.sh chmod 755 /usr/sbin/maildirdel.sh chmod a+w /etc/sudoers vi /etc/sudoers

vmail ALL = NOPASSWD: /usr/sbin/maildirmake.sh , /usr/sbin/maildirdel.sh

最后重新启动postfix即可

安装apache,php

Tar xzvf httpd-2.2.4.tar.gz

Tar xjvf php-5.2.4.tar.bz2 Cd httpd-2.2.4

./configure –prefix=/usr/local/apache&&make&&make install Cd php-5.2.4

./configure –with-apxs2=/usr/local/apache/bin/apxs –with-mysql&&make&&make install

安装 postfixadmin.tar.gz

直接解压到htdocs的目录下,然后做如下配置:

# mv postfixadmin-2.1.0 /www/postfixadmin 更改权限,假定运行apache的用户和组为vmail # chown -R vuser:vgroup /www/postfixadmin # cd /www/postfixadmin # chmod 640 *.php *.css # cd /www/postfixadmin/admin/ # chmod 640 *.php .ht*

# cd /www/postfixadmin/images/ # chmod 640 *.png

# cd /www/postfixadmin/languages/ # chmod 640 *.lang

# cd /www/postfixadmin/templates/ # chmod 640 *.tpl

# cd /www/postfixadmin/users/ # chmod 640 *.php

9

建立mysql表

建立Postfix Admin所需的MySQL数据库,在建立数据库之前需要修改DATABASE_MYSQL.TXT文件,其中第27行的“Postfix user & password”应当与你安装Postfix时的MySQL用户名和密码相同,为了安全你也应当修改postfixadmin用户的密码。

# cd postfixadmin

# mysql -u root < DATABASE_MYSQL.TXT

由于我架上去之后,一直不能再domain_admins添加记录,所以只能手工添加,不然界面获取不到域名

在数据库里添加一条语句:insert into domain_admins (username,domain,created) values ('admin@sc.com','sc.com',NOW()); # cp config.inc.php.sample config.inc.php # vi config.inc.php 本例中的配置如下:

$CONF['default_language'] = 'cn'; $CONF['database_type'] = 'mysql'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfixadmin'; $CONF['database_password'] = 'postfixadmin'; $CONF['database_name'] = 'postfix'; $CONF['encrypt'] = 'md5crypt'; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO'; $CONF['quota'] = 'YES';

$CONF['quota_multiplier'] = '1024000';

邮箱的存储格式使用domain.ltd/username的形式,所以设置: $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO';

更改postfixadmin目录及postfixadmin/admin目录下的create-mailbox.php文件 在这两个文件的$tQuota = $CONF['maxquota'];行后加一行(postfixadmin/admin目录下的大概在200行):

# vi /var/www/postfixadmin/admin/create-mailbox.php

system(\# vi /var/www/postfixadmin/create-mailbox.php

system(\

10

更改postfixadmin目录及postfixadmin/admin目录下的delete.php文件 在这两个文件的$result = db_query (%username='$fDelete' AND domain='$fDomain'\行后加几行: # vi /var/www/postfixadmin/admin/delete.php $userarray=explode(\$user=$userarray[0]; $domain=$userarray[1];

system(\

# vi /var/www/postfixadmin/delete.php $userarray=explode(\$user=$userarray[0]; $domain=$userarray[1];

system(\进入http://localhost/postfixadmin/admin/index.php 然后在里面添加域名,先添加域名-》在添加管理员 添加成功之后 移走setup。Php

用管理员用户登录http://localhost/postfixadmin添加用户

安装squirrelmail

cd /usr/local/apache/htdocs tar -xzvf squirrelmail-1.4.11.tar.gz

cd squirrelmail-1.4.11

./configure

# 你将要设置如下选项

#选择 “2. Server Settings”=>“A. Update IMAP Settings”=>“8. Server

11

software”改成“courier”;回到主菜单,选择“4.General Options”=>“1. Data Directoryand”改成“/var/www/data/”;再退回主菜单,选择“8. Plugins”=>添加你希望用到的插件。回到主菜单,选择“10. Languages”,将“ Default Language”改成“zh_TW”,“Default Charset”改成“utf-8”。保存退出。

mv data /usr/local/apache/htdocs/squirrelmail

chown -R vuser:vgroup /usr/local/apache/htdocs/squirrelmail

cd ../

mv squirrelmail-1.4.11 /usr/local/apache/htdocs/squirrelmail

我在这里遇到几个问题:进入网页里,报错imap_server,可能是imap没启动,把所有关于QMAIL的服务都要启动,出现/data和apache不能结合,是因为apache没权限写入/data目录 出现402什么的字眼,可能是selinux把权限限制了,把selinux关了就行了(在/etc/selinux/config,设置为DISABLE就行了),有时输入用户名和密码出现密码错误,可能是没给vpopmail的权限,如果出现无法存取页面的错误,那么注意seisson的权限问题

这里要提一下squirrelmail汉化: 小松鼠邮件系统汉化

小松鼠本身支持很多语言,可下载相应的语言包。可到其主页去下载

下载汉化包,这里给出现在的汉化包:

wget http://switch.dl.sourceforge.net/sourceforge/squirrelmail/zh_CN-1.4.4-20050308.tar.gz 8.3 汉化包安装

tar zxvf zh_CN-1.4.4-20050308.tar.gz

解压之后有locale目录,把locale下的文件移到squirrelmail目录下的locale目录下就行了

支持LDAP:

12

进入/var/www/html/squirrelmail/config/下(根据自己安装的目录所定)

vi config.php

................................................................................................ .......................................................................................................... ........................................................................................................... .......................................................................................................... $theme[48]['NAME'] = 'Classic Blue 2';

$theme[49]['PATH'] = SM_PATH . 'themes/powder_blue.php'; $theme[49]['NAME'] = 'Powder Blue';

$theme[50]['PATH'] = SM_PATH . 'themes/techno_blue.php'; $theme[50]['NAME'] = 'Techno Blue';

$theme[51]['PATH'] = SM_PATH . 'themes/turquoise.php'; $theme[51]['NAME'] = 'Turquoise';

$default_use_javascript_addr_book = false; $ldap_server[0] = array(

'host' => '192.168.10.168',填上LDAP服务器的IP

'base' => 'dc=webmail,dc=print68,dc=com',填上LDAP服务器的域名 'name' => '192.168.10.168',填上LDAP服务器的名字 'port' => 389,填上LDAP的端口,这是默认的 'charset' => 'utf-8'语言 );

$abook_global_file = '';

$abook_global_file_writeable = false; $abook_global_file_listing = true; $abook_file_line_length = 2048;

或者在/var/www/html/squirrelmail下 执行./configure

#选择 “6. Address Books”=>“1. Change LDAP Servers”=>然后自己按提示选择

由于LDAP服务器版本是V3的,但squirrelmail支持的是V2,所以要在

13

/usr/local/openldap/etc/openldap/sladp.conf 里

# Sample security restrictions

# Require integrity protection (prevent hijacking)

# Require 112-bit (3DES or better) encryption for updates # Require 63-bit encryption for simple bind # security ssf=1 update_ssf=112 simple_bind=64 allow bind_v2 在这里加上这行,让他支持V2版本 # Sample access control policy:

# Root DSE: allow anyone to read it

# Subschema (sub)entry DSE: allow anyone to read it # Other DSEs:

# Allow self write access

# Allow authenticated users read access # Allow anonymous users to authenticate

因为我们把 SquirrelMail 预设编码设为 Big5 ,但 LDAP 的 LDIF 信息皆为 UTF-8 编码格式,前提是系统了装了PHP-ICONV的包,如果没装,系统盘里有包

所以我们要进

/var/www/html/squirrelmail/functions/abook_ldap_server.php 里 310 // $fullname =

$this->charset_decode($row['cn'][0]); //默认值

311 $fullname = iconv(\//将 LDAP 查到的 utf-8 中文信息转换成 big5 在传给 SquirrelMail #vi

/usr/local/www/data/squirrelmail/functions/abook_ldap_server.php 264 //$expr = $this->charset_encode($expr); //预设值

265 $expr = iconv(\//输入搜寻条件为 big5 但转换成 utf-8 在去查 LDAP

使用 IE 登入 SquirrelMail 后收到中文文件名的附件按下 Download 后原来的中文档名档案下载后变成乱码档名

#vi /usr/local/www/data/squirrelmail/src/download.php 102 $filename =

charset_encode($filename,$default_charset,false); //加在这行下面

14

103 $filename = iconv(\//加入此行

让长的邮件内容自动换行

用SquirrelMail显示长的邮件内容时有一个缺陷,就是不会自动换行。查看源文件后,发现

问题有两点:一是在显示邮件内容时使用的是“pre”标识,二是表格TD都是不定长的。

要让长的邮件内容能自动换行,需要做如下改动:

1、不再使用“pre”标识显示邮件内容: vi functions/mime.php

-- $body = '

' . implode(\++    $body = implode(\   

2、找到显示“$messagebody”的TD语句,将TD改成定长: vi src/read_body.php 老版本:

-- \

新版本:

-- html_tag( 'td', '
'. $messagebody.\

++ html_tag( 'td', '
'. $messagebody.\

配置Cyrus-SASL 认证

RHEL4/CentOS4的cyrus-sasl默认没有打开authdaemon的支持,为了使用集中认证的authlib,必须打开这个支持。为此我们必须删除系统的cyrus-sasl软件包,替换成打开了authdaemon支持的sasl软件包。首先要删除系统老的cyrus-sasl: rpm -e --nodeps cyrus-sasl

15

然后安装新的支持authdaemon的软件包

rpm -ivh cyrus-sasl-lib-2.1.22-4

cyrus-sasl-devel-2.1.22-4 cyrus-sasl-sql-2.1.22-4 cyrus-sasl-plain-2.1.22-4 cyrus-sasl-2.1.22-4

cyrus-sasl-md5-2.1.22-4 cyrus-sasl-ntlm-2.1.22-4 cyrus-sasl-gssapi-2.1.22-4

Postfix的SMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息,编辑/etc/postfix/main.cf,增加如下内容: # smtpd related config smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, # SMTP AUTH config here broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous 其次用vi编辑/usr/lib/sasl2/smtpd.conf,确保其内容为: pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path:/var/spool/authdaemon/socket 16

存盘退出后,重新启动postfix: /etc/init.d/postfix restart 通过postfixadmin创建sc用户

测试SMTP认证

通过以下命令获得sc@sc.com的用户名及密码的BASE64编码: perl -e 'use MIME::Base64; print encode_base64(\dGVzdEBleHRtYWlsLm9yZw== perl -e 'use MIME::Base64; print encode_base64(\dGVzdA== 然后本机测试,其过程如下(蓝色的文字是我们输入/发送到Postfix的) telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.extmail.org ESMTP Postfix - by extmail.org ehlo demo.domain.tld 250-mail.extmail.org 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 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 quit 221 2.0.0 Bye

17

最后出现235 Authentication Successful 表明认证成功了。

反病毒/内容过滤配置

反病毒及内容过滤器是依赖Amavisd-new软件包,它是一个多功能的过滤器,能与杀毒软件及内容过滤软件(如SpamAssassin)结合,通用性较强。

安装依赖的Perl包

首先我们要确保系统自带的perl-Net-DNS软件包被删除干净,因为该包的版本较低(0.48),有已知的bug,所以必须替换成本文档提供的新版(0.5x),输入如下命令:

rpm -e --nodeps perl-Net-DNS

Amavisd-new 及SpamAssassin需要依赖大量的第三方perl软件包,下列要安装的部分RPM在上述的操作中已经安装了,为了给出较明确的依赖关系,我们依然将这些包的名称列出,如果安装时提示有安装包已安装过,或者提示冲突,请不必惊慌。请安装如下的RPM软件包:

rpm -ivh RPMS/perl-Digest-SHA1-2.07-5.i386.rpm rpm -ivh RPMS/perl-Digest-HMAC-1.01-1hzq.i386.rpm rpm -ivh RPMS/perl-Net-IP-1.24-1hzq.i386.rpm rpm --nodeps -ivh RPMS/perl-Net-DNS-0.57-1hzq.i386.rpm rpm -ivh RPMS/perl-Time-HiRes-1.72-1hzq.i386.rpm rpm -ivh RPMS/perl-HTML-Tagset-3.03-30.noarch.rpm rpm -ivh RPMS/perl-HTML-Parser-3.35-6.i386.rpm rpm -ivh RPMS/spamassassin-3.0.5-3.el4.i386.rpm rpm -ivh RPMS/perl-IO-stringy-2.110-1hzq.i386.rpm rpm -ivh RPMS/perl-IO-Multiplex-1.08-1hzq.i386.rpm rpm -ivh RPMS/perl-Net_SSLeay.pm-1.30-1hzq.i386.rpm rpm -ivh RPMS/perl-IO-Socket-SSL-0.97-1hzq.i386.rpm rpm -ivh RPMS/perl-Net-Server-0.93-1hzq.i386.rpm rpm -ivh RPMS/perl-Unix-Syslog-0.100-1hzq.i386.rpm rpm -ivh RPMS/perl-TimeDate-1.16-1hzq.i386.rpm rpm -ivh RPMS/perl-MailTools-1.67-1hzq.i386.rpm rpm -ivh --force RPMS/perl-MIME-Base64-3.05-1hzq.i386.rpm

18

rpm -ivh RPMS/perl-Convert-BinHex-1.119-1hzq.i386.rpm rpm -ivh RPMS/perl-MIME-tools-5.418-1hzq.i386.rpm rpm -ivh RPMS/perl-BerkeleyDB-0.26-1hzq.i386.rpm rpm -ivh RPMS/perl-Convert-TNEF-0.17-1hzq.i386.rpm rpm -ivh RPMS/perl-Convert-UUlib-1.051-1hzq.i386.rpm rpm -ivh RPMS/perl-Compress-Zlib-1.41-1hzq.i386.rpm rpm -ivh RPMS/perl-Archive-Zip-1.16-1hzq.i386.rpm rpm -ivh RPMS/perl-IO-Zlib-1.04-1hzq.i386.rpm rpm -ivh RPMS/perl-Archive-Tar-1.26-1hzq.i386.rpm rpm -ivh RPMS/arc-5.21o-1hzq.i386.rpm rpm -ivh RPMS/zoo-2.10-9hzq.i386.rpm rpm -ivh RPMS/unarj-2.65-49hzq.i386.rpm export LANG=C rpm -ivh RPMS/amavisd-new-2.4.0-1hzq.i386.rpm chown amavis.amavis /var/spool/vscan/db/ chkconfig --add amavisd 修改amavisd.conf

修改的主要参数如下,请逐一对照后修改: $max_servers = 10; $sa_spam_subject_tag = '[SPAM] '; $mydomain = 'mail.extmail.org'; $myhostname = 'mail.extmail.org'; @local_domains_maps = qw(.); $sa_tag2_level_deflt = 5.0; $sa_kill_level_deflt = 5.0; 注意事项:

上述$mydomain参数与$myhostname参数相同,主要是为了方便之后的病毒/垃圾汇报邮件发给系统管理员时,能投递到本地的别名里,再转交到虚拟域的特定用户。

增加如下参数(默认amavisd.conf没有):

$sa_spam_modifies_subj = 0; # don't modify subject $remove_existing_x_scanned_headers= 1; # remove existing headers

19

$remove_existing_spam_headers = 1; 配置SpamAssassin

Amavisd-new 通过Mail::SpamAssassin 模块来调用SA的功能,因此这里配置SA和常规配置SA软件有些区别,主要集中在修改local.cf文件上。 编辑/etc/mail/spamassassin/local.cf文件 vi /etc/mail/spamassassin/local.cf 将其内容修改为:

report_safe 1 use_bayes 0 auto_learn 0 bayes_auto_expire 1 skip_rbl_checks 1 use_razor2 0 use_dcc 0 use_pyzor 0 dns_available no 增加Chinese_rules.cf支持

Chinese_rules.cf是教育科研网的反垃圾邮件小组对大量垃圾邮件和正常邮件进行分析后得出的一个关键字/分数规则集,用于处理中文(简体)垃圾邮件还是比较有效的。这里我们通过如下命令增加到系统:

wget -N -P /usr/share/spamassassin www.ccert.edu.cn/spam/sa/Chinese_rules.cf 由于该规则每周更新一次,为了达到最好效果,最好在crontab里增加自动更新的内容,输入: /usr/bin/crontab -e 然后输入如下的内容:

0 0 1 * * wget -N -P /usr/share/spamassassin

www.ccert.edu.cn/spam/sa/Chinese_rules.cf; /etc/init.d/amavisd restart

20

存盘退出即可。最后运行以下调试命令以确认amavisd没有错误: /usr/sbin/amavisd debug

如果没有异常提示或报错退出则表示一切都正常,按ctrl+c终止,然后正常启动,若提示pid不存在等错误,不必理会,只要最后启动成功即可: /etc/init.d/amavisd start

安装ClamAV

执行如下命令:

Rpm –ivh clamav-db-0.91.2-1.el5.rf

clamd-0.91.2-1.el5.rf

clamav-0.91.2-1.el5.rf

编辑/etc/clamd.conf文件,去掉 'LocalSocket /var/run/clamav/clamd.sock'的注释,并注释掉 'TCPSocket 3310',我们将使用unix socket而不是TCP,两者不可并存。修改完毕后,保存,变动内容见下:

# Path to a local socket file the daemon will listen on. # Default: disabled LocalSocket /var/run/clamav/clamd.sock #TCPSocket 3310 将clamav加到amavis运行组里,并调整目录权限,否则clamav将无法扫描amavisd-new产生的临时文件

gpasswd -a clamav amavis usermod -G amavis clamav chown amavis.amavis /var/spool/vscan chmod 750 /var/spool/vscan chown amavis.amavis /var/spool/vscan/tmp chmod 750 /var/spool/vscan/tmp 默认的/var/spool/vscan 目录属性是:

21

rwx------ amavis.root

对于clamav用户而言,则无任何权限访问该目录,因此maillog里amavisd-new会提示:

May 19 08:38:53 as3 amavis[1752]: (01752-01) ask_av (ClamAV-clamd) FAILED - unexpected result: /var/spool/vscan/tmp/amavis-20050519T083853-01752/parts: Access denied. ERROR\\n

May 19 08:38:53 as3 amavis[1752]: (01752-01) WARN: all primary virus scanners failed, considering backups

启动ClamAV及freshclam /etc/rc.d/init.d/clamd start freshclam --daemon 将freshclam增加到自启动

输入如下命令,即可使freshclam一开机就实现自启动 echo \

配置Amavisd与Clamav结合

为了使Amavisd-new能与clamav结合,需要修改/etc/amavisd.conf文件,打开clamav的支持代码,编辑/etc/amavisd.conf文件,大概在300行左右,去掉clamav的支持代码注释,并将socket路径改为/var/run/clamav/clamd.sock,如下: ['ClamAV-clamd', \\&ask_daemon, [\ qr/\\bOK$/, qr/\\bFOUND$/, qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ], 在110行左右,修改投递/拦截的方法:

$final_virus_destiny = D_DISCARD; $final_banned_destiny = D_BOUNCE; $final_spam_destiny = D_PASS; $final_bad_header_destiny = D_PASS; 22

注意上述4个设置中,对spam(垃圾邮件)默认会直接反弹(BOUNCE),现在修改为继续投递(PASS)但在信头中增加相关X-Spam-Status信息等。这样可以很方便的在extmail中设置将被标记为垃圾邮件的mail投递到“垃圾邮件箱”中,便于用户翻查。

增加邮件别名

编辑/etc/postfix/aliases,增加如下信息,注意:默认的aliases数据库里已有一条virusalert的别名,所以请删除,再输入下面的别名记录,并确保所有记录都是唯一的:

virusalert: root spam.police: root postfix: sc@sc.com

保存并执行newaliases命令生成新的别名数据库,这样所有的重新启动amavisd: /etc/rc.d/init.d/amavisd restart

配置Postfix 集成amavisd-new

vi /etc/postfix/master.cf

增加如下内容:

127.0.0.1:10025 inet n - 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 smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o receive_override_options= 编辑/etc/postfix/main.cf

23

# Content-Filter content_filter = smtp:[127.0.0.1]:10024 receive_override_options = no_address_mappings 注意:receive_override_options 这里必须增加,禁止地址展开/影射,否则如果遇到别名的时候会引起冗余邮件的产生。 保存后/etc/init.d/postfix restart

测试Clamav

然后输入如下命令: 每输入一行后等待1秒左右: telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.extmail.org ESMTP Postfix - by extmail.org mail from:< sc@sc.com> 250 2.1.0 Ok rcpt to:< sc@sc.com> 250 2.1.5 Ok data 354 End data with . X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* . 250 2.0.0 Ok: queued as BC24E85260 quit 221 2.0.0 Bye Connection closed by foreign host. 在邮件日志里,应该有相应的信息出现:

May 19 10:11:44 as3 amavis[2770]: (02770-01) Blocked INFECTED (Eicar-Test-Signature), -> , quarantine: virus-20050519-101144-02770-01, Message-ID: <20050519141143.F224828AA8@mail. sc.com>, Hits: - 如果看到类似这样的日志,表明Clamav+Amavisd-new工作正常。

24

Spam Locker配置与安装

安装需求

支持Linux / BSD或Solaris,HP-UX等操作系统 Perl 5.6+,建议Perl 5.8.0以上 Net::DNS POSIX Fcntl Digest::MD5 Digest::SHA1 Digest::HMAC Net::IP 解包软件

cp -r src/slockd-0.083 /usr/local/slockd

安装相关Perl模块

由于slockd是以smtp特征检测为主的软件,因此很大程度依赖dns库,必须安装Net::DNS库才能正常工作。除此外还有诸如HMAC,MD5及SHA1, Net-IP等模块。

执行以下命令安装需要的模块,注意:这些模块在上文安装Amavisd-new时已经安装过,这里重复是为了强调slockd依赖这些软件包 rpm -ivh RPMS/perl-Digest-SHA1-2.07-5.i386.rpm rpm -ivh RPMS/perl-Digest-HMAC-1.01-1hzq.i386.rpm rpm -ivh RPMS/perl-Net-IP-1.24-1hzq.i386.rpm rpm -ivh --nodeps RPMS/perl-Net-DNS-0.57-1hzq.i386.rpm 25

配置resolv.conf

请确认/etc/resolv.conf里的dns服务器是离你的邮件服务器最近,速度最快的dns server,slockd很依赖dns的好坏,因此给系统配置一个快速的dns能大幅度提高处理速度。以下给出一个配置仅供参考: nameserver 202.96.128.68

上述dns服务器是广东电信的DNS服务器,对于非广东朋友,请改为离你最近的dns 服务器ip

如果可能的话,请配置一个简单的bind9,成为本地的dns cache server,可以获得最高性能。这里略过这一步骤,但您必须确保dns的配置是正确并且可靠的,否则slockd将不能工作!

启动/测试

执行:

/usr/local/slockd/slockd-init start

此时slockd将启动,并进入非daemon方式的监听模式,接受来自10030端口的请求,命令行下将显示如下调试信息:

Starting spam locker daemon: slockd starting child 2908 starting child 2909 08-01 12:34:40 [2908]: Loading APF::Plugin::localctrl 08-01 12:34:40 [2909]: Loading APF::Plugin::localctrl 08-01 12:34:40 [2908]: Loading APF::Plugin::anvil 08-01 12:34:40 [2908]: Loading APF::Plugin::fqdn 08-01 12:34:40 [2909]: Loading APF::Plugin::anvil 08-01 12:34:40 [2908]: Loading APF::Plugin::dnsbl 08-01 12:34:40 [2909]: Loading APF::Plugin::fqdn 08-01 12:34:40 [2909]: Loading APF::Plugin::dnsbl 08-01 12:34:40 [2908]: Loading APF::Plugin::hostname 08-01 12:34:40 [2909]: Loading APF::Plugin::hostname 26

打开另一个ssh/终端窗口,进入/usr/local/slockd/tools 目录,输入: perl policy_sig -h localhost -p 10030 --helo FOOBAR \\ --ip 192.168.0.1 --from sc@sc.com --to sc@sc.com 此时,程序应该返回如下错误信息:

action=504 : rejected, see http://bl.extmail.org/cgi/why?fqdn 这表示slockd初步的正常工作了。

后台方式运行slockd

调试正确后,必须将slockd配置成后台服务进程(Daemon Process)。vi /usr/local/slockd/config/main.cf 将如下两个配置的注释去掉: # uncomment the following line if you need to daemonize setsid 1 ## logging log_file /var/log/slockd.log 然后在运行slockd的命令行窗口按ctrl+c,关闭刚才运行的slockd。或者在另一个命令行窗口输入如下命令以杀死slockd进程: killall slockd 然后执行:

/usr/local/slockd/slockd-init start

自启动

输入如下的命令,将slockd启动加入到系统里,这样下一次服务器重新启动,就可以自动执行slockd了。

echo \ 27

配置Postfix

slockd调试正常后,必须配置postfix以使其打开对slockd的支持,编辑/etc/postfix/main.cf,将 check_policy_service inet:127.0.0.1:10030 这一行记录增加到smtpd_recipient_restrictions 里,例如: smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, check_policy_service inet:127.0.0.1:10030 最后,重新启动postfix以使配置生效 /etc/init.d/postfix restart 注意事项:

上述配置是将slockd的查询放到最后,这也是进一步提高资源利用律的办法,因为有部分功能postfix已实现了,所以就先由postfix检测,如果检测不到再由slockd完成。

最终测试

现在通过简单的email收发来确认系统是否正常。 发送测试邮件

输入以下命令,通过telnet方式给sc@sc.com发送一封测试信件 telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 28

220 mail.extmail.org ESMTP Postfix - by extmail.org helo sc@sc.com 250 mail.extmail.org mail from:< sc@sc.com> 250 2.1.0 Ok rcpt to:< sc@sc.com> 250 2.1.5 Ok data 354 End data with . Subject: Hello World Hello World! . 250 2.0.0 Ok: queued as 3E47685269 quit 221 2.0.0 Bye Connection closed by foreign host. 此时通过另一个命令行窗口,观察maillog,命令为: tail -f /var/log/maillog 将看到如下信息:

Aug 1 12:51:06 centos postfix/qmgr[3017]: 041718526B: from=, size=833, nrcpt=1 (queue active)

Aug 1 12:51:06 centos postfix/smtpd[3032]: disconnect from centos[127.0.0.1] Aug 1 12:51:06 centos amavis[2890]: (02890-01) Passed CLEAN, [127.0.0.1] -> , Message-ID: <20060801165039.3E47685269@mail. sc.com>, mail_id: N8nxpoRn4Hlq, Hits: 0.107, 11561 ms

Aug 1 12:51:06 centos postfix/smtp[3043]: 3E47685269: to=,

relay=127.0.0.1[127.0.0.1], delay=27, dsn=2.6.0, status=sent (250 2.6.0 Ok,

id=02890-01, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 041718526B) Aug 1 12:51:06 centos postfix/qmgr[3017]: 3E47685269: removed

Aug 1 12:51:06 centos postfix/pipe[3035]: 041718526B: to=, relay=maildrop, delay=0, dsn=2.0.0, status=sent (delivered via maildrop service) Aug 1 12:51:06 centos postfix/qmgr[3017]: 041718526B: removed

29

上述日志表示邮件经过了amavisd-new的扫描,并且已经通过maildrop投递到用户的maildir了

Postfix的FAQ:

telnet 25端口,然后收不到信,日志出现以下错误:

[root@mail local]# tail /var/log/maillog

Nov 8 10:09:11 mail postfix/smtpd[2530]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled

Nov 8 10:09:11 mail postfix/smtpd[2530]: connect from mail.sc.com[192.168.10.168]

Nov 8 10:09:21 mail postfix/smtpd[2530]: disconnect from mail.sc.com[192.168.10.168]

Nov 8 10:09:22 mail postfix/smtpd[2530]: connect from mail.sc.com[192.168.10.168]

Nov 8 10:10:05 mail postfix/smtpd[2530]: 61CE3C60110: client=mail.sc.com[192.168.10.168]

Nov 8 10:10:10 mail postfix/cleanup[2536]: 61CE3C60110: message-id=<20071108021005.61CE3C60110@mail.sc.com>

Nov 8 10:10:10 mail postfix/qmgr[2478]: 61CE3C60110: from=, size=351, nrcpt=1 (queue active)

Nov 8 10:10:10 mail maildrop[2539]: Temporary authentication failure. Nov 8 10:10:10 mail postfix/pipe[2538]: 61CE3C60110: to=, relay=maildrop, delay=29, delays=29/0.01/0/0.01, dsn=4.3.0, status=deferred (temporary failure. Command output: ERR: authdaemon: s_connect() failed: Permission denied maildrop: Temporary authentication failure. ) Nov 8 10:10:11 mail postfix/smtpd[2530]: disconnect from mail.sc.com[192.168.10.168]

解决方法:

原因在于courier-authlib 如果编译的话必须要加入--with-mailuser,--with-mailgroup,这两项,如果是用RPM安装的话,就必须敲这条命令chmod 755 /var/spool/authdaemon/ 如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证,当然maildrop的安装方式不同,/etc/postfix/master.cf的 maildrop的配置也不同

当postfixadmin出现如此错误时:

30

那就是创建域名的时候

Add a new domain Domain: Description: Aliases: Mailboxes: 1010 -1 = disable | 0 = unlimited -1 = disable | 0 = unlimited MB Mailboxes:: 10 -1 = disable | 0 = unlimited Add default mail aliases: Mail server is backup MX: Add Domain

解决方法:

Aliases,Mailboxes: Mailboxes:都选0 只勾MX这一项,就行了。

31

32

本文来源:https://www.bwwdw.com/article/ysw7.html

Top