Fedora 7下搭建基于Postfix的Extmail邮件服务器

安装环境:Fedora 7
说明:apache,php,mysql,为fedora7自带的,就是说我装系统的时候,就选择上了(在安装fedora7的时候,开发工具要全部安装),cyrus-sasl, postfix,courier-authlib,maildrop,courier-imap 是通过源码编译的,写这个的目的就是,复制内容,照着一步步的做下去就能配置出来一个成功的可视化管理的mail服务器。
如果是rpm方式安装的Msqyl, include及lib目录的位置
/usr/include/mysql 、 /usr/lib/mysql
如果是编译的,位于你指定的目录下,如果编译mysql指定目录为/usr/local/mysql则位于
/usr/local/mysql/include/mysql   /usr/local/mysql/lib/mysql
如果你的apache, php, mysql是fedora7自带的,就是说不是你自己编译的,以下的代码可以复制粘贴
命令       文件内容
# yum install mysql-devel
==courier-authlib==安装配置配置courier-authlib
==courier-authlib=下载地址
http://sourceforge.net/project/showfiles.php?group_id=5404
文件名:courier-authlib-0.60.2.tar.bz2
# yum install gdbm-*
==courier-authlib==进入解压目录编译
#./configure
--with-redhat
--with-authmysql=yes
--with-mysql-libs=/usr/local/mysql/lib/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql
--prefix=/usr/local/courier-authlib
--without-stdheaderdir

#make
#make install
#make install-configure

编辑#vi /etc/ld.so.conf
加入/usr/local/courier-authlib/lib/courier-authlib
# ldconfig
备注:如果没有运行ldconfig,按装完maildrop,运行maildrop -v时会出现错误(maildrop:error while loading shared libraries: libcourierauth.so.0)

# vi /etc/rc.d/rc.local
/usr/local/courier-authlib/sbin/authdaemond start //增加该行
修改目录权限,如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证:
#chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
然后编辑/usr/local/courier-authlib/etc/authlib/authmysqlrc
# vi /usr/local/courier-authlib/etc/authlib/authmysqlrc
清空原内容加入

MYSQL_SERVER            localhost
MYSQL_USERNAME          extmail
MYSQL_PASSWORD          extmail
MYSQL_SOCKET            /var/lib/mysql/mysql.sock
MYSQL_PORT              3306
MYSQL_OPT               0
MYSQL_DATABASE          extmail
MYSQL_USER_TABLE        mailbox
MYSQL_CRYPT_PWFIELD     password
MYSQL_UID_FIELD         uidnumber
MYSQL_GID_FIELD         gidnumber
MYSQL_LOGIN_FIELD       username
MYSQL_HOME_FIELD        homedir
MYSQL_NAME_FIELD        name
MYSQL_MAILDIR_FIELD     maildir
MYSQL_QUOTA_FIELD       quota
MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\
                        CONCAT('/home/domains/',homedir),               \
                        CONCAT('/home/domains/',maildir),               \
                        quota,                                          \
                        name                                            \
                        FROM mailbox                                    \
                        WHERE username = '$(local_part)@$(domain)'
启动服务
# /usr/local/courier-authlib/sbin/authdaemond start

=cyrus-sasl=安装配置cyrus-sasl
=cyrus-sasl=下载地址:ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
=cryus-sasl=文件名:cyrus-sasl-2.1.22.tar.gz
#rpm -qa|grep cyrus-sasl把查找出来的包都删除了
#rpm -e --nodeps 包名
#rm -rf /usr/lib/sasl
#rm -rf /usr/lib/sasl2
=cyrus-sasl=进入解压目录编译:
#./configure \
--enable-plain \
--enable-cram \
--enable-digest \
--enable-login \
--enable-sql \
--disable-anon \
--disable-ntlm \
--disable-gssapi \
--disable-krb4 \
--disable-otp \
--disable-srp \
--disable-srp-setpass \
--with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket \
--with-mysql
--with-mysql-libs=/usr/local/mysql/lib/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql

