确认下面的软件是否已经安装:
rpm -q httpd php php-mysql mysql mysql-server mysql-devel gdbm gdbm-devel openssl openssl-devel stunnel krb5-devel
#创建/home/pkg/目录
mkdir /home/pkg
cd home
#下载软件
wget [url]http://www.xuki.org/qmail_2.9.tar.gz[/url]
#将软件解压缩到目录中
tar   -zvf qmail_2.9.tar.gz
#解压缩netqmail-1.05.tar.gz
 
chmod 755 -R pkg
cd pkg
tar -xzf netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh
注意:./collate.sh这一步不要忘
第四节:安装qmail TOP
 
除非你确实熟悉各个软件和系统结构,否则请按照如下步骤一步一步安装软件,此文将引导你安装一套完整的邮件系统。这个安装过程基本上你只需要复制粘贴就可以完成。
 
安装daemontools
daemontools是一个收集管理UNIX进程的工具.用它来监听qmail-send,qmail-smtpd,qmail-pop3d.
参考:[url]http://cr.yp.to/daemontools.html[/url]
#安装:
cd /home/pkg
tar -zxvf daemontools-0.76.tar.gz
cd admin/daemontools-0.76
patch -p1 < /home/pkg/netqmail-1.05/other-patches/daemontools-0.76.errno.patch
package/install
# 验证daemontools已经正常运行:
sleep 5
ps ax | grep svscan
安装ucspi-tcp
ucspi-tcp软件包由一组工具组成。它们用来简单的建立客户机-服务器tcp后台程序。TcpServer是一个比inetd安全性更好的选择。它内建有基于规则的连接控制,能完善地在达到预定义的最大系统负载时将连接推迟,这点比 inetd好。Tcpserver也被推荐与qmail一同使用,因为它们是同一个作者编的程序。
参考:[url]http://cr.yp.to/ucspi-tcp.html[/url]
#安装:
cd /home/pkg
tar zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch < /usr/local/src/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch
make
make setup check
安装qmail
参考:[url]http://www.qmail.org[/url]
          [url]http://www.lifewithqmail.org/[/url]
这个toaster补丁,是下面这几个补丁的组合:
smtp auth (SMTP认证)
spf (发信人DNS检查)
qmail-queue (如果要使用病毒扫描引擎则需要这个补丁)
maildir++ patch
support oversize dns packets (not necessary if you use dnscache)
chkuser (检查本地vpopmail用户表,信头的语法,这个补丁需要在安装vpopmail后被安装。)
spam throttle
qregex (匹配badmailfrom和badmailto文件里的规则)
big concurrency (set the spawn limit above 255)
#安装:
#创建所需要的用户
mkdir /var/qmail
groupadd nofiles
useradd alias -g nofiles -d /var/qmail/alias -s /sbin/nologin
useradd qmaild -g nofiles -d /var/qmail -s /sbin/nologin
useradd qmaill -g nofiles -d /var/qmail -s /sbin/nologin
useradd qmailp -g nofiles -d /var/qmail -s /sbin/nologin
groupadd qmail
useradd qmailq -g qmail -d /var/qmail -s /sbin/nologin
useradd qmailr -g qmail -d /var/qmail -s /sbin/nologin
useradd qmails -g qmail -d /var/qmail -s /sbin/nologin
#顺便添加vpopmail用户
groupadd vchkpw -g 89
useradd vpopmail -u 89 -g vchkpw
#准备安装qmail
cd /home/pkg
tar -xzf toaster-.s-0.7.tar.gz
cd netqmail-1.05/netqmail-1.05/
# 搜索函数straynewline中的451改为553
vi qmail-smtpd.c
# 当你的服务器收到无效格式的邮件时,会发送:"I am not going to accept that message at the moment,you can try again later",对方服务器收到后,几秒钟后又会发送同样的邮件给你,造成多次的重复。
# 改为553后,你的服务器将直接发送:"I am not going to accept that message,don't try sending it again.",告诉对方的服务器不要再发这封无效的信件。
# RedHat/Fedora用户可能需要为TLS补丁链接一个include文件
# 输入如下命令:
ln -s /usr/kerberos/include/com_err.h /usr/include/
# 删除sendmail的链接
rm -rf /usr/sbin/sendmail
#qmail编译安装
make
make setup check
#注:qmail的补丁在vpopmail安装之后再打。
# 用你自己的主机名代替下面的mail.domain.com
./config-fast mail.domain.com
#设置管理员的邮箱地址。
#发往root/postmaster/mailer-daemon地址的邮件将会由定义的管理员邮箱接收。
#将如下的“[email]admin@domain.com[/email]"替换成你的管理员邮箱。
cd /var/qmail/alias
echo "[email]admin@domain.com[/email]" > .qmail-postmaster
echo "[email]admin@domain.com[/email]" > .qmail-mailer-daemon
echo "[email]admin@domain.com[/email]" > .qmail-root
chmod 644 /var/qmail/alias/.qmail*
#开启SPF设置
echo ./Maildir/ >/var/qmail/control/defaultdelivery
echo 3 > /var/qmail/control/spfbehavior
#添加qmail的帮助手册
echo MANPATH /var/qmail/man >> /etc/man.config
#为qmail服务建立监控目录和日志文件:
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir -p /var/qmail/supervise/qmail-pop3d/log
mkdir -p /var/qmail/supervise/qmail-pop3ds/log
cp /home/pkg/toaster-.s-0.7/send.run /var/qmail/supervise/qmail-send/run
cp /home/pkg/toaster-.s-0.7/send.log.run /var/qmail/supervise/qmail-send/log/run
cp /home/pkg/toaster-.s-0.7/smtpd.run /var/qmail/supervise/qmail-smtpd/run
cp /home/pkg/toaster-.s-0.7/smtpd.log.run /var/qmail/supervise/qmail-smtpd/log/run
cp /home/pkg/toaster-.s-0.7/pop3d.run /var/qmail/supervise/qmail-pop3d/run
cp /home/pkg/toaster-.s-0.7/pop3d.log.run /var/qmail/supervise/qmail-pop3d/log/run
cp /home/pkg/toaster-.s-0.7/pop3ds.run /var/qmail/supervise/qmail-pop3ds/run
cp /home/pkg/toaster-.s-0.7/pop3ds.log.run /var/qmail/supervise/qmail-pop3ds/log/run
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run
chmod 755 /var/qmail/supervise/qmail-pop3ds/run
chmod 755 /var/qmail/supervise/qmail-pop3ds/log/run
mkdir -p /var/log/qmail/smtpd
mkdir -p /var/log/qmail/pop3d
mkdir -p /var/log/qmail/pop3ds
chown -R qmaill /var/log/qmail
#启动脚本:
cd /home/pkg
cp toaster-.s-0.7/rc /var/qmail/rc
chmod 755 /var/qmail/rc
cp toaster-.s-0.7/qmailctl /var/qmail/bin/
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
rm -rf /usr/lib/sendmail
ln -s /var/qmail/bin/sendmail /usr/lib/sendmail
# 用daemontools来启动qmail-send和qmail-smtpd
ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service
#命令:
# 启动,停止,重启,查看队列等
qmailctl start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help
# 检查服务
netstat -an | grep 25
ps -ef | grep qmail
ps -efl | grep "service errors" | grep -v grep
 
