作者:阳光
时间:2009-06-11
软件环境:
操作系统(OS) ubuntu 开源系统
邮件传输代理(MTA) Postfix 使用最新版本2.5.1
数据库/目录服务 MySQL 可选openLDAP或NetScape LDAP,本文以MySQL为蓝本
邮件投递代理(MDA) maildrop 支持过滤和强大功能
Web帐户管理后台 ExtMan 支持无限域名、无限用户
POP3 服务器 Courier-IMAP 只使用pop3部分,对于大部分企业而言完全足够
WebMail 系统 ExtMail 支持多语言、全部模板化,功能基本齐全
防病毒软件 Anti-Virus ClamAV 最热门的开源杀毒软件
SMTP阶段反垃圾邮件工具 Spam Locker 基于SMTP行为识别的Antispam软件,大量可选插件
内容过滤器 Amavisd-new Content-Filter软件,支持与clamav/sa的挂接
内容级别的反垃圾邮件工具 SpamAssassin 著名的SA,可以支持大量规则,但速度慢
SMTP认证库 Cyrus SASL 标准的SASL实现库,可以支持Courier authlib
其他数据认证库 Courier Authlib authlib是maildrop, courier-imap等服务的关键部件
日志分析及显示 mailgraph_ext 在ExtMan中已经包含了
以上的软件到ubuntu源上大部分的都找得到 extmail,extman,spam loocker可以到http://www.extmail.org/cgi-bin/download.cgi去下载最近的版本
好了垃圾话不多说了,现在我们开始我们的试验了:
首先我们把系统装好,我的主机名为mail.extmail.org,装上中文语言,升级系统,使用root权限登录到系统.
我们要装“LAMP” 注:apache2,php5,mysql,phpmyadmin
打开终端,执行
出来的界面和使用新立得是一样的,我在这里选“LAMP Server”,"OpenSSH Server","Samba file server",你们可以按自己要求来选择,将光标移动到你要安装的软件,按“空格”选定。在安装过程中会让你输入"Mysql"的密码。安装完后,我们还要安装phpmyadmin来管理mysql.sudo tasksel
在安装“phpmyadmin”的过程中它会出现“Configure database for phpmyadmin with dbconfig-common?”,我们选“否”.打开“火狐”,在地址中输入“localhost/phpmyadmin”出现phpmyadmin 的介面说明你成功了。sudo apt-get install phpmyadmin
前面一步,我装了“openssh server”远程管理服务。我配置了“基于RSA key登陆”,这样更安全点。
生成公有/私有RSA密匙对。sudo ssh-keygen -t rsa
进入保证密匙的文件(/home/b/.ssh/id_rsa):
进入passphrase(empty for no passphrase):
再次进入同一passphrase:
你的验证文件保存在/home/b/.ssh/id_rsa.
你的公有密匙保存在 /home/b/.ssh/id_rsa.pub.
接下来修改apache2的配置文件。
把下面的代码全部考到文件的最后。sudo gedit /etc/apache2/apache2.conf
重新启动AddType application/x-httpd-php .php .htm .html
AddDefaultCharset UTF-8
ServerName 127.0.0.1
<IfModule dir_module>
DirectoryIndex index.htm index.html index.php
</IfModule>
我们来安装 ZendOptimizerV3.3.3ForLinux.gz 它是一个PHP优化工具,不装也无所谓。我下载后把它放到了“opt”文件下,将它解压。进入文件/etc/init.d/apache2 restart
/etc/init.d/mysql restart
一路默认,到出现“enter the location of your php.ini file”我们选择php5的安装路径“/etc/php5/apache2/”,一路默认,到出现"please specify the full path to the apache binary (httpd)"时,我们选择的路径为“/usr/sbin/apache2”一路确认,安装完后,我们来没试一下,看看zend起到做用没有,到 /var/www/下新建一个空白文件,文件名为index.php,文件内容为cd /opt/ZendOptimizer-3.3.3-linux-glibc23-i386
./install
这是一个php探针,打开后,里面会有zend的选项。<?php
echo phpinfo();
?>
上面工作做完后,接下来我们来安装postfix courier sasl等:
你会被询问以下问题:apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-fastcgi libfcgi-perl libapache2-mod-php5 php5 php5-mysql build-essential libtool libnet-server-perl libnet-cidr-perl libberkeleydb-perl arc zoo lzop liblzo1 libstdc++5 libgd-gd2-perl libfile-tail-perl libdigest-sha1-perl libdigest-HMAC-perl libnet-ip-perl libnet-dns-perl libhtml-tagset-perl libhtml-parser-perl libio-stringy-perl libio-multiplex-perl libio-socket-ssl-perl libio-zlib-perl libnet-ssleay-perl libunix-syslog-perl libtimedate-perl libmailtools-perl libconvert-binhex-perl libconvert-tnef-perl libconvert-uulib-perl libcompress-zlib-perl libarchive-zip-perl perl-suid apache2-suexec
Create directories for web-based administration? <-- No
General type of mail configuration: <-- Internet Site
System mail name: <-- mail.extmail.org
下载extmail,并修改配置
我用的是ExtMail 1.1.0.tar.gz和ExtMan 1.0.0.tar.gz
注意:修改/etc/postfix/mysql_virtual_*.cf,将其中的“localhost”均改为“127.0.0.1”tar zxvf extmail-1.1.0.tar.gz
tar zxvf extman-1.0.0.tar.gz
mkdir /var/www/extsuite
mv extmail-1.1.0 /var/www/extsuite/extmail
mv extman-1.0.0 /var/www/extsuite/extman
cp /var/www/extsuite/extman/docs/mysql_virtual_*.cf /etc/postfix/
注:如果打算使用默认用户vuser:vgroup,那么需创建此用户,且uid:gid为1000:1000.而本文为了以后方便,使用的是手动创建的用户vmail,所以需修改下边这些文件中的相关参数.chmod o= /etc/postfix/mysql_virtual_*.cf
chgrp postfix /etc/postfix/mysql_virtual_*.cf
新建一个用户vmail组为vmail uid和gid为1000,不允放登录。用户下用来存放所有的用户的邮件
注:如果打算使用默认用户vu修改uid和gid 由于程序中默认使用的为vuser:vgroup,其uid:gid为1000:1000。而当前采用了一个新建用户vmail,所以需修改程序中的所有相关参数,具体操作如下:groupadd -g 1000 vmail
useradd -m -g vmail -u 1000 -d /home/vmail -s /bin/bash vmail
修改/var/www/extsuite/extmail/webmail.cf里的其他参数,主要变动的内容见下:chown -R vmail:vmail /var/www/extsuite/extmail/cgi/
chown -R vmail:vmail /var/www/extsuite/extman/cgi/
cd /var/www/extsuite/extmail/
cp webmail.cf.default webmail.cf
SYS_MESSAGE_SIZE_LIMIT = 102400000 //注:这个选项为修改附件的大小,默认为5M,你可以自行修改,这里面改了是不行的,还要去postfix里面修改,我在下面会讲到。gedit webmail.cf
SYS_USER_LANG = zh_CN
SYS_USER_CHARSET = gb2312
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
SYS_AUTHLIB_SOCKET = /var/run/courier/authdaemon/socket
SYS_G_ABOOK_FILE_CHARSET = gb2312
SYS_MAILDIR_BASE = /home/vmail
gedit ../extman/webman.cf
SYS_CAPTCHA_ON = 0 //用于关闭后台登录时的验证码
SYS_MAILDIR_BASE = /home/vmail
SYS_DEFAULT_UID = 1000
SYS_DEFAULT_GID = 1000
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = 127.0.0.1
SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock
SYS_LANG = zh_CN
SYS_GROUPMAIL_SENDER = [email protected] //注: 这个选项是,你在后台群发后,用户收到邮件的发件人地址,你可以自行修改。
gedit dispatch-init
SU_UID=vmail
SU_GID=vmail
gedit dispatch_lig.sh
BASE=/var/www/extsuite/extmail
$BASE/tools/suid-with -u vmail -g vmail /usr/bin/perl $BASE/dispatch.fcgi
数据库初始化cd ../extman/
gedit tools/setid.pl
set_gid('vmail');
set_uid('vmail');
gedit tools/adminctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/userctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/aliasctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/domainctl.pl
--setgid=vmail
--setuid=vmail
注:这上面实际上都是把vuser改成vmail,vgroup改成vmail.
gedit contrib/passwd2ext.pl
my $sock = '/var/run/mysqld/mysqld.sock';
my $uid = '1000';
my $gid = '1000';
gedit libs/Ext/Mgr/LDAP.pm
uidNumber => $opt{uidnumber} || '1000', //349行
gidNumber => $opt{gidnumber} || '1000', //350行
︰
uidNumber => $opt{uidnumber} || '1000', //541行
gidNumber => $opt{gidnumber} || '1000', //542行
gedit docs/init.ldif
uidNumber: 1000
gidNumber: 1000
gedit /var/www/extsuite/extman/docs/init.sql
修改18行中的uid和gid
INSERT INTO `mailbox` VALUES ('[email protected]','postmaster','$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0','','PostMaster','','extmail.org/postmaster/Maildir/','extmail.org/postmaster','104857600S','52428800S','extmail.org',1000,1000,'2007-02-14 15:10:04','2010-11-08',1,0,0,0,0,0,0,0,'my question', 'my answer');
gedit /var/www/extsuite/extman/docs/extmail.sql
修改uid和gid
CREATE TABLE mailbox (
︰
︰
129行 uidnumber int(6) NOT NULL default '1000',
130行 gidnumber int(6) NOT NULL default '1000',
︰)
到此,vmail用户组修改完毕。
执行以下命令导入mysql数据库结构及初始化数据,注意必须逐行输入以下命令.
链接基本库到Extmailmysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
mysql -u root -p < /var/www/extsuite/extman/docs/init.sql
建立临时文件夹:
mkdir /tmp/extman
chown -R vmail:vmail /tmp/extman
注:linux系统有个tmpwatch工具,该工具会定期扫描/tmp/下的文件,如果这些文件很久都没被使用,将被删除,因此如果后台长期不使用, /tmp/extman目录有可能被tmpwatch删除,所以要么定期登陆后台,要么修改 webman.cf将临时目录修改到另一个地方。此处暂以/tmp/extman默认值为例。gedit /etc/rc.local
编辑rc.local,加入下面内容以实现开机自动建立编辑rc.local,加入下面内容以实现开机自动建立
if [ ! -d /tmp/extman ]; then
mkdir /tmp/extman
chown -R vmail:vmail /tmp/extman
fi
建立上边导入mysql的[email protected]帐户的Maildir,请输入如下命令:
Postfix配置cd /var/www/extsuite/extman/tools
./maildirmake.pl /home/vmail/extmail.org/postmaster/Maildir
chown -R vmail:vmail /home/vmail/extmail.org/
修改/etc/postfix/mysql_virtual_*.cf,将其中的localhost均改为127.0.0.1
把上面的都复制到你的main.cf文件中,各位可以按自己的要求自行配置cd /etc/postfix/
cp main.cf main.cf_backup
gedit main.cf
# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
mydomain = extmail.org
myhostname = mail.$mydomain
myorigin = $mydomain
mydestination = mail.$mydomain, localhost.$mydomain, localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
relayhost =
mynetworks = 127.0.0.1
message_size_limit = 102400000
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
html_directory = /usr/share/doc/postfix/html
######### virtual config############
virtual_alias_domains =
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_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_overquota_bounce = yes
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the your Maildir has overdrawn your diskspace quota, please free up some of spaces of your mailbox try again.
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
好了现在我们来做SMTP身份认证了
代码: 全选
cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509
它们询问你问题
Country Name (2 letter code) [AU]: //国家
State or Province Name (full name) [Some-State]: //省
Locality Name (eg, city) []: //城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]: //组织名称
Organizational Unit Name (eg, section) []: 组织单位名称
Common Name (eg, YOUR name) []: 通用名称
Email Address []: 邮件地址
更改smtpd.key权限
chmod o= /etc/postfix/smtpd.key
接下来是Apache2配置:/etc/init.d/postfix restart
我们可以新建一个站点,如果你的服务器,只是做邮件服务器,你可以直接修改默认的配置文件,不过修改前,还是要备份一下。
替换成我下面的代码:cp /etc/apache2/sites-enabled/000-default /etc/apache2/sites-enabled/000-default_backup
gedit /etc/apache2/sites-enabled/000-default
我用的是第二种办法:<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extmail /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman/ /var/www/extsuite/extman/html/
Alias /phpmyadmin /var/www/extsuite/phpmyadmin/
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
我到sites-available下新建了一个extmail的文件件,里面的代码是这样(参考)
你还要修改apache2里的配置文件<VirtualHost *:80>
ServerAdmin [email protected]
ServerName zhuzhaoguang.3322.org //注:这个是我申请的一个动态域名,我把他绑定我的电脑上
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extmail /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman/ /var/www/extsuite/extman/html/
Alias /phpmyadmin /var/www/extsuite/phpmyadmin/
ErrorLog /var/log/apache2/zhuzhaoguang-error.log
CustomLog /var/log/apache2/zhuzhaoguang-access.log combined
</VirtualHost>
添加apache2的启动用户 user vmail group vmailgedit /etc/apache2/apache2.conf
User vmail
Group vmail
你还要去执行这两条命令,不然apache2启动不起来的
chmod 777 /var/lib/apache2/fastcgi
chmod 777 /var/lib/apache2/fastcgi/dynamic
sudo /etc/init.d/apache2 restart
如果没有意外将启动10个dispatch.fcgi守护进程,可以通过以下命令将启动命令加到rc.local中,实现自启动:编辑/var/www/extsuite/extmail/dispatch-init文件:
MAXFORK=10
最后启动fastcgi server:
# /var/www/extsuite/extmail/dispatch-init start
访问页面echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.local
/etc/init.d/apache2 restart
关于在"apache2"里添加user,group后"phpmyadmin"打开显示为一片空白的解决办法:
删除/etc/apache2/conf.d/phpmyadmin 这个重定向的文件。
发现能打开,输入账号密码进不了,重启apache2,不行重启系统chown -R vmail:vmail /etc/phpmyadmin
chown -R vmail:vmail /usr/share/phpmyadmin
chmod 755 /etc/phpmyadmin
chmod 755 /usr/share/phpmyadmin
ln -s /usr/share/phpmyadmin/ /var/www/extsuite/phpmyadmin
SMTP认证
1.更改saslauthd
代码: 全选
gedit /etc/default/saslauthd
更改如下几项
START=yes 设置开机自动启动
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
gedit /etc/pam.d/smtp
内容如下:
代码: 全选
auth required pam_mysql.so user=extmail passwd=extmail host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=extmail passwd=extmail host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1
3.由于postfix处于chroot,要想调用到saslauthd 必须更改socket文件
代码: 全选
mkdir -p /var/spool/postfix/var/run/saslauthd
gedit /etc/postfix/sasl/smtpd.conf
代码: 全选
pwcheck_method:saslauthd
mech_list:plain login
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: 127.0.0.1
sql_user: extmail
sql_password: extmail
sql_database: extmail
log_level:7
sql_select: SELECT password FROM mailbox WHERE username='%u@%r' and domain='%r'
加入以上的内容gedit /etc/postfix/main.cf
###########SMTP AUTH config###############
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
###########smtpd related config############
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch, reject_unknown_sender_domain, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, check_recipient_maps
添加用户
5.重启postfix saslauthdadduser postfix sasl
来做一下验证测试/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
t
代码: 全选
elnet localhost 25
ehlo localhost
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
出现这两项表示 sasl 配置成功
然后继续操作
auth login
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
ZXh0bWFpbA==
235 2.0.0 Authentication successful
quit
221 2.0.0 Bye
POP验证
更改如下一项gedit /etc/courier/authdaemonrc
内容如下:authmodulelist="authmysql"
cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc
gedit /etc/courier/authmysqlrc
代码: 全选
MYSQL_SERVER 127.0.0.1
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/run/mysqld/mysqld.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/vmail/',homedir), \
CONCAT('/home/vmail/',maildir), \
quota, \
name, \
CONCAT("disablesmtpd=",disablesmtpd, \
",disablesmtp=",disablesmtp, \
",disablewebmail=",disablewebmail, \
",disablenetdisk=",disablenetdisk, \
",disableimap=",disableimap, \
",disablepop3=",disablepop3, \
",netdiskquota=",netdiskquota) \
FROM mailbox \
WHERE username = '$(local_part)@$(domain)'
测试Courier-Authlib是否能成功连接mysql配置Courier-POP3
编辑/etc/courier/pop3d修改下面参数
MAILDIRPATH=/home/vmail/
配置Courier-IMAP
编辑/etc/courier/imapd修改下面参数
MAILDIRPATH=/home/vmail/
重新启动
/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
authtest -s login [email protected] extmail
如果成功应该有如下显示
Authentication succeeded.
Authenticated: [email protected] (uid 1000, gid 1000)
Home Directory: /home/vmail/extmail.org/postmaster
Maildir: /home/vmail/extmail.org/postmaster/Maildir/
Quota: 104857600S
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options:disablesmtpd=0,disablesmtp=0,disablewebmail=0,disablenetdisk=0,disableimap=0,disablepop3=0,netdiskquota=52428800S
如果出现error请检查数据库连接,分析mail.log。 一般都是input/output
Tips: chown daemon:vmail /var/run/courier/authdaemon 可能避免错误
测试pop3
telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user [email protected]
+OK Password required.
pass extmail
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
如果出现问题请仔细分析日志
MDA配置
概念:MDA mail deliver agent其实就是邮件投递代理,postfix本身有很多邮件投递代理,由于我们的环境虚拟域所以可以使用postfix自己的virtual 这个代理,但是它必须创建一个用户来执行投递操作,main.cf中有记录象这样:
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_transport = virtual
下面介绍另一种MDA maildrop
安装Maildrop
手动创建日志apt-get install maildrop
gedit /etc/maildropmysql.config //创建一个文件
hostname 127.0.0.1
port 3306
database extmail
dbuser extmail
dbpw extmail
dbtable mailbox
default_uidnumber 1000
default_gidnumber 1000
uidnumber_field uidnumber
gidnumber_field gidnumber
uid_field username
homedirectory_field concat('/home/vmail/',homedir,'/')
maildir_field concat('/home/vmail/',maildir)
quota_field quota
mailstatus_field active
修改/etc/maildroprc
gedit /etc/maildroprc
logfile "/var/log/maildrop.log"
gedit /var/log/maildrop.log
chown vmail:vmail /var/log/maildrop.log
chmod 766 /var/log/maildrop.log
编辑/etc/postfix/master.cf,注释掉原来maildrop的配置内容并改为:创建 /etc/logrotate.d/maildrop
内容为下面:
/var/log/maildrop.log {
daily
notifempty
missingok
rotate 5
compress
create 766 vmail vmail
sharedscripts
}
代码: 全选
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
创建 /etc/quotawarnmsg,为邮箱空间超过配额时的警告邮件内容###### Maildrop config ########
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 2
virtual_transport = maildrop:
X-Comment: Rename/Copy this file to quotawarnmsg, and make appropriate changes
X-Comment: See deliverquota man page for more information
From: Mail Delivery System <[email protected]>
Reply-To: [email protected]
To: Valued Customer:;
Subject: Mail quota warning
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Your mailbox on the server is now more than 90% full. So that you can continue
to receive mail you need to remove some messages from your mailbox.
图形日志extmail
然后复制文件apt-get install mailgraph
cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext
修改/usr/local/mailgraph_ext/mailgraph-init为:
MAIL_LOG=/var/log/mail.log
启动服务cp /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init /etc/init.d/mailgraph
update-rc.d mailgraph start 20 2 3 4 5 . stop 20 0 1 6 .
cp /var/www/extsuite/extman/addon/mailgraph_ext/qmonitor-init /etc/init.d/qmonitor
update-rc.d qmonitor start 20 2 3 4 5 . stop 20 0 1 6 .
/usr/local/mailgraph_ext/mailgraph-init start
把上面的代码加入到/etc/rc.local中,让系统自动启动
POSTFIX无法发信问题,到日志里面一看 /var/log/mail.log/etc/init.d/mailgraph start
/etc/init.d/qmonitor start
Jun 1 14:19:58 mail postfix/qmgr[12930]: C969234426: from=<[email protected]>, size=348, nrcpt=1 (queue active)
Jun 1 14:19:58 mail postfix/pipe[12939]: C969234426: to=<[email protected]>, relay=maildrop, delay=21, delays=21/0.04/0/0.04, dsn=5.1.1, status=bounced (user unknown. Command output: ERR: authdaemon: s_connect() failed: Permission denied Invalid user specified. ) //这里是最重要的,说我没有权限。
Jun 1 14:19:58 mail postfix/cleanup[12938]: 192FF34447: message-id=<[email protected]>
Jun 1 14:19:58 mail postfix/qmgr[12930]: 192FF34447: from=<>, size=2194, nrcpt=1 (queue active)
Jun 1 14:19:58 mail postfix/bounce[12941]: C969234426: sender non-delivery notification: 192FF34447
Jun 1 14:19:58 mail postfix/qmgr[12930]: C969234426: removed
Jun 1 14:19:59 mail postfix/smtpd[12934]: disconnect from mail.extmail.org[127.0.0.1]
上面的错误说我没有"authdaemon"的权限,我是这样做的
这下可以了,但是重启之后发现,authdaemon的权限又改会来了,日~~~~chmod 755 /var/run/courier/authdaemon
让它开机后自动执行,完工我又在/etc/rc.local下把这个加了上去
chmod 755 /var/run/courier/authdaemon
到此,本系统基本上是安装完毕了。
下面我们来学习,反垃圾邮件,和反病毒
然后,添加 clamav 用户到 amavis 用户组sudo apt-get install amavisd-new spamassassin clamav clamav-daemon clamtk
sudo apt-get install libnet-dns-perl libmail-spf-query-perl libnet-ph-perl libnet-snpp-perl libnet-telnet-perl pyzor razor
sudo apt-get install arj bzip2 cabextract cpio file gzip lha nomarch pax rar unrar unzip zip zoo lzop arc lzop
修改/etc/amavis/conf.d/15-content_filter_mode //打开amavisd-new过滤功能sudo adduser clamav amavis
sudo adduser amavis clamav
里面内容为这样:
然后,修改 /etc/postfix/main.cf,增加: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; # ensure a defined return
修改
/etc/amavis/conf.d/20-debian_defaults
将:$final_spam_destiny = D_PASS;
改成
$final_spam_destiny = D_DISCARD;
并重启这两个服务:
/etc/init.d/amavis restart
/etc/init.d/clamav-daemon restart
/etc/init.d/clamav-freshclam restart
修改 /etc/postfix/master.cf,增加:#### amavis config #####
content_filter = smtp-amavis:[127.0.0.1]:10024
receive_override_options = no_address_mappings
代码: 全选
smtp-amavis unix - - - - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
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_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
重启 Postfix:
root@mail:~# netstat -tap/etc/init.d/postfix restart
/postfix check
激活Internet连接 (服务器和已建立连接的)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 mail.extmail.org:10024 *:* LISTEN 2519/amavisd (maste
tcp 0 0 mail.extmail.org:10025 *:* LISTEN 3375/master
tcp 0 0 mail.extmail.org:mysql *:* LISTEN 2598/mysqld
tcp 0 0 mail.extmail.org:10030 *:* LISTEN 2703/slockd (master
tcp 0 0 mail.extmail.org:spamd *:* LISTEN 2713/spamd.pid
tcp 0 0 *:www *:* LISTEN 3949/apache2
tcp 0 0 *:ssh *:* LISTEN 2481/sshd
tcp 0 0 mail.extmail.org:ipp *:* LISTEN 3691/cupsd
tcp 0 0 mail.extmail.org:8888 *:* LISTEN 4017/dispatch.fcgi
tcp 0 0 *:smtp *:* LISTEN 3375/master
tcp 1 1 mail.local:47076 tx-in-f113.google.c:www LAST_ACK -
tcp6 0 0 [::]:imaps [::]:* LISTEN 3225/couriertcpd
tcp6 0 0 [::]:pop3s [::]:* LISTEN 3273/couriertcpd
tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN 3407/smbd
tcp6 0 0 [::]:pop3 [::]:* LISTEN 3246/couriertcpd
tcp6 0 0 [::]:imap2 [::]:* LISTEN 3198/couriertcpd
tcp6 0 0 [::]:ssh [::]:* LISTEN 2481/sshd
tcp6 0 0 localhost:ipp [::]:* LISTEN 3691/cupsd
tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN 3407/smbd
root@mail:~#
出现上面 “10024”,“10025”,字样说明amavis安装成功接下来我们来做反垃圾。
接下来就是spamassassin的配置了:
因为DCC不在我们软件库中我们要执行下面的操作
cd /tmp
wget http://launchpadlibrarian.net/11564361/ ... 5_i386.deb
wget http://launchpadlibrarian.net/11564359/ ... 5_i386.deb
dpkg -i dcc-common_1.3.42-5_i386.deb
dpkg -i dcc-server_1.3.42-5_i386.deb
1所需套件
* 2简介
* 3设定SpamAssassin
* 4设定SpamAssassin和Postfix搭配使用
* 4.1 spamd/spamd模式(一般作法)
* 4.2利用Amavisd-new来呼叫SpamAssassin(建议做法)
* 5测试SpamAssassin
* 6其它
所需套件
spamassassin (sa)
简介
SpamAssassin (SA)是利用Perl来进行文字分析以达到过滤垃圾邮件之目的。它的判断方式是藉由评分方式-若这封邮件符合某种特征,则加以评分。若总得分高于某项标准,则判定为垃圾邮件。
为了应用于高负载之服务器上,它也提供了spamc/spamd这组以Client/Server为架构之程式,如此可以有效降低SpamAssassin对系统资源的需求。但Debian预设上并不会启用这个服务。
而我们还可以替而使用Amavisd-new来呼叫SpamAssassin,也就是让Amavisd-new肩负扫毒及过滤垃圾邮件的重责。而在本人的系统中,这个方法比起使用spamc/spamd的做法快上了非常多,所以建议采用这种作法。
设定SpamAssassin
修改/etc/mail/spamassassin/local.cf如下,这是SpamAssassin的配置文件:
(详细设定请参考man Mail::SpamAssassin::Conf)
(修改/etc/mail/spamassassin/local.cf后会即时生效,用不着重新启动SpamAssassin。)
# This is the right place to customize your installation of SpamAssassin.
#
# See 'perldoc Mail::SpamAssassin::Conf' for details of what can be
# tweaked.
#
################################################## #########################
#
# rewrite_subject 0
# report_safe 1
# trusted_networks 212.17.35.
#得分多少以上就会被判定为垃圾邮件
required_hits 5.0
#绝不会被判定为垃圾邮件之列表,即白名单
#请自行加以增删修改!
whitelist_from tetralet@localhost
whitelist_from *@virtual.com
score USER_IN_BLACKLIST 20.00
score USER_IN_WHITELIST -1200.0
#在垃圾邮件上之标题上加上注记
rewrite_subject 1
#要如何处理垃圾邮件。因为邮件还会经过防毒程式的处理,所以必须设定为0。
# 0:将资讯写入邮件表头。
# 1:将垃圾邮件转为附件。
# 2:将垃圾邮件转为纯文字附件。
report_safe 0
#在处理垃圾邮件时,在邮件档头是否不加注详细原因?
use_terse_report 0
rewrite_header Subject ****SPAM****
#是否使用Bayesian
use_bayes 1
# Bayesian之资料库位置
bayes_path /var/lib/amavis/.spamassassin/bayes
#是否启用Bayesian自动学习功能?
auto_learn 1
#略过RBLs之检查
skip_rbl_checks 0
#是否使用Razor version 2
use_razor2 1
#是否使用DCC (Distributed Checksum Clearinghouse)
use_dcc 1
#是否使用Pyzor
use_pyzor 1
#是否在邮件表头中加入DCC资讯
dcc_add_header 1
#是否能够进行DNS查询。直接设定为yes将有效加快amavis的启动速度。
#设定值:(yes|no|test)
dns_available yes
#检查是否为由内部网路所寄出的信件。
#若是,则永远不判断为垃圾邮件。 (评分减50分)
#其中的example.net请替换成您的Domain Name...
header LOCAL_RCVD Received =~ /.*\(\S+\.example\.net\s+\[.*\]\)/
describe LOCAL_RCVD Received from local machine
score LOCAL_RCVD -50
#一些自订的规则
body WINDOWOPEN /window\.open\(/i
describe WINDOWOPEN JavaScript. Windows.Open
score WINDOWOPEN 3.5
#垃圾邮件计分规则。
## Optional Score Increases
score DCC_CHECK 4.000
score RAZOR2_CHECK 2.500
score BAYES_99 4.300
score BAYES_90 3.500
score BAYES_80 3.000
# Disabled scores #防止中文主旨和中文收件者误判,建议再加上下列几行
score HEADER_8BITS 0
score HTML_COMMENT_8BITS 0
score SUBJ_FULL_OF_8BITS 0
score UPPERCASE_25_50 0
score UPPERCASE_50_75 0
score UPPERCASE_75_100 0
# local domain from but ip not match #网域和ip不符,疑似为垃圾信件
header __FROM_TEATIME Received =~ /from 4wei.us/i
header __FROM_TEATIME_IP Received =~ /\[88\.88\.88\.20\]/
meta FROM_TEATIME_BUT_IP_ERROR (__FROM_TEATIME)
describe FROM_TEATIME_BUT_IP_ERROR From 4wei.us but ip not match
score FROM_TEATIME_BUT_IP_ERROR 8
设定SpamAssassin和Postfix搭配使用
Postfix与外部过滤程序的通讯有两种方式:基于命令的过滤(即以下所说的"一般做法"),以及基于守护进程的过滤(即以下的"建议做法")。
对于前者,Postfix每处理一封邮件,过滤命令就被启动一次,并且过滤程序还必须调用一次Sendmail,将完成过滤的邮件送回Postfix,所以运算成本比较高。
相对于实时地启动外部过滤程序,基于守护进程的过滤显然在I/O与CPU使用方面比较经济,不必每处理一封邮件就多创建一个新的进程,并且基于守护进程的过滤与Postfix之间的交互架构也比较先进,双方使用标准的SMTP或LMTP协议交换邮件。
=== spamd/spamd模式(一般做法)===
修改/etc/default/spamassassin,将其中的ENABLED=0改为ENABLED=1,以启动spamd:
# /etc/default/spamd.conf
# Duncan Findlay
# WARNING read README.spamd before using. THERE ARE SECURITY RISKS!
# Change to one to enable spamd
ENABLED = 1
# Options
# See man spamd for possible options. The -d option is automatically added.
OPTIONS="-c -m 10 -a -H"
# Set nice level of spamd
#NICE="--nicelevel 15"
注:也可以在此使用-u参数来指定启用SpamAssassin Daemon的帐号, 但由于SpamAssassin Daemon会su成Client帐号来过滤垃圾邮件, 因而并无此必要...
修改/etc/postfix/master.cf如下,告知Postfix使用SpamAssassin来扫描邮件内容:(其中的spamassassin字串可以自订)
(上略)
# ================================================= =========================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ================================================= =========================
smtp inet n - n - - smtpd -v
-o content_filter=spamassassin
(下略)
并再修改/etc/postfix/master.cf,加入以下内容:
(在此是设定spamassassin的内容。详细参数请参考man spamc及man sendmail之说明。)
注意,一般是以nobody身份来启动SpamAssassin,但在此例中是以amavis的身份来呼叫SpamAssassin的!
spamassassin unix - n n - - pipe
flags=Rq user=amavis argv=/usr/bin/spamc -d 127.0.0.1 -f -p 783 -t 30 -e /usr/sbin/sendmail -oi -f ${sender} -- ${recipient}
因为,若以nobody身份来启动SpamAssassin时,往往会因为nobody的Home Directory不存在,因而在/var/log/mail.log中将出现类似以下的错误讯息:
Oct 30 13:21:47 qemu spamd[788]: info: setuid to nobody succeeded
Oct 30 13:21:47 qemu spamd[788]: Creating default_prefs [/nonexistent/.spamassassin/user_prefs]
Oct 30 13:21:47 qemu spamd[788]: Cannot write to /nonexistent/.spamassassin/user_prefs: No such file or directory
Oct 30 13:21:47 qemu spamd[788]: Couldn't create readable default_prefs for [/nonexistent/.spamassassin/user_prefs]
所以改由以amavis身份来启动SpamAssassin。
修改完毕后,使用以下指令来启动SpamAssassin并重新启动Postfix:
/etc/init.d/spamassassin start
/etc/init.d/postfix restart
在预设上,spamd会监听783这个Port。
另外,SpamAssassin可以使用sa-learn指令来学习新的垃圾邮件规则,请参考AntiSpam with Bayesian Classifier一章之说明。
===利用Amavisd-new来呼叫SpamAssassin(建议做法)===
我们可以替而使用Amavisd-new来呼叫SpamAssassin,也就是让Amavisd-new肩负扫毒及过滤垃圾邮件的重责。而在本人的系统中,这个方法比起使用spamc/spamd的做法快上了非常多,所以建议采用这种作法。
请修改/etc/amavis/amavisd.conf如下:
(注:/etc/amavis/amavisd.conf的内容很大,以下只节录必须修改的项目)
#在@bypass_spam_checks_acl = qw( . );前加上注解,让Amavisd-new启动SpamAssassin
# Any setting can be changed with a new assignment, so make sure
# you do not unintentionally override these settings further down!
# @bypass_spam_checks_acl = qw( . ); # No default dependency
#不要移去SpamAssassin所加入的Headers,但似乎是没有作用?
#$remove_existing_spam_headers = 0; # leave existing X-Spam* headers alone
$remove_existing_spam_headers = 0; # remove existing spam headers if
# spam scanning is enabled (default)
#让SpamAssassin可以和外部连线
# $sa_local_tests_only is passed to Mail::SpamAssassin::new as a value
# of the option local_tests_only. See Mail::SpamAssassin man page.
# If set to 1, SA tests are restricted to local tests only, ie no tests
# that require internet access will be performed.
#
$sa_local_tests_only = 0; # (default: false)
#启用自动的White List
$sa_auto_whitelist = 1; # turn on AWL (default: false)
#设定White List
#注意:在/etc/spamassassin/local.cf所设定的将失去效用!
map { $whitelist_sender{lc($_)}=1 } (qw(
[email protected]
));
#或指定为某个档案。注意:这些档案必须存在,否则Amavisd-new将无法启动!
read_hash(\%whitelist_sender, '/var/lib/amavis/whitelist');
#指定黑名单
read_hash(\%blacklist_sender, '/var/lib/amavis/blacklist');
#若收件人名列其中,则不进行垃圾邮件检测
read_hash(\%spam_lovers, '/var/lib/amavis/spam_lovers');
#超过某个特定大小的邮件可以不经过SpamAssassin的扫瞄
$sa_mail_body_size_limit = 150*1024; # don't waste time
#设定评分规则。
# default values, can be overridden by more specific lookups, eg SQL
#超过这个标准者,就在邮件标头加入Spam资讯
$sa_tag_level_deflt = 4.0; # add spam info headers if at, or above that level
#超过这个标准者,就直接视为垃圾邮件
$sa_tag2_level_deflt = 6.3; # add 'spam detected' headers at that level
#超过这个标准者,就直接将信件备份后删除。
$sa_kill_level_deflt = 10 ; # triggers spam evasive actions
# at or above that level: bounce/reject/drop,
# quarantine, and adding mail address extension
#启用SpamAssassin的Debug。在正式上线时请记得去掉!
# Turn on SpamAssassin debugging (output to STDERR, use with 'amavisd debug')
$sa_debug = 1; # defaults to false
然后重新启动Amavisd-new即可。
若因任何原因而无法启动Amavisd-new,可以使用以下指令来进行Debug:
amavisd-new debug-sa
测试SpamAssassin
在安装SpamAssassin时,也同时会附上测试用的Spam范例档。您可以用以下指令来测试SpamAssassin是否能够正确运作了:
spamassassin -t < /usr/share/doc/spamassassin/examples/sample-spam.txt
寄封测试用的垃圾邮件吧:
# telnet 127.0.0.1 25
Connected to 127.0.0.1.
Escape character is '^]'.
220 qemu ESMTP Postfix (Debian/GNU)
MAIL FROM:<[email protected]>
250 Ok
RCPT TO:<tetralet>
250 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Test spam mail (GTUBE)
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
.
250 Ok: queued as 0C3E9C906B
quit
221 Bye
Connection closed by foreign host.
看看这封邮件是否真的被判定为垃圾邮件了:
From [email protected] Fri Oct 22 16:50:46 2004
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: by qemu (Postfix, from userid 65534)
id 7ACB8C9073; Fri, 22 Oct 2004 16:50:46 +0800 (CST)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by qemu (Postfix) with SMTP id 9D7C0C9063
for <tetralet>; Fri, 22 Oct 2004 16:50:18 +0800 (CST)
Subject: *****SPAM***** Test spam mail (GTUBE)
Message-Id: <20041022085018.9D7C0C9063@qemu>
Date: Fri, 22 Oct 2004 16:50:18 +0800 (CST)
From: [email protected]
To: undisclosed-recipients: ;
X-Spam-DCC: :
X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) http://razor.sf.net/">http://razor.sf.net/)
* -100 USER_IN_WHITELIST From: address is in the user's white-list
* 3.3 MSGID_FROM_MTA_SHORT Message-Id was added by a relay
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
如果一切没问题,那就大功告成啰∼∼
注: 上面的是别人写的,下面我会放出我的local.cf配置文件出来,供给大家参考。
为 SpamAssassin 添加过滤规则
接下来我们需要下载一些过滤规则,创建 /usr/local/sbin/sa_rules_update.sh
内容为:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# export http_proxy=http://your.proxy.server
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/71_s ... re3.0.0.cf -O 71_sare_redirect_pre3.0.0.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_s ... son_nxm.cf -O 70_sare_bayes_poison_nxm.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_html.cf -O 70_sare_html.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_html4.cf -O 70_sare_html4.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_html_x30.cf -O 70_sare_html_x30.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_header0.cf -O 70_sare_header0.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_header3.cf -O 70_sare_header3.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_s ... der_x30.cf -O 70_sare_header_x30.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_specific.cf -O 70_sare_specific.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_adult.cf -O 70_sare_adult.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/72_s ... post25x.cf -O 72_sare_bml_post25x.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/99_s ... post25x.cf -O 99_sare_fraud_post25x.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_spoof.cf -O 70_sare_spoof.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_random.cf -O 70_sare_random.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_oem.cf -O 70_sare_oem.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_genlsubj0.cf -O 70_sare_genlsubj0.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_genlsubj3.cf -O 70_sare_genlsubj3.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_s ... ubj_x30.cf -O 70_sare_genlsubj_x30.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_unsub.cf -O 70_sare_unsub.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/70_sare_uri.cf -O 70_sare_uri.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://mywebpages.comcast.net/mkettler/sa/antidrug.cf -O antidrug.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.timj.co.uk/linux/bogus-virus-warnings.cf -O bogus-virus-warnings.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.yackley.org/sa-rules/evilnumbers.cf -O evilnumbers.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.stearns.org/sa-blacklist/random.current.cf -O random.current.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/88_FVGT_body.cf -O 88_FVGT_body.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/88_FVGT_rawbody.cf -O 88_FVGT_rawbody.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/88_FVGT_subject.cf -O 88_FVGT_subject.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/88_FVGT_headers.cf -O 88_FVGT_headers.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/88_FVGT_uri.cf -O 88_FVGT_uri.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/99_FVGT_Tripwire.cf -O 99_FVGT_Tripwire.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.rulesemporium.com/rules/99_FVGT_meta.cf -O 99_FVGT_meta.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.nospamtoday.com/download/mime_validate.cf -O mime_validate.cf &> /dev/null
cd /usr/share/spamassassin/ &> /dev/null && /usr/bin/wget http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf -O Chinese_rules.cf &> /dev/null
/etc/init.d/amavis restart &> /dev/null
exit 0
然后,执行它
chmod 755 /usr/local/sbin/sa_rules_update.sh
cd /etc/spamassassin
/usr/local/sbin/sa_rules_update.sh
你还可以加入计划任务中,让它每天自动执行,例如,执行 crontab -e,然后创建如下任务
10 4 * * * /usr/local/sbin/sa_rules_update.sh &> /dev/null
这样每天早上 4 点 10 分,就会自动下载更新这些过滤规则了
我们再来编辑/etc/spamassassin/v310.pre
我们把 #loadplugin Mail::SpamAssassin::Plugin::DCC
前的“#”给去掉
然后重置spamassassin 请执行
spamassassin --lint
然后重新启动 Amavisd-new:
/etc/init.d/amavis restart
注意这里不是启动 spamassassin,因为 spamassassin 以及配置为由 Amavisd-new 来调用了。
再更新我们的SpamAssassin
sa-update --no-gpg
为了让它以后能够自动更新,我们要做这样两步
执行下面的建一个脚本
crontab -e
把下面的代码复制
20 4 * * * /usr/bin/sa-update --no-gpg &> /dev/null
按ctrl+o 来保存,按ctrl+x来退出
这样每天早上 4 点 20 分,就会自动下载更新。
安装 Spam Locker 反垃圾邮件
在 ubuntu 上安装 Spam Locker 比较简单了,大部分 perl 包在上面已经安装了。
我们从www.extmail.org下载最新的 slockd-0.99.tar.gz 我们将它解压,并放到/usr/local下面
tar zxvf slockd-0.99.tar.gz
mv slockd /usr/local/slockd
然后编辑 /usr/local/slockd/config/main.cf,将
setsid 1
log_file /var/log/slockd.log
两行前面的注释去掉。
将 /usr/local/slockd/slockd-init 复制到 /etc/init.d 目录下,然后建立启动关闭服务的链接文件:
cp /usr/local/slockd/slockd-init /etc/init.d/slockd
update-rc.d slockd start 19 2 3 4 5 . stop 21 0 1 6 .
创建 /etc/logrotate.d/slockd
/var/log/slockd.log {
daily
notifempty
missingok
rotate 5
compress
create 644 root root
sharedscripts
}
然后,编辑 /usr/local/slockd/config/whitelist,加入你的白名单列表。之后启动 slockd 服务。
/etc/init.d/slockd start
编辑 /etc/postfix/main.cf,将
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_sender_domain, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, check_recipient_maps
中的
check_recipient_maps
替换为
check_policy_service inet:127.0.0.1:10030
即可。然后重新启动 Postfix。
/etc/init.d/postfix reload
启动/测试 slockd
在/usr/local/slockd目录下,执行
./slockd
此时slockd将启动,并进入监听模式,接受来自10030端口的请求,要注意的是,如果刚才配置了log_file路径,则调试信息必须通过如下命令获得:
tail -f /var/log/slockd.log
打开另一个ssh/终端窗口,进入/usr/local/slockd/tools 目录,输入:
perl policy_sig -h localhost -p 10030 --helo FOOBAR \
--ip 192.168.0.1 --from [email protected] --to [email protected]
此时,程序应该返回如下错误信息:
action=504 <FOOBAR>: rejected, see http://bl.extmail.org/cgi/why?fqdn
这表示slockd初步的正常工作了。
ps 先看一下 spam lock 的进程还有没有
ps aux |grep slockd
会有如下显示
root 20821 1.9 5.1 48736 19708 ? S 13:19 0:08 gedit /usr/local/slockd/config/whitelist
root 21005 0.0 1.1 7592 4344 ? SNs 13:20 0:00 slockd (master)
root 21007 0.0 1.8 11636 7084 ? SN 13:20 0:00 slockd (idle)
root 21014 0.0 1.8 11612 7068 ? SN 13:20 0:00 slockd (idle)
root 21047 0.0 0.2 3560 820 pts/1 S+ 13:26 0:00 grep slockd
如果你想监视postfix发去和接收所有的邮件,请在main.cf中加入
always_bcc = 你的邮件地址
文章到这里就己经讲完了,如果有更好的修改建议,请到论坛上加以修改。