#make
#make install
#ln -s /usr/local/lib/sasl2 /usr/lib/sasl2
#vi /etc/ld.so.conf
/usr/local/lib //增加该行
# ldconfig
# vi /usr/local/lib/sasl2/smtpd.conf
加入以下四行
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

==postfix==安装配置postfix
==postfix==下载地址:http://www.postfix.org/download.html
==postfix==文件名:postfix-2.4.6.tar.gz
==postfix==进入解压目录编译:
# yum install db*-devel*
# make tidy
# groupadd postfix -g 54321 //如果原来系统中有该用户则不需要再建
# groupadd postdrop
# useradd -s /bin/false -u 54321 -g postfix -G postdrop postfix
==postfix==备注,我的mysql是rpm包装的,如果是你自己源码编译的,下边mysql路径会有变化
#make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -I/usr/local/include/sasl' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lm -lz -L/usr/local/lib -lsasl2'
#make
#make install
#mv /etc/aliases /etc/aliases.old
#ln -s /etc/postfix/aliases /etc/aliases
#echo 'root: admin@example.com'>>/etc/postfix/aliases
#/usr/bin/newaliases
#postconf -n > /etc/postfix/main2.cf
#mv /etc/postfix/main.cf /etc/postfix/main.cf.old
#mv /etc/postfix/main2.cf /etc/postfix/main.cf
# vi /etc/postfix/main.cf
==postfix==main.cf加入以下内容
# hostname
mynetworks = 127.0.0.1
myhostname = mail.extmail.org
mydomain = extmai.com
myorigin = $mydomain
mydestination = $mynetworks $myhostname

# banner
mail_name = Postfix - by extmail.org
smtpd_banner = $myhostname ESMTP $mail_name

# response immediately
smtpd_error_sleep_time = 0s
unknown_local_recipient_reject_code = 450

# extmail config here
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport = maildrop:

==postfix==main.cf内容结束
==postfix==以下几个文件可以通过
#cp /var/www/html/extsuite/extman/docs/mysql_* /etc/postfix/得到
需要将extman包解压,见下文‘配置extmail&extman’ 自己创建也可
==postfix==编辑mysql_virtual_alias_maps.cf
#vi /etc/postfix/mysql_virtual_alias_maps.cf
内容如下:
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = alias
select_field = goto
where_field = address

==postfix==编辑mysql_virtual_domains_maps.cf
#vi /etc/postfix/mysql_virtual_domains_maps.cf
内容如下:
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = domain
select_field = description
where_field = domain
#additional_conditions = and backupmx ='0' and active ='1'

==postfix==编辑mysql_virtual_mailbox_maps.cf
#vi /etc/postfix/mysql_virtual_mailbox_maps.cf
内容如下:
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'


==postfix==SMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息,编辑/etc/postfix/main.cf,增加如下内容:
# vi /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


==maildrop==安装配置maildrop
==maildrop==下载地址:
http://sourceforge.net/project/showfiles.php?group_id=5404
==maildrop==文件名:maildrop-2.0.4.tar.bz2
#yum install pcre-*
#ln -s /usr/local/courier-authlib/bin/courierauthconfig /usr/bin/courierauthconfig
==maildrop==这样编译出来的maildrop才会ourier Authentication Library extension enabled.
# groupadd -g 1000 vgroup
# useradd -g 1000 -u 1000 -s /bin/false vuser
==maildrop==编译:
# ./configure   \
--enable-sendmail=/usr/sbin/sendmail \
--enable-trusted-users='root vuser' \
--enable-syslog=1 \
--enable-maildirquota \
--enable-maildrop-uid=1000 \
--enable-maildrop-gid=1000 \
--with-trashquota \
--with-dirsync

# make
# make install
# maildrop -v   //检查信息,如果有courier-authlib则表示安装成功