#日志:
/var/log/maillog
/var/log/qmail/current
/var/log/qmail/pop3d/current
/var/log/qmail/pop3ds/current
/var/log/qmail/smtpd/current
我建议重新回顾一下刚才我们所做的步骤以熟悉对qmail的安装. 下面我们将开始vpopmail的安装.
第五节:安装vpopmail TOP
 
vpopmail是一个以qmail为基础的虚拟域管理包;其允许在一个IP地址添加多个虚拟域;并且可以不需要使用系统帐号做邮件帐号。
参考:[url]http://vpopmail.sf.net[/url]
#创建目录:
mkdir -p /home/vpopmail/etc
# 设置默认域,红色部份改成你要设置的域。
echo "domain.com" > /home/vpopmail/etc/defaultdomain
# 设置smtp规则,关闭open relays
echo '127.0.0.1:allow,RELAYCLIENT=""' > /home/vpopmail/etc/tcp.smtp
cd /home/vpopmail/etc ; tcprules tcp.smtp.cdb tcp.smtp.tmp < tcp.smtp
# 设置MySQL信息,第一个vpopmail是帐号,xukixu为密码,第二个vpopmail是数据库
echo "localhost|0|vpopmail|xukixu|vpopmail" > /home/vpopmail/etc/vpopmail.mysql
chmod 640 /home/vpopmail/etc/vpopmail.mysql
chown -R vpopmail.vchkpw /home/vpopmail/etc
# 在MySQL里添加vpopmail的帐号
mysql -uroot -pxukixu
CREATE DATABASE vpopmail;
GRANT select,insert,update,delete,create,drop . vpopmail.*
TO vpopmail@localhost IDENTIFIED BY 'xukixu';
FLUSH PRIVILEGES;
QUIT
#安装:
cd /home/pkg/
tar zxvf vpopmail-5.4.10.tar.gz
cd vpopmail-5.4.10
# 带数据库支持
./configure --enable-incdir=/usr/include/mysql --enable-libdir=/usr/lib/mysql --disable-roaming-users --enable-logging=p --disable-passwd --enable-clear-passwd --disable-domain-quotas --enable-auth-module=mysql --enable-auth-logging --enable-sql-logging --disable-valias --disable-mysql-limits --enable-learn-passwords
make
make install-strip
#管理:
echo 'export PATH=$PATH:/home/vpopmail/bin' >> /etc/profile
source /etc/profile
# 添加域,红色部份前面是域名,后面是管理员(postmaster)密码
vadddomain domain.com xukixu
# 添加用户,红色部份为注解,不用输入
vadduser -q 10485760S(邮箱大小) [email]xukixu@domain.com[/email](邮箱帐号) 1234(密码)
vmoduser -c 许靖(邮箱描述) [email]xukixu@domain.com[/email]
# 设置邮箱容量达到90%的警告信息
vi /home/vpopmail/domains/.quotawarn.msg
From: 邮箱管理员
Reply-To: [email]postmaster@domain.com[/email]
To: 邮箱用户
Subject: 邮箱空间警告
Mime-Version: 1.0
Content-Type: text/html; charset=gb2312
Content-Transfer-Encoding: base64
您的邮箱空间已经达到90%.如果想继续使用,请删除一些信件.
如果需要帮助,请联系邮箱管理员:
Email : [email]postmaster@domain.com[/email]
# 设置邮箱已满的警告信息
echo "邮件被拒绝,用户的邮箱空间已满." > /home/vpopmail/domains/.over-quota.msg
#启动脚本:
cp /home/pkg/toaster-.s-0.7/vpopmailctl /var/qmail/bin
ln -s /var/qmail/bin/vpopmailctl /usr/bin
chmod 755 /var/qmail/bin/vpopmailctl
#现在打上qmail的补丁:
cd /home/pkg/netqmail-1.05/netqmail-1.05
bunzip2 -c /home/pkg/qmail-toaster-0.7.2.patch.bz2 | patch -p0
make clean
make
qmailctl stop
make setup check
chown -R vpopmail:vchkpw /var/qmail/spam
#创建SSL Key
make cert
#按提示输入公司信息
[root@mail netqmail-1.05]# make cert
Generating a 1024 bit RSA private key
.............++++++
...............++++++
writing new private key to '/var/qmail/control/servercert.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:GD
Locality Name (eg, city) [Newbury]:SZ
Organization Name (eg, company) [My Company Ltd]:Domain
Organizational Unit Name (eg, section) []:Domain
Common Name (eg, your name or your server's hostname) []:domain.com
Email Address []:xukixu@domain.com
make tmprsadh
#注:这里可能要多等一会
chown -R vpopmail:qmail /var/qmail/control/clientcert.pem /var/qmail/control/servercert.pem
# 用"crontab -e"在crontab里增加下面这条,每天晚上更新temp keys
01 01 * * * /var/qmail/bin/update_tmprsadh > /dev/null 2>&1
#起动qmail
qmailctl start
# 用daemontools来启动qmail-pop3d和qmail-pop3ds
ln -s /var/qmail/supervise/qmail-pop3d /service
ln -s /var/qmail/supervise/qmail-pop3ds /service
#命令:
# 启动,停止,重启,查看队列等
vpopmailctl start|stop|restart|stat|pause|cont|help
# 检查服务
netstat -an | grep 110
ps -ef | grep qmail
ps -efl | grep "service errors" | grep -v grep
 
#POP3和SMTP测试
用outlook测试qmail的smtp和pop3是否正常,注意由于vpopmail支持虚拟域名,所以在outlook中设置邮件帐号时,用户名后要加上域名,如[email]demo@demo.com[/email]。smtp是带认证的,在outlook中也要作相应设置。建议先测试正常后再进行下一步安装。如果qmail出现问题,可查看mysql中的vpopmail数据库,/var/log下的mysqld和maillog日志记录,这样容易很快找出问题。
第八节:安装courier-imap TOP
 
Courier-IMAP支持IMAP/SIMAP访问
参考:[url]http://www.inter7.com/courierimap[/url]
courier-imap 从 4版本开始,把 courier-authlib 独立出来了,需要先安装 courier-authlib. 具体步骤:
    cd /home/pkg
    tar -xjvf courier-authlib-0.55.tar.bz2
    cd courier-authlib-0.55
    ./configure --prefix=/usr/local --exec-prefix=/usr/local --with-authvchkpw --without-authldap --without-authmysql --disable-root-check --with-ssl --with-authchange pwdir=/usr/local/libexec/authlib --with-redhat
    make
    make install
    make install-configure
#修改设置文件:/usr/local/etc/authlib/authdaemonrc,去掉不需要的认证模式,只留vchkpw方式,然后认证进程改成2个
#完成后启动它:
    /usr/local/sbin/authdaemond start
#需要把这个脚本放到/etc/init.d, 然后在/etc/rc3.d 或/etc/rc5.d做一个符号连接,以便系统启动时自动运行。
#启动后,在内存中可以看到2个authlib进程:
    ps -aef |grep authlib
        root     20108 20107 0 Jan28 ?        00:00:00 /usr/local/libexec/courier-authlib/authdaemond
        root     20109 20108 0 Jan28 ?        00:00:00 /usr/local/libexec/courier-authlib/authdaemond
 
#这里可以想办法把运行身份改成vpopmail,毕竟用root运行,如果出现问题影响范围会大很多。
#测试是否正常:
运行/usr/local/sbin/authtest:(红字为输入内容,后面的1121221应该是pop3密码,后面部分应该是命令结果)
authtest [email]xukixu@domain.com[/email] 1121221
         Authenticated: [email]xukixu@domain.com[/email] (uid 509, gid 509)
        Home Directory: /var/vpopmail/domains/domain.com/xukixu
               Maildir: (none)
                 Quota: (none)
    Encrypted Password: $1$LJjMeeeeqqeqF9VWUywtLV/O5ciqeg.
    Cleartext Password: xukixu
               Options: disablewebmail=0,disablepop3=0,disableimap=0
#出现上面的提示就是说authlib运行正常
#下面来安装courier-imap
    cd /home/pkg
    tar -xjf courier-imap-4.0.2.tar.bz2
    cd courier-imap-4.0.2
# 作为vpopmail用户进行安装
    chown -R vpopmail:vchkpw ../courier-imap-4.0.2
    su vpopmail
    ./configure --with-redhat
# 注:Redhat用户需要使用"--with-redhat"选项
    make
    exit
    make install-strip
    make install-configure
    cp courier-imap.sysvinit /etc/rc.d/init.d/courier-imap
    chmod 755 /etc/rc.d/init.d/courier-imap
    chkconfig --add courier-imap
#配置:
# 修改文件/usr/lib/courier-imap/etc/authdaemonrc,如果没有,则链接/usr/local/etc/authlib/authdaemonrc
    authmodulelist="authvchkpw"
# 修改文件/usr/lib/courier-imap/etc/imapd
    IMAPDSTART=YES
# 修改文件/usr/lib/courier-imap/etc/imapd-ssl                               
    IMAPDSSLSTART=YES
# 修改文件/usr/lib/courier-imap/etc/imapd.cnf
    CN=domain.com
    emailAddress=postmaster@domain.com
# 修改文件/usr/lib/courier-imap/etc/pop3d.cnf
    CN=domain.com
    emailAddress=postmaster@domain.com
#启动:
    /etc/rc.d/init.d/courier-imap start
#使用outlook测试一下IMAP是否正常
    
第九节:安装SquirrelMail(可选) TOP
 
SquirrelMail 是一个PHP编写的IMAP客户端,在安装SquirrelMail之前,要确保你的IMAP正常运行。
参考: [url]http://www.squirrelmail.org/[/url]
#安装 squirrelmail 我在这里遇到几个问题:进入网页里,报错imap_server,可能是imap没启动,把所有关于QMAIL的服务都要启动,出现/data和apache不能结合,是因为apache没权限写入/data目录
                                                              出现402什么的字眼,可能是selinux把权限限制了,把selinux关了就行了(在/etc/selinux/config,设置为DISABLE就行了)
   
    cd /home/pkg
    tar -xzvf squirrelmail-1.4.4.tar.bz
    cd squirrelmail-1.4.4
    cd plugins
    tar -xzf ../../quota_usage-1.3-1.2.7.tar.gz
    cp quota_usage/config.php.sample quota_usage/config.php
    cd ../
    ./configure
    # 你将要设置如下选项
    
    #选择 “2. Server Settings”=>“A. Update IMAP Settings”=>“8. Server software”改成“courier”;回到主菜单,选择“4.General Options”=>“1. Data Directoryand”改成“/var/www/data/”;再退回主菜单,选择“8. Plugins”=>添加你希望用到的插件。回到主菜单,选择“10. Languages”,将“ Default Language”改成“zh_CN”,“Default Charset”改成“GB2312”。保存退出。
    mv data /var/www/
    chown -R vpopmail.vchkpw /var/www/data
    cd ../
    mv squirrelmail-1.4.4 /var/www/html/squirrelmail
     
#登录[url]http://domain.com/squirrelmail[/url] 验证是否安装成功。
安装Ezmlm
exmlm是一个快速,强大的邮件列表程序,可以通过qmailadmin对其进行配置
#安装:
cd /home/pkg
tar -xvzf ezmlm-0.53.tar.gz
tar -xvzf ezmlm-idx-0.42.tar.gz
cp -rf ezmlm-idx-0.42/* ezmlm-0.53/
cd ezmlm-0.53
patch < idx.patch
chmod u+x makelang
make
make man
#汉字GB2312支持
make ch_GB
make setup
第十三节:安装qmailadmin TOP
qmailadmin除了不能添加删除虚拟域外,几乎可以完成所有的虚拟域管理
#安装:
cd /home/pkg
tar -xvzf qmailadmin-1.2.3.tar.gz
cd qmailadmin-1.2.3
./configure --enable-htmldir=/var/www/html --enable-cgibindir=/var/www/cgi-bin --enable-vpopuser=vpopmail --enable-autoresponder-bin=/usr/bin --disable-ezmlm-mysql --enable-maxusersperpage=20 --enable-maxaliasesperpage=20 --enable-modify-quota --enable-domain-autofill
make
make install-strip
cd /usr/local/share/qmailadmin/lang
mv en en.bak
cp zh-cn en
安装选项参考:
qmailadmin 1.2.3
Current settings
---------------------------------------
cgi-bin dir = /var/www/cgi-bin
html dir = /var/www/html
image dir = /var/www/html/images/qmailadmin
image URL = /images/qmailadmin
template dir = /usr/local/share/qmailadmin
qmail dir = /var/qmail
vpopmail dir = /home/vpopmail
autorespond dir = /usr/bin
ezmlm dir = /var/qmail/bin/ezmlm
ezmlm idx = yes
mysql for ezmlm = no
help = no
modify quota = yes
domain autofill = yes
modify spam check = no
第十六节:安装SpamAssassin TOP
Spam是一个让人讨厌的字眼. 大部分的人都不喜欢它. 如果你想保护自己免受spam, 你就需要安装SpamAssassin.
因我在安装系统的时候已经选择好了SpamAssassin。现在我们将其升级到最新版:
    cd /home/pkg
    rpm -Uvh spamassassin-3.0.2-2.1.el3.rf.i386.rpm
     
还需要安装另外一个软件包:
    rpm -Uvh perl-Razor-Agent-2.40-2.i386.rpm
     
    #修改起动脚本使spamassassin支持vpopmail
    #修改如下一行:
    vi /etc/init.d/spamassassin
        SPAMDOPTIONS="-d -c -m5 -H -x -u spamd -v"
    vi /etc/sysconfig/spamassassin
        SPAMDOPTIONS="-d -c -m5 -H -x -u spamd -v"
下图是我在安装SpamAssassin时所列出的perl模块,SpamAssassin所要用到的一些Perl模块是:
 
perl-Time-HiRes
perl-Digest-SHA1
perl-HTML-Parser
perl-DB_File
perl-HTML-Tagset
perl-Razor-Agent
perl-DBI
perl-Net-DNS
perl-URI
这些模块请安装上。
 
#spamassassin的过滤模板在/etc/mail/spamassassin/local.cf,修改为:
vi /etc/mail/spamassassin/local.cf
required_score          5.0
rewrite_header Subject ********SPAM********
report_safe            1
use_bayes              1
skip_rbl_checks         0
ok_languages            zh en
ok_locales              en ko
score HEAD_ILLEGAL_CHARS 0
score SUBJ_ILLEGAL_CHARS 0
score DATE_IN_PAST_03_06 0
score UPPERCASE_25_50 0
score UPPERCASE_50_75 0
score UPPERCASE_75_100 0
score X_MSMAIL_PRIORITY_HIGH 0
score X_PRIORITY_HIGH 0
score TO_TXT 100
score RATWARE_HASH_2 100
score RATWARE_HASH_2_V2 100
score BAYES_99 0.1
score BAYES_80 0.1
score BAYES_60 0.1
score FROM_ILLEGAL_CHARS 0.1
score MIME_BASE64_TEXT 0.1
score NO_RDNS_DOTCOM_HELO 0.1
score CHINA_HEADER 0.1
score NO_REAL_NAME 0.2
score HTML_MESSAGE 0.2
score MIME_HTML_ONLY 0.2
score MIME_HTML_ONLY_MULTI 0.2
score FORGED_MUA_OUTLOOK 0.2
score FORGED_HOTMAIL_RCVD 0.2
score FORGED_OUTLOOK_TAGS 0.2
score MAILTO_TO_SPAM_ADDR 0.2
#黑白名单
whitelist_from *@domain.com
# ---------------------------------------------------------------------------
# 使用中国反垃圾邮件联盟的CBL/CDL
# URL: [url]http://www.anti-spam.org.cn/[/url]
header RCVD_IN_CBL .:check_rbl('cbl', 'cbl.anti-spam.org.cn.')
describe RCVD_IN_CBL Received via a relay in cbl.anti-spam.org.cn
tflags RCVD_IN_CBL net
header RCVD_IN_CDL .:check_rbl('cdl-notfirsthop', 'cdl.anti-spam.org.cn.')
describe RCVD_IN_CDL CDL: dialup sender did non-local SMTP
tflags RCVD_IN_CDL net
#SCORE
score RCVD_IN_CBL 4.0
score RCVD_IN_CDL 3.0
#运行ntsysv,将spamassassin设定的为开机运行
#使用CCERT 中文垃圾邮件过滤规则集Chinese_rules.cf
wget -N -P /usr/share/spamassassin [url]www.ccert.edu.cn/spam/sa/Chinese_rules.cf[/url]
#启动SpamAssassin
service spamassassin start
#定期自动更新中文反垃圾邮件规则
crontab –e
#加入
0 0 1 * * wget -N -P /usr/share/spamassassin [url]www.ccert.edu.cn/spam/sa/Chinese_rules.cf;/etc/init.d/spamassassin[/url] restart;/etc/init.d/spamassassin restart;
#建立SpamAssassin的学习系统
sa-learn --sync -D -p user_prefs
#查看自学习的数据信息
sa-learn --dump all
#查看调试信息
spamassassin --lint –D
第十七节:安装Clamav   TOP
#添加所需的组和用户
groupadd clamav
useradd -g clamav -s /bin/false clamav
#安装软件
cd /home/pkg
tar -xzvf clamav-0.83.tar.gz
cd clamav-0.83
./configure --disable-zlib-vcheck
make check
make install
#测试Clamav
clamscan --recursive --log=/tmp/clamscan.log ./         //扫描当前目录,测试clamscn是否运行
cat /tmp/clamscan.log
#更改/usr/local/etc/freshclam.conf文件,去掉下面选项前面的#:
vi /usr/local/etc/freshclam.conf
#Example \\前面加上#
UpdateLogFile /var/log/freshclam.log \\去掉前面的#
LogSyslog \\去掉前面的#
PidFile /var/run/freshclam.pid \\去掉前面的#
更改/usr/local/etc/clamd.conf文件,去掉下面选项前面的#:
vi /usr/local/etc/clamd.conf
#Example \\前面加上#
LogFile /var/log/clamav/clamd.log \\去掉前面的#
LogFileMaxSize 2M \\去掉前面的#
LogTime \\去掉前面的#
PidFile /var/run/clamd.pid \\去掉前面的#
LogSyslog \\去掉前面的#
ScanMail \\去掉前面的#
touch /var/log/freshclam.log
chmod 644 /var/log/freshclam.log
chown clamav:clamav /var/log/freshclam.log
mkdir /var/lib/clamav
chown clamav:clamav /var/lib/clamav
#升级clamscan病毒库
freshclam --verbose
#把freshclam加入crontab 定时更新病毒库,自动扫描/home目录
crontab -e
0 1 * * * freshclam --quiet -l /var/log/freshclam.log
0 6 * * * /usr/local/bin/clamscan --recursive --infected --exclude /usr/local/share/clamav/viruses.db --exclude /usr/local/share/clamav/viruses.db2 --log=/var/log/clamscan.log /home
#创建freshclam日志记录文件
mkdir -p /var/log/clamav
touch /var/log/clamav/clamd.log
chown clamav.clamav -R /var/log/clamav/
chmod 644 -R /var/log/clamav/
#创建clamav启动脚本
vi /etc/rc.d/init.d/clamav
#!/bin/sh
#
# Startup / shutdown . for Clam Antivirus
case "$1" in
start)
/usr/local/sbin/clamd && echo -n 'Clamd started'
/usr/local/bin/freshclam -d -c 2 -l /var/log/freshclam.log
echo -n ' freshclam started'
;;
stop)
/usr/bin/killall clamd > /dev/null 2>&1 && echo -n 'Clamd stoped'
/usr/bin/killall freshclam > /dev/null 2>&1 && echo -n ' freshclam Stoped'
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
#使其能够执行
chmod 755 /etc/init.d/clamav
#随开机起动
ln -s /etc/init.d/clamav /etc/rc.d/rc3.d/S88clamav
ln -s /etc/init.d/clamav /etc/rc.d/rc5.d/S88clamav
以上是QMAIL的安装。
下面是LDAP的安装
注:我的安装方法是以源码编译的方式进行的,以root用户进行安装。
安装所需软件
openldap-2.1.29 [url]http://www.openldap.org[/url]
Berkeley DB 4.2.52 [url]http://www.sleepycat.com[/url]
安装步骤
1、由于openldap需要Berkeley DB来存放数据,所以需先安装Berkeley DB 4.2.52,可到它的网站下载,网址见上面。
# tar -zxvf db-4.2.52.tar.gz
解完压后,会生成一个db-4.2.52目录,进行该目录下的build_unix目录。执行以下命令进行配置安装。
# ../dist/configure
# make
# make install
。该软件默认是安装在/usr/local/BerkeleyDB.4.2目录下。安装完成后,要把/usr/local/BerkeleyDB.4.2/lib的库路径加到/etc/ld.so.conf文件内,添加完成后执行一次 ldconfig,使用配置文件生效。这样编译openldap时才能找到相应的库文件。这样资料库就安装完成了,接下来可以安装openldap了。
ld.so.conf是什么东西?它就是系统动态链接库的配置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录 /lib,/usr/lib除外),各个目录名间以空白字符(空格,换行等)或冒号或逗号分隔。一般的LINUX发行版中,此文件均含一个共享目录 /usr/X11R6/lib,为X window窗口系统的动态链接库所在的目录。 ldconfig是它的管理命令,具体操作方法可查询man手册,这里就不细讲了。
2、到openldap官方网站下载最新的稳定版源码,并解压。查看INSTALLT 和README文档,这个很重要,因为安装方法和一些注意事项都在里面有介绍。认真弄明白文档内容能节省你不少的安装调试时间。这也是开源软件的一个特点,给用户提供了最大的灵活性和可配置性。但也增加了系统安装配置的难度,需要有相关的文档配置说明和指导。在官方网站上还有详细的帮助文件,在整个系统配置中需要经常查询。
# tar -zxvf openldap-stable-20040329.tgz
解压完成后,会生成一个openldap-2.1.29目录。进行该目录,执行以下命令进行配置安装。
# env CPPFLAGS="-I/usr/local/db/include" LDFLAGS="-L/usr/local/db/lib" ./configure --prefix=/usr/local/openldap --enable-ldbm
注意以上配置语句,要设置资料库的include和lib路径,否则在配置到资料库相关内容时会提示Berkeley DB版本不兼容,并中断配置。如果没有--enable-ldbm选项,在make test时会提示ldbm找不到。为了减少出错,还是加上为好。
#make depend
#make
#make test
#make install
通过配置命令可以看出,我们把openldap安装到/usr/local/openldap目录下。建议以源码安装的软件都放到独立的目录下,不要放到软件默认的目录。好处是方便管理和控制,所有文件在统一的目录下,卸载软件只要删除整个目录就可以了。
3、ok,安装完相关软件后就可以着手配置了。Berkeley DB资料库没什么好配置的。主要是配置openldap 服务。配置文件在软件的安装目录的etc/openldap下,有四个文件,主要的是slapd.conf and ldap.conf,其它两个是backup文件。首先,我们先来配置slapd.conf文档。
系统默认的slapd.conf文件如下:
# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8 2003/05/24 23:19:14 kurt Exp $
#
# See slapd.conf(5) for details . configuration options.
# This file should NOT be world readable.
#
include         /usr/local/openldap/etc/openldap/schema/core.schema 设置schema配置文档包含
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral       ldap://root.openldap.org
pidfile         /usr/local/openldap/var/slapd.pid 设置pid和args文档位置
argsfile        /usr/local/openldap/var/slapd.args
# Load dynamic backend modules:
# modulepath    /usr/local/openldap/libexec/openldap
# moduleload    back_bdb.la
# moduleload    back_ldap.la
# moduleload    back_ldbm.la
# moduleload    back_passwd.la
# moduleload    back_shell.la
# 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
# Sample access control policy:
#       Root DSE: allow anyone to read it
#       Subschema (sub)entry DSE: allow anyone to read it
#       Other DSEs:
#       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
#       Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#       by self write
#       by users read
#       by anonymous auth
#
# if no access controls are present, the default policy is:
#       Allow read by all
#
# rootdn can always write!
#######################################################################
# ldbm database definitions
#######################################################################
database        bdb 设置使用的资料库,也可用lbdm。
suffix          "dc=my-domain,dc=com" 设置目录后缀
rootdn          "cn=Manager,dc=my-domain,dc=com" 设置目录管理员
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw          secret 设置管理密码,这里用了明文的secret密码。
# The database directory MUST exist prior to running slapd AND
# should .ly be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory       /usr/local/openldap/var/openldap-data 设置资料库路径
# Indices to maintain
index   objectClass     eq 设置目录项索引
要服务器正常动作,要修改一些始初参数和设置,修改后的配置文档如下:
# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8 2003/05/24 23:19:14 kurt Exp $
#
# See slapd.conf(5) for details . configuration options.
# This file should NOT be world readable.
#
include         /usr/local/openldap/etc/openldap/schema/core.schema 为了有效使用目录服务,包含相关的文件。
include         /usr/local/openldap/etc/openldap/schema/corba.schema 注意,在包含文件时是要按一定顺序的,因为文件
include         /usr/local/openldap/etc/openldap/schema/cosine.schema 里的属性存在依赖关系。如果顺序不对,服务器启
include         /usr/local/openldap/etc/openldap/schema/inetorgperson.schema    动不了,文档间的依赖关系在文档中都有说明,请
include         /usr/local/openldap/etc/openldap/schema/misc.schema             仔细查看一个。如果懒得看也可以按我的顺序。
include         /usr/local/openldap/etc/openldap/schema/openldap.schema
include         /usr/local/openldap/etc/openldap/schema/nis.schema
include         /usr/local/openldap/etc/openldap/schema/samba.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral       ldap://root.openldap.org
pidfile         /usr/local/openldap/var/slapd.pid
argsfile        /usr/local/openldap/var/slapd.args
loglevel 1 增加了日志功能,需修改syslog配置文件,在文件中增加一项:local4.* /var/log/ldap.log
                                日志级别定义可查相官方网站的文档。1级记录的信息很多。可用于调试。
# Load dynamic backend modules:
# modulepath    /usr/local/openldap/libexec/openldap
# moduleload    back_bdb.la
# moduleload    back_ldap.la
# moduleload    back_ldbm.la
# moduleload    back_passwd.la
# moduleload    back_shell.la
allow bind_v2 (这里一定要设,因为squirrelmail支持LDAP——v2)
# 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
# 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
#       Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#       by self write
#       by users read
#       by anonymous auth
#
# if no access controls are present, the default policy is:
#       Allow read by all
#
# rootdn can always write!
#######################################################################
# ldbm database definitions
#######################################################################
database        bdb
suffix          "dc=it,dc=com" 改成你自已的目录后缀,
rootdn          "cn=root,dc=it,dc=com" 设置root为管理员,与linux的root没有什么关系。
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw          {MD5}mjkiuPt0wXhpxxkdiOOO+0000000AKq0by 设置root密码,用MD5加密。密码串用slappasswd -h {MD5}指令
# The database directory MUST exist prior to running slapd AND
# should .ly be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory       /usr/local/openldap/var/openldap-data   
# Indices to maintain
ok,到现在为止,服务器基本就配置完成了,可以启动了,服务器程序是位于安装目录的libexec下的slapd程序。注意,不是sldap哦。
# ./slapd
如果没有提示什么出错信息,直接返回shell状态,就说明服务器正常启动了,你可以查询日志或用ps -aux查看。或用以下命令查询服务器。
ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
如果命令执行成功,返回一些信息,则说明服务器正常运行了。如果启动不成功,它会提示一些出错信息,多数是slapd.conf配置出错。回头仔细核查一下配置文档。
4、客户端配置文档是ldap.conf。该文档相当简单,其实不和配置也能正常操作。
# $OpenLDAP: pkg/ldap/libraries/libldap/ldap.conf,v 1.9 2000/09/04 19:57:01 kurt Exp $
#
# LDAP Defaults
#
# See ldap.conf(5) for details
# This file should be world readable but not world writable.
BASE    dc=it, dc=com 设置目录起点
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666
#SIZELIMIT      12
#TIMELIMIT      15
#DEREF          never
5、ok,服务器正常运作后,就可以录入信息了。信息的录入有三种方法,一种是手工录入,一种是.ldif文件格式录入。信息录入用到ldapadd这个程序。可在安装目录的bin目录下找到。具体用法如下:
第一步是要建立DN:
# ldapadd -x -D 'cn=root,dc=it,dc=com' -W
dn: dc=it,dc=com
objectClass: dcObject
objectClass: organization
dc: it
o: Corporation
de.ion: d Corporation
注意:如果你用复制/粘贴功能把以上内容拷贝过去,一定要注意每行后面不要有空格。
第二步是建立RDN:
# ldapadd -x -D 'cn=root,dc=it,dc=com' -W -x表示用简单验证,-D表示指定目录,-W表示弹出密码输入提示
dn: uid=qq,dc=it,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
uid: qq
cn: qq
sn: qq
telephoneNumber: 138888888
de.ion: openldap test
telexNumber: tex-8888888
street: my street
postOfficeBox: postofficebox
displayName: qqdisplay
homePhone: home1111111
mobile: mobile99999
mail:qq@qq.com
输入完所有信息后,按Ctrl+d结束存盘。如果出现出错信息,请查一下对象类和属性的对应关系有没有错或输入失误。初学者就容易出错的地方是对象类和属性的对应关系没有处理好。对象类和属性是在schema文档中定义的。它们之间的关系是这样的,对象类中有些属性是必选的,有些属性是可选的。录入信息的属性必须在对象类中有定义才能用。
输入以下命令可查询到刚才输入的信息。
# ldapsearch -x -b 'dc=it,dc=com' -b设置目录起点,如果设置了BASE参数,该项可不用。
如果按以上配置文件设置了acl,用上面的查询命令是查询不到受保护的内容的。如上面的userPassword and mail。要查询到这些受限内容,需要通过验证才可以。
# ldapsearch -x -LLL -h it.com -b 'dc=it,dc=com' -D 'uid=qq,dc=it,dc=com' -W 'uid=qq'
接着提示输入密码。输入userPassword的密码回车,所有信息就都出来了。
.ldif文件方式也就是把以上手工输入的内容先写入一个.ldif文件中,然后,用ldapadd命令的-f参数导入
# ldapadd -x -D "cn=root,dc=it,dc=com" -W -f test.ldif
文件格式:dn: cn=總經理, dc=webmail, dc=print68, dc=com
        objectClass: inetOrgPerson
        cn: 總經理
        sn: 總經理
        telephoneNumber: 111-222-9999
        mail: [email]gm@webmail.print68.com[/email]
        localityName: Houston
1、删除命令ldapdelete
# ldapdelete -x -D 'cn=root,dc=it,dc=com' -W 'uid=qq1,dc=it,dc=com'
2、设置使用者密码,当然了,你的用户需要有userPassword项了。
#ldappasswd -x -D "cn=root,dc=it,dc=com" -W "uid=qq1,dc=it,dc=com" -S
New password:
Re-enter new password:
Enter bind password:
Result: Success (0)
注意:"Enter bind password" 是 "cn=root,dc=it,dc=com"管理员的密码。
3、管理员密码更改
#slappasswd
New password
Re-enter new password
{SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs
接下來再拷到 /path/to/sldap.conf 的 rootpw 即可,重启使用配置文件生效
4、通过ldapmodify修改目录内容
ldapmodify -x -D "cn=root,dc=it,dc=com" -W -f modify.ldif
上面是LDAP的安装,下面是SQUIRRELMAIL+LDAP的安装
8.4 测试小松鼠邮件系统:
[url]http://192.168.0.66/squirrelmail/src/configtest.php[/url]
如果一切顺利的话,那么你成功了。如果提示错误,请仔给细检查配置文件
   支持LDAP:
             进入/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_._addr_book = false;
$ldap_server[0] = array(
    'host' => '192.168.10.220',填上LDAP服务器的IP
    'base' => 'dc=webmail,dc=print68,dc=com',填上LDAP服务器的域名
    'name' => '192.168.10.220',填上LDAP服务器的名字或者IP
    '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,所以要在/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("utf-8","big5",$row['cn'][0]);      //將 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",$expr);     //輸入搜尋條件為 big5 但轉換成 utf-8 在去查 LDAP
架设LDAP的web界面YALA:
         
1.cp config.inc.php.example config.inc.php
2 . vi config.inc.php 在这一行改成自己yala所在的路径
   define("UNIX_PATH",     "/usr/local/apache/htdocs/yala");
3 .cp conf.d/ldap-servers.inc.php.example conf.d/ldap-servers.inc.php
          define("LDAP_SERVER",   "192.168.2.13"); 改成LDAP服务器的IP或者名字
define("LDAP_PORT",     "389"); LDAP开放的端口
define("LDAP_BASEDN",   "dc=examble,dc=com"); 改LDAPBASE
define("LDAP_BINDDN",   "cn=root,dc=examble,dc=com");改LDAPBASEDN
# No good reason to use LDAPv2, unless an old PHP or LDAP Server
define("LDAP_VERSION", "3");看LDAP的版本,现在都是版本3了。
# Use TLS to encrypt the ldap connection. Must be supported by server.
define("LDAP_TLS", FALSE);
4 . cp entry_type-config.inc.php.example entry_type-config.inc.php 新建用户需要这个文件
5 . cp conf.d/attr_desc-config.inc.php.example conf.d/attr_desc-config.inc.php
6 .   如果界面出现乱码的话,首先看http.conf文件,再看yala/include/header.inc,改 charset=utf-8
以上是我在centos4.4的版本上做得,我本来 httpd和php是用rpm方式安装的,后来YALA显示不出来,就改用源代码安装http和php,就可以显示了,可能是版本不兼容吧!!