# make install //安装程序会提问一些问题,可以直接按回车采用默认值。
# make upgrade //如果以后升级postfix采用改命令
# vi /etc/profile //把屏蔽的环境变量重新启用
# init 6 //重新启动系统
给postfix用户做一个系统别名,并将超级用户的邮箱转发到一个普通用户如admin。使用/etc/postfix/aliases别名数据库:
# cd /etc/postfix
# vi aliases //内容如下
MAILER-DAEMON: postmaster
postmaster: root
root: admin@mydomain.com
bin: root
daemon: root
named: root
nobody: root
uucp: root
www: root
ftp-bugs: root
postfix: root
# manager: root
dumper: root
operator: root
abuse: postmaster
这样admin@mydomain2.com这个用户就是邮件系统管理员用户,禁止掉manager,因为要使用这个邮件帐号,所以再这要禁止掉.
生成/etc/postfix/aliases别名数据库:
# postalias /etc/postfix/aliases //Linux或者BSD使用这个
# postalias dbm:/etc/postfix/aliases //Solaris不支持默认的hash,要使用dbm格式
生成/etc/postfix/virtual的DB库:
# postmap dbm:/etc/postfix/virtual
注意:保留db格式的virtual库是为了系统临时增加转发方便起见.
2.配置Postfix
A.修改/etc/postfix/master.cf中的关于maildrop的配置:
# vi master.cf //将下面两行
maildrop unix - n n - - pipe
flags=DRhu user=wmail argv=/usr/local/bin/maildrop -d ${recipient}
更改为:
maildrop unix - n n - - pipe
flags=DRhu user=maildrop argv=/usr/local/bin/maildrop -w 90 -d $(recipient)
注意: 这里要把maildrop的路径修改为上面安装的maildrop实际安装路径,用户maildrop是我们上面添加过的,记着flags=...这行前面 是以空格缩进的.-w 90参数是定义当用户的邮箱达到限额的90%时有提示信息!
B.修改/etc/postfix/main.cf的配置
# vi /etc/postfix/main.cf //修改配置如下:
#=====================BASE=========================
myhostname = mail.mydomain.com
smtpd_banner = Welcome to C&WIT Mail Service System! //登录欢迎信息
mydomain = mydomain.com //域名
myorigin = $mydomain //支持的虚拟域
mydestination = $mydomain,mydomain2.com //允许接收的域
mynetworks_style = host
smtp_helo_name = mail.mydomain.com //发送邮件使用的helo地址
home_mailbox = Maildir/ //使用的邮箱格式
local_recipient_maps =
alias_maps = dbm:/etc/postfix/aliases
alias_database = dbm:/etc/postfix/aliases
mailbox_transport = maildrop
fallback_transport = maildrop
#====================MYSQL=======================
virtual_maps = dbm:/etc/postfix/virtual,mysql:/etc/postfix/virtual.mysql
virtual_mailbox_base = / //指定用户邮箱所在的根目录
virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf //指定用户邮箱的目录
virtual_gid_maps = mysql:/etc/postfix/mysql-gids.cf //用户gid
virtual_uid_maps = mysql:/etc/postfix/mysql-uids.cf //用户uid
#====================QUOTA========================
message_size_limit = 20971520 //限制每次发邮件的大小为20M
virtual_mailbox_limit = 102400000 //默认的邮箱大小
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql-quota.cf //每个用户的邮箱大小
virtual_mailbox_limit_override = yes //是否允许覆盖默认邮箱的大小
virtual_create_maildirsize = yes
#====================SASL========================
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
#====================FILTER=======================
smtpd_recipient_restrictions =
permit_mynetworks, //使用TAB键
permit_sasl_authenticated,
check_recipient_access mysql:/etc/postfix/filter.mysql,
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
如果希望支持更多的虚拟域,可以在mydestination参数后面加上你所要支持的域即可.
通过virtual和virtual.mysql为系统提供了邮箱本地查询表.
在上面的配置文件里面使用了SASL来进行SMTP发信认证.
通过smtpd_recipient_restrictions提供了基本的反垃圾邮件功能.首先允许本地网络(这里是本机)和通过SASL认证的用户可以使用 本服务器发信;然后检查每个用户的全局邮件过滤功能是否打开,如果关闭则不进行后面的反垃圾邮件检查;其后是一些Postfix支持的基本反垃圾邮件功能.
C.创建/etc/postfix/virtual.mysql
它提供了本地用户和邮件转发功能,FORWARD字段默认是指向用户的存储邮箱名的(Courier-IMAP所管理的邮箱名称),即进行本地投递;
如果FORWARD字段是另外一个用户名或者邮件地址,则该邮件被转发到别的用户或其它邮件地址.
# vi virtual.mysql
#
# mysql config file for alias lookups on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = FORWARD
where_field = USERNAME
additional_conditions = and STATUS = 1 limit 1
D.创建/etc/postfix/filter.mysql
# vi filter.mysql
#
# mysql config file for filter flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
# OK : ignore filter
# DUNNO : filter
select_field = FILTER
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
E.创建/etc/postfix/mysql-maildir.cf
# vi mysql-maildir.cf
#
# mysql config file for maildir lookups on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = HOMEDIR
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
F.创建/etc/postfix/mysql-quota.cf
# vi mysql-quota.cf
#
# mysql config file for quota flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = QUOTA
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
G.创建/etc/postfix/mysql-uids.cf
# vi mysql-uids.cf
#
# mysql config file for uid flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = UID
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
H.创建/etc/postfix/mysql-gids.cf
# vi mysql-gids.cf
#
# mysql config file for gid flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = GID
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
3.设置域转发
添加数据库
# vi transport.sql
use mail;
CREATE TABLE transport (
id int(11) unsigned NOT NULL auto_increment,
domain varchar(255) NOT NULL default '',
transport varchar(255) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY domain (domain)
) TYPE=MyISAM;
INSERT INTO transport (domain,transport)
VALUES ('mydomain2.com','mydomain.com');
# /usr/local/mysql/bin/mysql -u root -p < transport.sql
在/etc/postfix/main.cf中添加:
transport_maps = mysql:/etc/postfix/mysql-transport.cf
创建mysql-transport.cf文件
# vi mysql-transport.cf
#
# mysql config file for transport flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = password
# the database name on the servers
dbname = mail
# the table name
table = transport
select_field = transport
where_field = domain
4.测试Postfix
# /usr/sbin/postfix start //启动postfix,如果出错,可以查看/var/log/syslog
# netstat -an | grep LISTEN //应该有25端口在监听
如果不在25端口监听,使用以下命令启动postfix
# telnet localhost 25 //如果有以下提示,说明认证成功
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 Welcome to C&WIT Mail Service System!
ehlo peijun //手工输入,如果能成功打印出一下信息,说明成功
250-mail.mydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME
quit //输入该命令退出
八.安装Courier-IMAP
1.安装Courier-IMAP
# wgetftp://ftp.sunfreeware.com/pub/freeware/sp...-sparc-local.gz
# gunzip gdbm-1.8.3-sol9-sparc-local.gz //安装gdbm,以备后用
# pkgadd -d gdbm-1.8.3-sol9-sparc-local
# wgetftp://ftp.sunfreeware.com/pub/freeware/sp...-sparc-local.gz
# gunzip openssh-3.8p1-sol9-sparc-local.gz
# pkgadd -d openssh-3.8p1-sol9-sparc-local
# ln -s /usr/local/ssl/include/openssl /usr/include/openssl
# wgethttp://umn.dl.sourceforge.net/sourceforge/...p-2.2.1.tar.bz2
# bunzip2 courier--imap-2.2.1.tar.bz2
# gtar vxf courier-imap-2.2.1.tar.bz2
# ./configure \
--prefix=/usr/local/courier \
--enable-unicode=utf-8,iso-8859-1,gb2312 \
--with-mysql-libs=/usr/local/mysql/lib/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql \
--with-authmysql=yes \
--with-authchangepwdir \
--disable-root-check \
--with-trashquota \
--with-dirsync
--with-db=gdbm //不能使用db方式,即使安装上了db也会出问题
# make
# make install-strip
# make install-configure
2.设置Courier-IMAP
设置启动文件,如果你要同时使用pop3d和imapd服务可以这样设置,如果只使用pop3d服务,跳过该步骤:
# cp courier-imap.sysvinit /etc/init.d/courier
# ln -s /etc/init.d/courier /etc/rc3.d/S90courier
# ln -s /etc/init.d/courier /etc/rc0.d/K90courier
编译使用Mysql认证模块:
# cd /usr/local/courier/etc/
# vi authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
version="authdaemond.mysql"
修改Mysql认证模块配置文件:
# vi authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME mail
MYSQL_PASSWORD password
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 3306
MYSQL_DATABASE mail
MYSQL_USER_TABLE USER
MYSQL_CRYPT_PWFIELD PASSWORD
MYSQL_CLEAR_PWFIELD CLEAR_PASSWORD
MYSQL_UID_FIELD UID
MYSQL_GID_FIELD GID
MYSQL_LOGIN_FIELD USERNAME
MYSQL_HOME_FIELD HOMEDIR
MYSQL_NAME_FIELD USERNAME
MYSQL_MAILDIR_FIELD MAILDIR
MYSQL_QUOTA_FIELD QUOTA
MYSQL_WHERE_CLAUSE STATUS=1
修改POP3配置文件pop3d,使其能自动启动:
# vi pop3d
POP3DSTART=YES
修改IMAP配置文件imapd,使其能自动启动(如果不使用IMAP服务,跳过该项操作):
# vi imapd
IMAPDSTART=YES
注意:本文章只使用pop3的服务,所以具体的启动文件设置按照一下方法:
3.运行测试
# cd /usr/local/courier/libexec
# ln -s pop3d.rc pop3d
# cp pop3d /etc/init.d/pop3d
# ln -s /etc/init.d/pop3d /etc/rc3.d/S90pop3d
# ln -s /etc/init.d/pop3d /etc/rc0.d/K90pop3d
启动pop3d服务:
# /etc/init.d/pop3d start
# ps -ef //应该可以看到authdaemond.mysql和pop3d进程已经启动
# netstat -an | grep LISTEN //应该可以看到110端口已经在监听
4.建立目录
# mkdir -p /mail/domains
# mkdir -p /mail/domains/mydomain.com
# mkdir -p /mail/domains/mydomain2.com
# mkdir -p /mail/domains/mydomain.com/admin
# mkdir -p /mail/domains/mydomain2.com/test
# /usr/local/courier/bin/maildirmake /mail/domains/mydomain.com/admin/Maildir
# /usr/local/courier/bin/maildirmake /mail/domains/mydomain2.com/test/Maildir
# chmod -R 700 /mail/domains/mydomain.com
# chmod -R 700 /mail/domains/mydomain2.com
# chown -R maildrop:maildrop /mail/domains/mydomain.com
# chown -R maildrop:maildrop /mail/domains/mydomain2.com
此时使用客户端程序Outlook或者Foxmail就可以对添加的用户user和虚拟域用户viruser进行收发测试.
九.建立邮件列表
# cd /etc/postfix
# vi main.cf
修改alias_maps,alias_database为:
alias_maps = dbm:/etc/postfix/aliases,dbm:/etc/postfix/maillist
alias_database = dbm:/etc/postfix/aliases,dbm:/etc/postfix/maillist
# postfix reload
# touch mail-list
# vi maillister
cwi_staff: 11@sohu.com 22@sohu.com 33@sohu.com
# postalias dbm:/etc/postfix/mail-list //记住,每次修改maillist文件都要执行一次该项操作!
这时候,当发往staff@mydomain2.com的邮件,11@sohu.com/22@sohu.com/33@sohu.com就都可以收到了.
十.安装Clamav
1.下载
# wgethttp://download.sourceforge.net/clamav/cla...mav-0.65.tar.gz
2.添加用户和组
# groupadd clamav //添加组
# useradd -g clamav -d /nonexistent -c "Clam Antivirus" clamav //添加用户
3.安装
# gtar zxvf clamav-0.65.tar.gz
# cd clamav-0.65
# ./configure
# make install
4.测试
# clamscan --recursive --log=/tmp/clamscan.log ./ //扫描当前目录,并讲扫描结果保存在/tmp/clamscan.log中
# cat /tmp/clamscan.log //查看扫描情况
5.升级病毒库
# freshclam --verbose
6.创建日志记录文件
# touch /var/log/freshclam.log
# chmod 644 /var/log/freshclam.log
# chown clamav:clamav /var/log/freshclam.log
7.创建自动更新任务
# vi /var/spool/cron/crontabs/root
0 8 * * * /usr/local/bin/freshclam --quiet -l /var/log/freshclam.log
8.创建自动启动脚本
# vi /etc/init.d/clamd
#!/bin/sh
#
# Startup / shutdown script for Clam Antivirus
case "$1" in
start)
/usr/local/sbin/clamd
echo -n 'clamd'
;;
stop)
pkill clamd
rm /var/amavis/clamd/clamav.socket
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
# ln -s /etc/init.d/clamd /etc/rc3.d/S90clamd
# ln -s /etc/init.d/clamd /etc/rc0.d/K90clamd
9.修改配置文件
# vi /usr/local/etc/clamav.conf
# Example //在前面加上#屏蔽该项,不然无法启动.
LogFile /var/log/freshclam.log
LogFileMaxSize 2M
LogTime
LogVerbose
PidFile /var/run/clamd.pid
DataDirectory /usr/local/share/clamav
LocalSocket /var/amavis/clamd/clamav.socket
User root
ScanMail
ClamukoMaxFileSize 10M
十一.安装Spamassassin
1.安装
# perl -MCPAN -e shell
cpan>install Mail::SpamAssassin
2.建立maildrop过滤脚本(如果你使用amavisd-new来对spamassassin进行操作的话,跳过该项)
# vi /etc/maildroprc
if ( $SIZE < 26144 )
{
exception {
xfilter "/usr/bin/spamassassin"
}
}
if (/^X-Spam-Flag: *YES/)
{
exception {
to "$HOME/$DEFAULT/.Spam/"
}
}
else
{
exception {
to "$HOME/$DEFAULT"
}
}
3.配置Spamassassin
A.建立自学习系统
# sa-learn --dump all
# sa-learn --dump all //可以查看自学习的数据信息
B.定义过滤模板
# vi /etc/mail/spamassassin/local.cf
required_hits 5.0
# Whether to change the subject of suspected spam
rewrite_subject 1
# Text to prepend to subject if rewite_subject is used
subject_tag ********SPAM********
# Encapsulate spam in an attachment
report_safe 1
# Keep HTML messages intact
defang_mime 0
# Do not add the "*****SPAM*****" prefix to the subject line
rewrite_subject 0
# Use "report headers", which turns off the body reporting for tagged e-mail
report_header 1
# Reduce some of the superfluous explanations in the report:
use_terse_report 1
# Enable the Bayes system
use_bayes 1
# Enable Bayes auto-learning
#auto_learn 1
bayes_auto_learn 1
bayes_min_ham_num 500
bayes_min_spam_num 500
bayes_auto_learn_threshold_nonspam 1.0
bayes_auto_learn_threshold_spam 9.0
# Enable or disable network checks
skip_rbl_checks 0
use_razor2 1
use_dcc 1
use_pyzor 1
# Whitelist
whitelist_from *@mydomain.com *@mydomain2.com
# Mail using languages used in these country codes will not be marked
# as being possibly spam in a foreign language
# - chinese english
ok_languages zh en
# Mail using locales used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_locales en zh
###################################
# Follow is check CBL
# URL:http://www.anti-spam.org.cn/
###################################
header RCVD_IN_CBL eval:check_rbl('cblplus', 'cblplus.anti-spam.org.cn.')
describe RCVD_IN_CBL Received via a relay in cblplus.anti-spam.org.cn
tflags RCVD_IN_CBL net
header RCVD_IN_CBL_DIALUP eval:check_rbl('cdl-notfirsthop', 'cdlplus.anti-spam.org.cn.', '127.0.8.4')
describe RCVD_IN_CBL_DIALUP CBL: dialup sender did non-local SMTP
tflags RCVD_IN_CBL_DIALUP net
#SCORE
score RCVD_IN_CBL 2.0
score RCVD_IN_CBL_DIALUP 1.5
######################################
C.设置SBL/BBL/EMBL过滤列表
# cd /usr/local/share/spamassassin
# wgethttp://anti-spam.org.cn/rules/sa/55_diy_score.cf
十二.安装amavisd-new
1.下载
# wgethttp://www.ijs.si/software/amavisd/amavisd...30616-p8.tar.gz
2.必须的软件
bzip2-1.0.2-sol9-sparc-local.gz //前面已经安装过
arc-5.21e-sol9-sparc-local.gz
gzip-1.3-sol9-sparc-local.gz //前面已经安装过
3.安装perl模块
# perl -MCPAN -e shell
cpan>install CPAN
cpan>install Bundle::CPAN
cpan>install Time::HiRes
cpan>install File::Spec
cpan>install Getopt::Long
cpan>install Net::Cmd
cpan>install Net::Ping
cpan>install Net::DNS
cpan>install File::Copy
cpan>install Digest::Nilsimsa
cpan>install URI::Escape
cpan>install Digest::SHA1
cpan>install Unix::Syslog
cpan>install Convert::UUlib
cpan>install Convert::TNEF
cpan>install Compress::Zlib
cpan>install Archive::Tar
cpan>install Archive::Zip
cpan>install G/GB/GBARR/MailTools-1.15.tar.gz
cpan>install MIME::Tools
cpan>install Net::Server
cpan>install Net::Server::PreForkSimple
4.安装
# gtar zxvf amavisd-new-20030616-p8.tar.gz
# cd amavisd-new-20030616-p8
# groupadd amavis
# useradd -g amavis -s /bin/false -c "Amavis User" -d /var/amavis amavis
# mkdir -p /var/amavis/clamd
# chown -R amavis:amavis /var/amavis
# chmod -R 750 /var/amavis/
# cp amavisd /usr/local/sbin/
# ln -s /usr/local/sbin/amavisd /usr/sbin/amavisd
# cp amavisd.conf /etc/
# mkdir /var/virusmails
# chown amavis:amavis /var/virusmails
# /usr/local/sbin/amavisd debug //测试amavisd-new
# vi /etc/init.d/amavisd //创建amavisd-new的启动脚本
#!/bin/sh
#
# Startup / shutdown script for Amavisd-NEW
case "$1" in
start)
/usr/local/sbin/amavisd
echo -n 'amavisd'
;;
stop)
pkill amavisd
rm /var/amavis/amavisd.sock
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
# ln -s /etc/init.d/amavisd /etc/rc3.d/S90amavisd
# ln -s /etc/init.d/amavisd /etc/rc0.d/K90amavisd
5.设置
# vi /etc/amavisd.conf
$MYHOME = '/var/amavis'; //设置目录
$mydomain = 'mydomain.com'; //设置邮件域
$daemon_user = 'amavis'; //设置运行的用户
$daemon_group = 'amavis'; //设置运行的组
$QUARANTINEDIR = '/var/virusmails'; //设置病毒邮件存放的目录
$log_level = 0; //设置日志记录等级
$final_virus_destiny = D_DISCARD; //设置对病毒邮件处理的方式(D_DISCARD表示丢弃,D_BOUNCE表示后来弹回信息, D_REJECT表示当时弹回信息,D_PASS表示允许通过)
$final_banned_destiny = D_BOUNCE; //不是很清楚
$final_spam_destiny = D_DISCARD; //设置对垃圾邮件处理的方式
$final_bad_header_destiny = D_PASS; //设置对不规范的邮件头格式的处理方式
$sa_spam_subject_tag = '***SPAM***'
$virus_admin = "admin\@$mydomain";
$mailfrom_notify_admin = "admin\@$mydomain";
$mailfrom_notify_recip = "admin\@$mydomain";
$mailfrom_notify_spamadmin = "admin\@$mydomain";
['Clam Antivirus-clamd',
\&ask_daemon, ["CONTSCAN {}\n", '/var/amavis/clamd/clamav.socket'],
qr/\bOK$/, qr/\bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
6.启动
# amavisd debug
# /etc/init.d/amavisd start
7.设置postfix
A.修改/etc/postfix/main.cf
# vi /etc/postfix/main.cf //加入一下行
content_filter = smtp-amavis:127.0.0.1:10024
B.修改/etc/postfix/master.cf
# vi /etc/postfix/master.cf //在最后加上
# amavisd-new
smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
localhost:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o mynetworks=127.0.0.0/8
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
c.重新启动postfix
# postfix reload
# netstat -an | grep LISTEN //应该可以看到这两个端口在监听
127.0.0.1.10024 *.* 0 0 49152 0 LISTEN
127.0.0.1.10025 *.* 0 0 49152 0 LISTEN
注意:如果发现amavisd进程自动停止的话,更改以下参数可以解决:
(1) # vi /etc/amavisd.conf
$max_servers = 2;
$max_requests = 10;
更改为:
$max_servers = 10;
$max_requests = 50;
(2) # vi /etc/postfix/master.cf
smtp-amavis unix - - n - 2 smtp
更改为:
smtp-amavis unix - - n - 10 smtp
然后重新启动postfix和amavisd即可!
8.测试
1.测试病毒扫描
# /etc/init.d/clamd start
使用其他邮件系统用户给该系统的用户发送邮件,内容包含一下内容:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
如果这个用户能够收到有病度提示的邮件说明病毒过滤已经成功!
邮件病毒扫描日志将被记录在/var/log/clamav.log中!
2.测试垃圾邮件扫面
使用其他邮件系统用户给该系统的用户发送邮件,然后查看系统日志
# cat /var/log/syslog
Apr 4 21:16:11 mail.mydomain.com amavis[694]: [ID 702911 mail.info] (00694-01) Passed,
如果有以上类似的信息,说明垃圾扫描功能已经成功.Hits: 1.29表示spamassassin给该邮件打的分数,如果超过5分将被视为垃圾邮件而 被系统丢弃.
十三.创建添加/删除用户脚本
1.创建添加用户脚本
# vi /sbin/addmailuser
#!/bin/sh
uid=450
gid=450
status=1
filter=DUNNO
quota=104857600
mysql_name=mail
mysql_password=password
echo 'Enter user name:'
read name
if [ "$name" = "" ]; then
echo 'Must input name!'
exit
fi
echo 'Enter user password:[123]'
read password
if [ "$password" = "" ]; then
password=123
fi
echo 'Enter user forward:['$name']'
read forward
if [ "$forward" = "" ]; then
forward=$name
fi
echo 'Enter user domain:[mydomain.com]'
read domain
if [ "$domain" = "" ]; then
domain=mydomain.com
fi
echo 'Enter user home:[/mail/domains/'$domain'/'$name']'
read home
if [ "$home" = "" ]; then
home=/mail/domains/$domain/$name
fi
echo 'Enter user Maildir:['$home'/Maildir]'
read maildir
if [ "$maildir" = "" ]; then
maildir=$home/Maildir
fi
echo 'name= '$name
echo 'password= '$password
echo 'forward= '$forward
echo 'domain= '$domain
echo 'home= '$home
echo 'maildir= '$maildir
echo 'status= '$status
echo 'filter= '$filter
echo 'quota= '$quota
echo "If under value is right,please input 'y' any Enter:"
read mychoice
if [ "$mychoice" = "y" ]; then
echo "use mail;" > tmp_addmailuser.sql
fi
echo "INSERT INTO USER (USERNAME,PASSWORD,CLEAR_PASSWORD,FORWARD,DOMAIN,HOMEDIR,MAILDIR,MAIL) VALUES ('$name','','$password','
$forward','$domain','$home','$maildir','$name@$domain');" >> tmp_addmailuser.sql
/usr/local/mysql/bin/mysql -u$mysql_name -p$mysql_password < tmp_addmailuser.sql
rm tmp_addmailuser.sql
MailUserDir=$home
mkdir -p $MailUserDir
/usr/local/courier/bin/maildirmake $MailUserDir/Maildir;chmod -R 700 $MailUserDir;chown -R maildrop:maildrop $MailUserDir
exit
fi
# chmod 755 /sbin/addmailuser
2.创建删除用户脚本
# vi /sbin/delmailuser
#!/bin/sh
uid=450
gid=450
status=1
filter=DUNNO
quota=104857600
mysql_name=mail
mysql_password=password
echo 'Enter user name:'
read name
if [ "$name" = "" ]; then
echo 'Must input name!'
exit
fi
echo 'Enter user domain:[mydomain.com]'
read domain
if [ "$domain" = "" ]; then
domain=mydomain.com
fi
echo "use mail;" > tmp_delmailuser.sql
echo "select USERNAME,DOMAIN,HOMEDIR,MAILDIR,MAIL from USER where (USERNAME='"$name"' and MAIL='"$name@$domain"' and DOMAIN='"
$domain"');" >> tmp_delmailuser.sql
/usr/local/mysql/bin/mysql -u$mysql_name -p$mysql_password < tmp_delmailuser.sql | grep $name@$domain > tmp_delmailuser
user=`awk '{ print $1 }' tmp_delmailuser`
mail=`awk '{ print $5 }' tmp_delmailuser`
home=`awk '{ print $3 }' tmp_delmailuser`
maildir=`awk '{ print $4 }' tmp_delmailuser`
if [ "$home" = "" ]; then
echo "No $name in $domain , please check and input again."
rm -rf tmp_delmailuser.sql
rm -rf tmp_delmailuser
exit
fi
echo 'name= '$name
echo 'domain= '$domain
echo 'mail= '$name@$domain
echo 'home= '$home
echo 'maildir= '$maildir
echo "if under value is right,please input 'y' and Enter:"
read mychoice
if [ "$mychoice" = "y" ]; then
echo "use mail;" > tmp_delmailuser.sql
echo "delete from USER where (MAIL='"$name@$domain"' and USERNAME='"$name"' and DOMAIN='"$domain"');" >> tmp_delmailuser.sql
/usr/local/mysql/bin/mysql -u$mysql_name -p$mysql_password < tmp_delmailuser.sql
rm -rf tmp_delmailuser.sql
rm -rf tmp_delmailuser
MailUserDir=$home
rm -rf $MailUserDir
exit
fi
# chmod 755 /sbin/delmailuser
十三.安装Apache2+PHP4
1.安装Apache2
下载httpd-2.0.47.tar.gz
卸载掉系统自带的apache
# pkgrm SUNWapchd
# pkgrm SUNWapchr
# pkgrm SUNWapchu
安装db-3.3.11-sol9-sparc-local,安装目录在/usr/local/BerkeleyDB.3.3.安装过db-1.85- sol9-sparc-local,但是老是make不过去,后来 安装了这个db的版本,指定lib和include后就可以了,原因未知!!!
# gunzip db-3.3.11-sol9-sparc-local.gz
# pkgadd -d db-3.3.11-sol9-sparc-local
# gtar zxvf httpd-2.0.47.tar.gz
# cd httpd-2.0.47
# CC=gcc CFLAGS="-O6" CXX=gcc CXXFLAGS="-O6 -felide-constructors -fno-exceptions -fno-rtti"
# CPPFLAGS="-I/usr/local/BerkeleyDB.3.3/include";export CPPFLAGS
# LDFLAGS="-L/usr/local/BerkeleyDB.3.3/lib";export LDFLAGS
# ./configure --prefix=/usr/local/apache --enable-module=so
# make
# make insatll
# cp /usr/local/BerkeleyDB.3.3/lib/* /usr/lib //否则启动apache会提示无法找到libdb-3.3.so模块,而且安装PHP的时候也提示apxs 模块不可用
# cp /usr/local/apache/bin/apachectl /etc/init.d/apache
# ln -s /etc/init.d/apache /etc/rc3.d/S90apache
# ln -s /etc/init.d/apache /etc/rc0.d/K90apache
# vi /usr/local/apache/conf/httpd.conf
Group #-1
更改为:
group nobody
# /etc/init.d/apache start
#http://YouIP/ //测试如果能看到Apache的欢迎页面,说明Apache已经安装成功
2.安装PHP4
下载php-4.3.2.tar.gz
# gtar zxvf php-4.3.2.tar.gz
# cd php-4.3.2
# CC=gcc CFLAGS="-O6" CXX=gcc CXXFLAGS="-O6 -felide-constructors -fno-exceptions -fno-rtti"
# ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-gettext --with-pear --with-xml \
--with-mysql=/usr/local/mysql \
--enable-ftp \
--with-dom \
--with-zlib-dir=/usr/local/include
# make
# make install
# cp php.ini-dist /usr/local/php/lib/php.ini
# vi /usr/local/php/lib/php.ini
max_execution_time = 600 ; //最大运行时间600秒
max_input_time = 600 ; //最大输出时间600秒
memory_limit = 20M ; //最大内存限制20M
register_global =On
post_max_size = 20M ; //php可接受的 post 方法大小 20M
file_uploads = On ; //允许上载文件
upload_max_filesize = 20M ; //最大上载文件20M
session.auto_start = 1 ; //session自动启动
3.设置Apache2和PHP4结合
# vi /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
LoadModule php4_module modules/libphp4.so
DirectoryIndex index.html index.htm index.php
4.测试
# /etc/init.d/apache restart //重新启动apache,使apache的配置文件的更改生效
# vi /usr/local/apache/htdocs/index.php
#http://YouIP/ //应该可以看到PHP对系统的统计信息
十四.安装Webmail
1.安装Sqwebmail
下载sqwebmail-3.5.0-CN.tar.gz
# gtar zxvf sqwebmail-3.5.0-CN.tar.gz
# cd sqwebmail-3.5.0
# ./configure \
--prefix=/mail/webmail \
--enable-cgibindir=/mail/webmail/www/cgi-bin \
--enable-imagedir=/mail/webmail/www/image \
--enable-imageurl=/image \
--without-authpam \
--with-db=gdbm \
--enable-webpass=no \
--without-authpwd \
--without-authshadow \
--with-trashquota
# make configure-check
# make
# make install-strip
# make install-configure
2.设置Sqwebmail
# cd /mail/webmail
# vi authdaemonrc //修改如下
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=5
version="authdaemond.mysql"
authdaemonvar="/mail/webmail/var/authdaemon"
# vi authmysqlrc //修改如下
MYSQL_SERVER localhost
MYSQL_USERNAME mail
MYSQL_PASSWORD password
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE USER
#MYSQL_CRYPT_PWFIELD PASSWORD
MYSQL_CLEAR_PWFIELD CLEAR_PASSWORD
DEFAULT_DOMAIN mydomain.com
MYSQL_UID_FIELD UID
MYSQL_GID_FIELD GID
MYSQL_LOGIN_FIELD MAIL
MYSQL_HOME_FIELD HOMEDIR
MYSQL_NAME_FIELD USERNAME
MYSQL_MAILDIR_FIELD MAILDIR
MYSQL_QUOTA_FIELD QUOTA
MYSQL_WHERE_CLAUSE STATUS=1
# vi /etc/init.d/webmail //建立启动脚本
#!/bin/sh
#
# Startup / shutdown script for Clam Antivirus
case "$1" in
start)
/mail/webmail/libexec/authlib/authdaemond start
;;
stop)
/mail/webmail/libexec/authlib/authdaemond stop
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
# ln -s /etc/init.d/webmail /etc/rc3.d/S90webmail
# ln -s /etc/init.d/webmail /etc/rc0.d/K90webmail
# ln -s /usr/lib/sendmail /usr/bin/sendmail //做一个postfix的sendmail外壳文件的连接,sqwebmail要到这个目录查找这个命令, 如果没有sqwebmail无法发送邮件.
# /mail/webmail/libexec/authlib/authdaemond start //启动webmail
修改apache的配置文件httpd.cnf
# vi /usr/local/apache/conf/httpd.conf
DocumentRoot "/usr/local/apache/htdocs"
更改为:
DocumentRoot "/mail/webmail/www"
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
更改为:
ScriptAlias /cgi-bin/ "/mail/webmail/www/cgi-bin/"
# cd /mail/webmail/www
# cp -Rf image webmail
# vi /mail/webmail/www/index.html