==maildrop==配置main.cf和master.cf使postfix调用maildrop
由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加如下参数:
#vi /etc/postfix/main.cf
加入
maildrop_destination_recipient_limit = 1
为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,注释掉原来的maildrop的配置内容,并改为:
#vi /etc/postfix/master.cf
把maildrop   unix        -       n        n        -        -        pipe
  #flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}这行注释
改为flags=DRhu user=vuser argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

此处要注意argv=后边的maildrop要加上路径,否则会出现
temporary failure. Command output: pipe: fatal: pipe_command: execvp maildrop: No such file or directory
注意maildrop unix这行前边不能有空格,要不会出现以下错误提示
warning: connect to transport maildrop: No such file or directory
Oct 31 23:21:24 localhost postfix/error[2235]: BE0AE27DAF6: to=<jjq002@abc.com>,relay=none,delay=1443,delays=1443/0.24/0/0.02,dsn=4.3.0, status=deferred (mail transport unavailable)
注意flags=Drhu这一行前边有两个空格,要不会出现以下错(fatal: /etc/postfix/master.cf: line 100: bad transport type: user=vuser)。
虚拟主机设置
在/etc/httpd/conf/httpd.conf中,注解掉
#AddDefaultCharset UTF-8
在最后一行加上:
NameVirtualHost *:80
Include conf/vhost_*.conf

编辑/etc/httpd/conf/vhost_extmail.conf,里面定义虚拟主机的相关内容包括主目录,以及ExtMail和ExtMan的相关配置,Suexec的设置等。

# VirtualHost for ExtMail Solution
<VirtualHost *:80>
ServerName www.abc.com
DocumentRoot /var/www/html/extsuite/extmail/html/

ScriptAlias /extmail/cgi/ /var/www/html/extsuite/extmail/cgi/
Alias /extmail/ /var/www/html/extsuite/extmail/html/

ScriptAlias /extman/cgi/ /var/www/html/extsuite/extman/cgi/
Alias /extman/ /var/www/html/extsuite/extman/html/

# Suexec config
SuexecUserGroup vuser vgroup
</VirtualHost>
保存,重启apache
出现Warning: DocumentRoot [/var/www/html/extsuite/extmail/html/] does not exist
不必理会,下边马上会配置
========================
配置extmail,extman
下载地址:http://www.extmail.org/cgi-bin/download.cgi
文件名:extmail-1.0.2.tar.gz   extman-0.2.2.tar.gz 下载并解压
配置过程:
#mkdir -p /var/www/html/extsuite
=====针对ExtMailcyrus-sasl-2.1.22.tar.gz
#cp -r extmail-1.0.2 /var/www/html/extsuite/extmail
#cd /var/www/html/extsuite/extmail/
#cp webmail.cf.default webmail.cf
编辑webmail.cf   #vi /var/www/html/extsuite/extmail/webmail.cf
把/var/www/extsuite/替换为/var/www/html/extsuite/
其它变动如下:
SYS_USER_LANG = zh_CN
SYS_USER_CHARSET = gb2312

SYS_MFILTER_ON = 1
SYS_NETDISK_ON = 1

SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail

SYS_G_ABOOK_TYPE = file
SYS_G_ABOOK_FILE_CHARSET = gb2312

更新cgi目录权限
由于SuEXEC的需要,必须将extmail的cgi目录修改成vuser:vgroup权限:
#chown -R vuser:vgroup /var/www/html/extsuite/extmail/cgi/

====针对ExtMab
#cp -r extman-0.2.2 /var/www/html/extsuite/extman
#cd /var/www/html/extsuite/extman
编辑webman.cf  
把/var/www/extsuite/替换为/var/www/html/extsuite/
其它配置
SYS_CHARSET = gb2312
SYS_LANG = zh_CN

更新cgi目录权限
由于SuEXEC的需要,必须将extman的cgi目录修改成vuser:vgroup权限:
#chown -R vuser:vgroup /var/www/html/extsuite/extman/cgi/

