#确认没有冲突的服务(postfix/sendmail/smtpd/httpd)开启
setup
修改后reboot
#安装qmail
#创建/home/pkg/目录,存放全部所需软件
#注:qmail将被安装到/var/qmail,vpopmail将被安装到/home/vpopmail,igenus&igenus_admin将被安装到/usr/local/apps/www/igenus
mkdir /home/pkg
cd home
tar zxvf qmail_2.9.tar.gz
#安装netqmail
cd /home/pkg
tar zxvf netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh
#安装daemontools
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
cd /home/pkg
tar zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch -p1 < ../ucspi-tcp-0.88.errno.patch
make
make setup check
#创建所需要的用户
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用户
#注销掉89 postfix用户
vi /etc/group
#注销掉89postfix用户
vi /etc/passwd
groupadd vchkpw -g 89
useradd vpopmail -u 89 -g vchkpw
#准备安装qmail
cd /home/pkg
tar zxvf toaster-scripts-0.7.tar.gz
cd netqmail-1.05/netqmail-1.05/
# 搜索函数straynewline中的451改为553
# 当你的服务器收到无效格式的邮件时,会发送:"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.",告诉对方的服务器不要再发这封无效的信件。
vi qmail-smtpd.c
# 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
# 用你自己的主机名代替下面的mail.51divx.com
./config-fast mail.51divx.com
#设置管理员的邮箱地址。
#发往root/postmaster/mailer-daemon地址的邮件将会由定义的管理员邮箱接收。
#将如下的“admin@domain.com"替换成你的管理员邮箱。
cd /var/qmail/alias
echo "postmaster@51divx.com" > .qmail-postmaster
echo "postmaster@51divx.com" > .qmail-mailer-daemon
echo "postmaster@51divx.com" > .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-scripts-0.7/send.run /var/qmail/supervise/qmail-send/run
cp /home/pkg/toaster-scripts-0.7/send.log.run /var/qmail/supervise/qmail-send/log/run
cp /home/pkg/toaster-scripts-0.7/smtpd.run /var/qmail/supervise/qmail-smtpd/run
cp /home/pkg/toaster-scripts-0.7/smtpd.log.run /var/qmail/supervise/qmail-smtpd/log/run
cp /home/pkg/toaster-scripts-0.7/pop3d.run /var/qmail/supervise/qmail-pop3d/run
cp /home/pkg/toaster-scripts-0.7/pop3d.log.run /var/qmail/supervise/qmail-pop3d/log/run
cp /home/pkg/toaster-scripts-0.7/pop3ds.run /var/qmail/supervise/qmail-pop3ds/run
cp /home/pkg/toaster-scripts-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-scripts-0.7/rc /var/qmail/rc
chmod 755 /var/qmail/rc
cp toaster-scripts-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
#安装vpopmail
mkdir -p /home/vpopmail/etc
# 设置默认域,红色部份改成你要设置的域。
echo "51divx.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 !不执行此行
注:此处我们使用root帐号(密码12345)来往mysql库里写入信息,用vpopmail帐号也可以,但mysql的vpopmail帐号默认密码空是不行的,得先修改密码才能使用
echo "219.238.233.116|0|root|12345|vpopmail" > /home/vpopmail/etc/vpopmail.mysql
chmod 640 /home/vpopmail/etc/vpopmail.mysql
chown -R vpopmail.vchkpw /home/vpopmail/etc
# 给mysql的root帐号授权
mysql -p12345
CREATE DATABASE vpopmail;
GRANT all privileges ON vpopmail.* TO root@219.238.233.116 IDENTIFIED BY '12345';
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
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock #此处应该提示'已存在'的信息
# 添加域
#如域存在:#############################################
/home/vpopmail/bin/vdeldomain 51divx.com
cd /home/vpopmail/bin
./vadddomain 51divx.com 11111
# 添加用户
./vadduser zengyu@51divx.com 111111
# 设置邮箱容量达到90%的警告信息
vi /home/vpopmail/domains/.quotawarn.msg
----------------------------
From: 邮箱管理员
Reply-To: postmaster@51divx.com
To: 邮箱用户
Subject: 邮箱空间警告
Mime-Version: 1.0
Content-Type: text/html; charset=gb2312
Content-Transfer-Encoding: base64
您的邮箱空间已经达到90%.如果想继续使用,请删除一些信件。
如果需要帮助,请联系邮箱管理员:
Email : postmaster@51divx.com
----------------------------
# 设置邮箱已满的警告信息
echo "邮件被拒绝,用户的邮箱空间已满." > /home/vpopmail/domains/.over-quota.msg
#启动脚本:
cp /home/pkg/toaster-scripts-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
#按提示输入公司信息
----------------------------
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:BJ
Locality Name (eg, city) [Newbury]:BJ
Organization Name (eg, company) [My Company Ltd]:51divx
Organizational Unit Name (eg, section) []:51divx
Common Name (eg, your name or your server's hostname) []:51divx.com
Email Address []:postmaster@51divx.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
#此时,用netstat -an就可看到25/110端口已经处于监听状态
#POP3和SMTP测试
#用outlook测试qmail的smtp和pop3是否正常,注意由于vpopmail支持虚拟域名,所以在outlook中设置邮件帐号时,用户名后要加上域名,如zengyu@51divx.com。
#smtp是带认证的,在outlook中也要作相应设置。建议先测试正常后再进行下一步安装。
#如果qmail出现问题,可查看mysql中的vpopmail数据库,/var/log下的mysqld和maillog日志记录,这样容易很快找出问题。
#安装iGenus
cd /home/pkg
tar zxvf igenus_2.0.2_20040901_release.tgz -C /usr/local/apps/www/
#建temp文件夹
mkdir /tmp/temp
chmod -R 0755 /tmp/temp
chown -R vpopmail:vchkpw /tmp/temp
mkdir /usr/local/apps/www/netdisk
chmod -R 0755 /usr/local/apps/www/netdisk
chown -R vpopmail:vchkpw /usr/local/apps/www/netdisk
chmod -R 0755 /usr/local/apps/www/igenus/
chown -R vpopmail:vchkpw /usr/local/apps/www/igenus/
#修改httpd.conf
vi /usr/local/apps/apache2/conf/httpd.conf
#修改
ServerName mail.51divx.com
User vpopmail
Group vchkpw
NameVirtualHost *:80
#添加
AddDefaultCharset GB2312 //使默认页面为中文
AddType application/x-httpd-php-source .phps
<VirtualHost *:80>
ServerName mail.51divx.com
DocumentRoot /usr/local/apps/www/igenus/
ErrorLog /dev/null
CustomLog /dev/null common
</VirtualHost>
#重启apache
/usr/local/apps/apache2/bin/apachectl restart
#修改config_inc.php文件
vi /usr/local/apps/www/igenus/config/config_inc.php
---------------------------------
$CFG_BASEPATH = "/usr/local/apps/www/igenus/"; \\改成你安装的目录
$CFG_MYSQL_HOST = 'localhost';
$CFG_MYSQL_USER = 'root'; \\vpopmail访问mysql的帐号
$CFG_MYSQL_PASS = '12345'; \\vpopmail访问mysql的密码
$CFG_MYSQL_DB = 'vpopmail'; \\数据库
$CFG_TEMP = "/tmp/temp"; \\删除$CFG_BASEPATH,并修改路径
---------------------------------
#保存退出
#重新编制Mysql数据库表格
#删除之前创建的域名
/home/vpopmail/bin/vdeldomain 51divx.com
#编辑数据库:
mysql -p12345
use vpopmail;
drop table lastauth;
drop table vpopmail;
quit;
#导入前编辑iGENUS.sql
vi /usr/local/apps/www/igenus/docs/iGENUS.sql
-------------------------
# Table structure for table `address`
use vpopmail; //加入这一行
CREATE TABLE `address`(
`id` int(11) unsigned NOT NULL auto_increment,
`pw_id` int(5) NOT NULL default '0',
`name` varchar(64) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
UNIQUE KEY `id` (`id`),
KEY `pw_id` (`pw_id`)
) TYPE=MyISAM PACK_KEYS=1 ;
# -----------------------------------------------
CREATE TABLE `vpopmail` (
`pw_id` int(5) unsigned NOT NULL auto_increment,
`pw_name` varchar(32) NOT NULL default '',
`pw_domain` varchar(64) NOT NULL default '',
`pw_passwd` varchar(40) NOT NULL default '',
`pw_uid` int(11) default NULL,
`pw_gid` int(11) default NULL,
`pw_gecos` varchar(48) default NULL,
`pw_dir` varchar(255) default NULL,
`pw_shell` varchar(20) default NULL,
`pw_clear_passwd` varchar(16) default NULL, \\加入这一行
`createtime` timestamp(14) NOT NULL,
PRIMARY KEY (`pw_id`),
KEY `pw_name` (`pw_name`,`pw_domain`)
) TYPE=MyISAM PACK_KEYS=1 ;
-------------------------
#保存退出
#运行如下命令导入数据表
mysql -p12345 --database=vpopmail </usr/local/apps/www/igenus/docs/iGENUS.sql
#设置igenus 定义允许上传下载的邮件的大小
#编辑/etc/php.ini
vi /etc/php.ini
-------------------------
max_execution_time=60
memory_limit=20M
post_max_size = 10M
file_uploads=on
upload_max_filesize=10M
register_globals=On
session.bug_compat_42=0
session.bug_compat_warn=0
sendmail_path = /var/qmail/bin/qmail-inject
-------------------------
chmod 777 /var/lib/php/session/ -R
#添加新域名和新用户。
/home/vpopmail/bin/vadddomain 51divx.com 123456
/home/vpopmail/bin/vadduser zengyu@51divx.com 123456
#最后打开浏览器,输入,就可以访问igenus企业邮局了。
#安装iGenus_Admin,一个基于Web的vpopmail域和帐号管理工具。
#安装
cd /home/pkg
tar -xzvf igenus_admin_0.1.tgz -C /usr/local/apps/www/igenus/
#设置
vi /usr/local/apps/www/igenus/admin/includes/config_inc.php
--------------------------------
$CFG_VPOPMAIL_HOST = "localhost";
$CFG_VPOPMAIL_USER = "root"; \\改为你的帐号
$CFG_VPOPMAIL_PASS = "12345"; \\改为你的密码
$CFG_VPOPMAIL_PATH = "/home/vpopmail"; \\改为你的vpopmail安装目录
--------------------------------
#保存退出
touch /etc/syspasswd.dat
chown -R vpopmail.vchkpw /usr/local/apps/www/igenus/
chmod -R 755 /usr/local/apps/www/igenus/
#解决出现不能执行查询(query): SELECT * FROM admin ORDER BY id ASC LIMIT -20, 20,修改
vi /usr/local/apps/www/igenus/admin/sys/index.php
--------------------------------
$start_row = ($get_page - 1)*$CFG_NUMOFPAGE;
修改成
if ($get_page == 0) {
$start_row = $get_page*$CFG_NUMOFPAGE;
}
else{
$start_row = ($get_page - 1)*$CFG_NUMOFPAGE;
}
--------------------------------
#保存退出
#登录设置页面,用户:Admin密码Admin来登录.注意A要大写..这个管理帐号密码登录后可以改的
#登录后,首先点“更新数据库”你就会看见你的域名。然后点“编辑”把“登录权限该域管理员(Postmaster)有权登录进行用户管理”这一项打勾,确认后,就可以用
来登录管理了。
#安装Clamav
#添加所需的组和用户
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 script 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
#安装 SpamAssassin
# 安装Time-HiRes perl模块
cd /var/src
# 注意: 如果你是第一次运行CPAN,你将会被问一系列的问题。
# 大部分问题默认就行了。
perl -MCPAN -e'shell'
cpan> install Time::HiRes
cpan> exit
# 安装SpamAssassin
cd /var/src
tar -xzf tar/Mail-SpamAssassin-2.31.tar.gz
cd Mail-SpamAssassin-2.31
perl Makefile.PL
make
make install
#修改起动脚本使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的过滤模板在/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:
header RCVD_IN_CBL eval: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 eval: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
#添加SpamAssasin服务启动必须的用户
useradd spamd
#启动SpamAssassin
service spamassassin start
#定期自动更新中文反垃圾邮件规则
crontab –e
#加入
0 0 1 * * wget -N -P /usr/share/spamassassin ;/etc/init.d/spamassassin restart;/etc/init.d/spamassassin restart;
#建立SpamAssassin的学习系统
sa-learn --sync -D -p user_prefs
#查看自学习的数据信息
sa-learn --dump all
#查看调试信息
spamassassin --lint –D
#进行一个spam和non-spam的测试
spamassassin -t < sample-spam.txt > spamtest.txt
less spamtest.txt
spamassassin -t < sample-nonspam.txt > nospamtest.txt
less nospamtest.txt
#spamtest.txt文件在主题一段中将包含"*****SPAM*****" 这一行, 而nospamtest.txt文件中则没有。
OK了,到次qmail的主要模块都装上了,要实测正常收发,请注意将你正式域名的MX记录指向过来。