====数据库初始化,need to edit extmail.sql and init.sql to suit you website,and the init user , passwd are in this tow file
#mysql -u root -p < /var/www/html/extsuite/extman/docs/extmail.sql //创建数据库
#Enter password:
# mysql -u root -p < /var/www/html/extsuite/extman/docs/init.sql //插入一些默认值
#Enter password:

=======链接基本库到Extmail
由于ExtMan的体系与ExtMail比较类似,因此ExtMan需要使用ExtMail中几个基础perl 模块,在
extman的源码包里,包含了一个叫buildpkg.sh(可能以前版 本为buildlink.sh) 的小脚本,该脚
本完成了这些链接的工作,使用方法:
#cd /var/www/html/extsuite/extman/libs/Ext
#./buildpkg.sh build /var/www/html/extsuite/extmail/libs/Ext
#mkdir /tmp/extman
#chown -R vuser:vgroup /tmp/extman
======数据库中默认插入的测试邮箱时postmaster@extmail.org为其建立 maildir
#cd /var/www/html/extsuite/extman/tools/
#./maildirmake.pl /home/domains/extmail.org/postmaster/Maildir
#chown -R vuser:vgroup /home/domains
=======[mailtest.com是我自己建立的URL]通过
http://www. mailtest.com/exmail/访问邮件登陆页面。会出现
Unix::Syslog not found, please install it first! 需要按装:perl-Unix-Syslog
下载地址:
http://rpm.pbone.net/index.php3/ ... 9.el5.i386.rpm.html
文件名: perl-Unix-Syslog-0.100-9.el5.i386.rpm

=====通过http://www.cloudrainwind.com/extman访问后台管理面,会看不到验证码,需要按装perl-GD
下载地址:http://dries.ulyssis.org/rpm/packages/perl-GD/info.html
            或:http://apt.sw.be/packages/perl-GD/
文件名:perl-GD-2.30-2.2.el5.rf.i386.rpm
整体测试:
# echo "test"|maildrop -V 10 -d postmaster@extmail.org
//出现maildrop: Delivery complete.说明已经正常投递
配置courier-imap
下载地址:http://sourceforge.net/project/showfiles.php?group_id=5404
文件名: courier-imap-4.2.1.tar.bz2
编译:
# ./configure --prefix=/usr/local/courier-imap \
--with-redhat \
--enable-unicode \
--disable-root-check \
--with-trashquota \
--without-ipv6 COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig'

# make
# make install
然后
#cp /usr/local/courier-imap/etc/imapd.dist  /usr/local/courier-

imap/etc/imapd
#cp
/usr/local/courier-imap/etc/imapd-ssl.dist  /usr/local/courier-imap/etc/imapd-ssl
#cp /usr/local/courier-imap/etc/pop3d.dist  /usr/local/courier-imap/etc/pop3d
#cp
/usr/local/courier-imap/etc/pop3d-ssl.dist /usr/local/courier-imap/etc/pop3d-ssl
配置Courier-IMAP,为用户提供pop3服务:
#vi /usr/local/courier-imap/etc/pop3d
POP3DSTART=yes
注:如果你想为用户提供IMAP服务,可以在"/usr/local/courier-imap/etc/imapd"文件中设

置"IMAPDSTART=YES"。
#cp courier-imap.sysvinit /etc/rc.d/init.d/imapd
#chmod 755 /etc/rc.d/init.d/imapd
#chkconfig --add imapd

==mailgraph_ext==配置,需要的包及下载地址:
下载地址:
http://rpm.pbone.net/index.php3/ ... 3.el5.i386.rpm.html
文件名:rrdtool-1.2.23-3.el5.i386.rpm
下载地址:
http://rpm.pbone.net/index.php3/ ... l5.rf.i386.rpm.html
文件名:perl-rrdtool-1.2.23-1.el5.rf.i386.rpm
#rpm –ivh 安装上以上两个rpm包
按装:File::Tail及Time::HiRes
# yum install perl-CPAN
#perl -MCPAN -e shell
#cpan>install File::Tail
#cpan>install Time::HiRes
#cpan>quit
必要的包装好后,配置mailgraph_ext
#cp -r
/var/www/html/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext/
# /usr/local/mailgraph_ext/mailgraph-init start
# /usr/local/mailgraph_ext/qmonitor-init start
为了一开机就能自动执行上述进程,将上述命令加到rc.local 里面:
#echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local
#echo "/usr/local/mailgraph_ext/qmonitor-init start" >> /etc/rc.d/rc.local


到这里邮件系统就可以运行了,下边的部分可以选择配置以下给postfix邮件系统加上防病毒和防垃圾邮件

系统。
==amavisd==安装配置
下载地址:http://mirror.mainloop.se/amavisd/#download
文件名:amavisd-new-2.5.2.tar.gz
==amavisd==安装所需要的文件,实际这些文件名在amavised解压后的INSTALL里有列表
#perl -MCPAN -e shell
cpan>install Archive::Tar
cpan>install Archive::Zip
cpan>install Compress::Zlib
cpan>install Convert::UUlib
cpan>install MIME::Base64
cpan>install Mail::Internet
cpan>install Net::Server
cpan>install Net::SMTP
cpan>install Digest::MD5
cpan>install IO::Stringy
cpan>install Time::HiRes
cpan>install Unix::Syslog
cpan>install BerkeleyDB
cpan>install Convert::TNEF
cpan>install MIME::Parser
cpan>install MIME::Tools
=amavisd==配置,INSTALL中有详细的安装说明
==amavisd==进入解压目录
添加用户:
# groupadd amavis
# useradd -g amavis -s /bin/false -c "Clam AntiVirus" amavis
建立目录
# mkdir /var/amavis
# mkdir /var/amavis/tmp /var/amavis/var /var/amavis/db /var/amavis/home
# chown -R amavis:amavis /var/amavis
# chmod -R 750 /var/amavis
复制amavisd文件
# cp amavisd /usr/local/sbin/
# chown root /usr/local/sbin/amavisd
# chmod 755 /usr/local/sbin/amavisd
复制amavisd.conf
# cp amavisd.conf /etc/
# chown root /etc/amavisd.conf
# chmod 644 /etc/amavisd.conf
建立quarantine area
#mkdir /var/virusmails
#chown amavis:amavis /var/virusmails
#chmod 750 /var/virusmails
此目录下是放标记为病毒或垃圾的邮件

# vi /etc/amavisd.conf
修改amavisd.conf

$max_servers = 10; # num of pre-forked children (2..15 is common), -m
$daemon_user = 'amavis'; # (no default; customary: vscan or amavis), -u
$daemon_group = 'amavis'; # (no default; customary: vscan or amavis), -g

$MYHOME = '/var/amavis';
$TEMPBASE = "$MYHOME/tmp";
$db_home = "$MYHOME/db";

$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;

增加 三行:
$sa_spam_modifies_subj = 0; # don't modify subject
$remove_existing_x_scanned_headers= 1; # remove existing headers
$remove_existing_spam_headers = 1;


# cp amavisd_init.sh /etc/init.d/amavisd
# chmod 744 /etc/init.d/amavisd
# vi /etc/init.d/amavisd
prog="/usr/local/sbin/amavisd"
# chkconfig --add amavisd
# chkconfig amavisd on
# service amavisd restart
会有错误提示,暂不用理会
而且此时从其它邮件服务器给刚配置的邮件服务器发邮件会提示
(connect to 127.0.0.1[127.0.0.1]: Connection refused
只需要配置好spamassassin后,重启amavisd

配置Postfix 集成amavisd-new
编辑/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
增加如下内容
#Content-Filter
content_filter = smtp:[127.0.0.1]:10024
receive_override_options = no_address_mappings

==SpamAssassin==安装配置安装
==SpamAssassin==安装相关的包
方法一:
下载地址:http://spamassassin.apache.org/
文件名:Mail-SpamAssassin-3.2.3.tar.gz
进入解压目录:
# perl Makefile.PL
# make
# make install
方法二:
perl -MCPAN -e shell
cpan>install Digest::SHA1
cpan>install HTML::Parser
cpan>install Net::DNS
cpan>install Mail::SPF::Query
cpan>install IP::Country
cpan>install Net::Ident
cpan>install IO::Socket::INET6
cpan>install IO::Socket::SSL
cpan>install DBI
cpan>install LWP::UserAgent
cpan>install Mail::SpamAssassin
用上述两种方法之一按spamassassin即可
修改配置文件/etc/mail/spamassassin/local.cf文件
# How many hits before a message is considered spam.
required_hits           9.5

# Text to prepend to subject if rewrite_subject is used
rewrite_header Subject *****垃圾邮件*****

# Encapsulate spam in an attachment
report_safe             1

# Enable the Bayes system
use_bayes               1

# Enable Bayes auto-learning
bayes_auto_learn        1

# Enable or disable network checks
skip_rbl_checks         1
use_razor2              0
use_dcc                 0
use_pyzor               0

# Mail using languages used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_languages            all

# Mail using locales used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_locales              all

=========local.cf内容结束处

增加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


==clamav==安装配置
下载地址:http://www.clamav.org/download/sources/
文件名:clamav-0.91.2.tar.gz
进入解压目录
#groupadd clamav
#useradd -g clamav -s /bin/false -d /dev/null clamav

#./configure --prefix=/usr/local/clamav --with-dbdir=/usr/local/share/clamav
#make
#make check
#make install

#vi /usr/local/clamav/etc/clamd.conf

LogSyslog yes
LogVerbose yes
LogFacility LOG_MAIL
LogFile /var/log/clamav/clamd.log
PidFile /var/run/clamav/clamd.pid
DatabaseDirectory /usr/local/share/clamav
LocalSocket /var/run/clamav/clamd
StreamMaxLength 10M
User amavis
ScanMail yes
ScanArchive yes

#vi /usr/local/clamav/etc/freshclam.conf
DatabaseDirectory /usr/local/share/clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogSyslog yes
LogVerbose yes
DatabaseOwner amavis
Checks 12
DatabaseMirror db.CN.clamav.net
DatabaseMirror database.clamav.net
NotifyClamd /usr/local/clamav/etc/clamd.conf

注意:注释掉两个文件中Example那行

创建日志文件夹并设置权限
#mkdir /var/log/clamav
#chmod -R 744 /var/log/clamav
#chown -R amavis:amavis /var/log/clamav
#chown -R amavis:amavis /usr/local/share/clamav

#mkdir /var/run/clamav
#chmod 700 /var/run/clamav
#chown amavis.amavis /var/run/clamav

手动更新病毒库
#/usr/local/clamav/bin/freshclam


启动
# /usr/local/clamav/sbin/clamd
编辑/etc/rc.local加入
/usr/local/clamav/sbin/clamd

设置自动更新病毒库
#crontab -e
0 4 * * * root /usr/local/clamav/bin/freshclam --quiet -l

/var/log/clamav/clamd.log

配置Amavisd与Clamav结合
为了使Amavisd-new能与clamav结合,需要修改/etc/amavisd.conf文件,打开clamav的支持代码,
编辑 /etc/amavisd.conf文件,大概在300行左右,去掉clamav的支持代码注释,并将socket路径改为

/var/run/clamav/clamd.sock,如下:
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],
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;

注意上述4个设置中,对spam(垃圾邮件)默认会直接反弹(BOUNCE),现在修改为继续投递(PASS)但在

信头中增加相关X-Spam- Status信息等。这样可以很方便的在extmail中设置将被标记为垃圾邮件的mail投

递到“垃圾邮件箱”中,便于用户翻查。