2007年8月30日 星期四

Qmail On Linux

wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://shupp.org/software/netqmail-1.05.tar.gz
//wget http://shupp.org/patches/qmail-toaster-0.8.3.patch.bz2
wget http://shupp.org/software/vpopmail-5.4.13.tar.gz
//wget http://shupp.org/patches/vpopmail-5.4.13-cumulative-1.patch
//wget http://shupp.org/software/autorespond-2.0.4.tar.gz
//wget http://shupp.org/patches/autorespond-2.0.4-2.0.5.patch
//wget http://shupp.org/software/qmailadmin-1.2.10.tar.gz
//wget http://shupp.org/software/qmailadmin-help-1.0.8.tar.gz
wget http://cr.yp.to/software/ezmlm-0.53.tar.gz
wget http://shupp.org/software/ezmlm-idx-0.443.tar.gz
wget http://nchc.dl.sourceforge.net/sourceforge/courier/courier-imap-4.1.1.tar.bz2
wget http://shupp.org/software/courier-authlib-0.58.tar.bz2
//wget http://shupp.org/software/squirrelmail-1.4.6.tar.bz2
//wget http://shupp.org/software/quota_usage-1.3.1-1.2.7.tar.gz
wget http://shupp.org/software/toaster-scripts-0.8.1.tar.gz

刪除已有的SMTP/POP/IMAP元件:

rpm -e --nodeps sendmail
rpm -e --nodeps postfix

tar -zxvf tar/netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh

cd..


## daemontools ##
tar -zxvf daemontools-0.76.tar.gz
cd admin/daemontools-0.76
patch -p1 < ../netqmail-1.05/other-patches/daemontools- 0.76.errno.patch
package/install

cd..

## ucspi-tcp ##
tar -zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch -p1 < ../netqmail-1.05/other-patches/ucspi-tcp-0.88.a_record.patch
patch -p1 < ../netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch
patch -p1 < ../netqmail-1.05/other-patches/ucspi-tcp-0.88.nodefaultrbl.patch
make
make setup check

## Qmail ##
mkdir /var/qmail
groupadd nofiles
useradd -g nofiles -d /var/qmail/alias alias
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails


tar -zxvf toaster-scripts-0.8.1.tar.gz

cd netqmail-1.05/netqmail-1.05/

ln -s /usr/kerberos/include/com_err.h /usr/kerberos/include/krb5.h /usr/kerberos/include/profile.h /usr/include/

vi qmail-smtpd.c //搜索函數 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.",告訴對方的伺服器不要再發這封無效的信件。

make
make setup check

echo 3 > /var/qmail/control/spfbehavior


(cd ~alias; echo "max@shengmax.com" > .qmail-postmaster ;\
echo "max@shengmax.com" > .qmail-mailer-daemon ;\
echo "max@shengmax.com" > .qmail-root )
chmod 644 ~alias/.qmail*

vi /etc/man.config # 加 "MANPATH /var/qmail/man"

chmod 644 /var/qmail/alias/.qmail*

echo 1 > /var/qmail/control/mfcheck
echo ./Maildir/ >/var/qmail/control/defaultdelivery
cd -

# 用"crontab -e"在crontab里增加下面,每天晚上更新temp keys
01 01 * * * /var/qmail/bin/update_tmprsadh > /dev/null 2>&1

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
chmod +t /var/qmail/supervise/qmail-send
chmod +t /var/qmail/supervise/qmail-smtpd
chmod +t /var/qmail/supervise/qmail-pop3d/log
chmod +t /var/qmail/supervise/qmail-pop3ds/log
cp /usr/local/qmail_src/toaster-scripts-0.8.1/send.run /var/qmail/supervise/qmail-send/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/send.log.run /var/qmail/supervise/qmail-send/log/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/smtpd.run /var/qmail/supervise/qmail-smtpd/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/smtpd.log.run /var/qmail/supervise/qmail-smtpd/log/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/pop3d.run /var/qmail/supervise/qmail-pop3d/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/pop3d.log.run /var/qmail/supervise/qmail-pop3d/log/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/pop3ds.run /var/qmail/supervise/qmail-pop3ds/run
cp /usr/local/qmail_src/toaster-scripts-0.8.1/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

#啟動腳本:

cp /usr/local/qmail_src/toaster-scripts-0.8.1/rc /var/qmail/
cp /usr/local/qmail_src/toaster-scripts-0.8.1/qmailctl /var/qmail/bin/
chmod 755 /var/qmail/rc
chmod 755 /var/qmail/bin/qmailctl

ln -s /var/qmail/bin/qmailctl /usr/bin
ln -s /var/qmail/bin/sendmail /usr/sbin/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

sleep 5
qmailctl stat


日志:
/var/log/maillog
/var/log/qmail/current
/var/log/qmail/pop3d/current
/var/log/qmail/pop3ds/current
/var/log/qmail/smtpd/current

## Vpopmail ##
groupadd -g 89 vchkpw
useradd -u 89 -g vchkpw vpopmail

mkdir -p /home/vpopmail
mkdir -p /home/vpopmail/etc

echo "shengmax.com" > /home/vpopmail/etc/defaultdomain

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

echo "localhost|0|vpopmail|cys12345|vpopmail" > /home/vpopmail/etc/vpopmail.mysql

chmod 640 /home/vpopmail/etc/vpopmail.mysql
chown -R vpopmail.vchkpw /home/vpopmail/etc

cd /usr/local/qmail_src/vpopmail-5.4.13

mysql -uroot -p

CREATE DATABASE vpopmail;
grant all on vpopmail.* to vpopmail@localhost identified by "cys12345";
FLUSH PRIVILEGES;
QUIT;


tar zxvf vpopmail-5.4.13.tar.gz
cd vpopmail-5.4.13

./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

make
make install-strip

#管理:
echo 'export PATH=$PATH:/home/vpopmail/bin' >> /etc/profile
source /etc/profile

# 添加域,前面是域名,后面是管理(postmaster)密碼
vadddomain shengmax.com
cys12345
cys12345

#如果你想設定郵箱容量限制,那麼修改 vlimits.default:
vi ~vpopmail/etc/vlimits.default
# in particular set the default mailbox size to be something reasonable eg 10Mb
default_quota 1024576 (修改這個內容,默認的是10M; 50M=52428800)

# 添加用戶
vadduser max@shengmax.com cys12345
vmoduser -c MAX max@shengmax.com

# 設置郵箱容量達到90%的警告信息
vi /home/vpopmail/domains/.quotawarn.msg

From: 電子郵件管理員
Reply-To: max@shengmax.com
To: 電子郵件用戶
Subject: 電子郵件空間警告
Mime-Version: 1.0
Content-Type: text/html; charset=big5
Content-Transfer-Encoding: base64

您的電子郵件空間已經達到90%.如果想繼續使用,請刪除一些信件.
如果需要協助,請聯絡電子郵件管理員:
Email : max@shengmax.com

# 設置電子郵件已滿的警告信息
echo "電子郵件被拒絕,用戶的電子郵件空間已滿." > /home/vpopmail/domains/.over-quota.msg

#啟動腳本:

cp /usr/local/qmail_src/toaster-scripts-0.8.1/vpopmailctl /var/qmail/bin
ln -s /var/qmail/bin/vpopmailctl /usr/bin
chmod 755 /var/qmail/bin/vpopmailctl

# 用daemontools來啟動qmail-pop3d和qmail-pop3ds
ln -s /var/qmail/supervise/qmail-pop3d /service
ln -s /var/qmail/supervise/qmail-pop3ds /service

#修正:

# mysql支持
cd /usr/local/qmail_src/netqmail-1.05/netqmail-1.05
bunzip2 -c ../../qmail-toaster-0.8.3.patch.bz2 | patch -p0
make clean
make
qmailctl stop
make setup check
qmailctl start


## Courier-IMAP ##
rpm -ivh ftp://ftp.pbone.net/mirror/ftp.pld-linux.org/dists/1.0/PLD/i386/PLD/RPMS/expect-5.37-1.i386.rpm ftp://ftp.pbone.net/mirror/www.python.org/pyvault/centos-3-i386/tcltk83-8.3.5-2.el3.pyv.i386.rpm
tar -xjvf courier-authlib-0.58.tar.bz2
cd courier-authlib-0.58
chown -R vpopmail:vchkpw ../courier-authlib-0.58
su vpopmail
umask 0022

./configure --with-redhat
make
exit
make install-strip
make install-configure

cp courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod 755 /etc/init.d/courier-authlib
ln -s ../init.d/courier-authlib /etc/rc0.d/K30courier-authlib
ln -s ../init.d/courier-authlib /etc/rc1.d/K30courier-authlib
ln -s ../init.d/courier-authlib /etc/rc2.d/S80courier-authlib
ln -s ../init.d/courier-authlib /etc/rc3.d/S80courier-authlib
ln -s ../init.d/courier-authlib /etc/rc4.d/S80courier-authlib
ln -s ../init.d/courier-authlib /etc/rc5.d/S80courier-authlib
ln -s ../init.d/courier-authlib /etc/rc6.d/K30courier-authlib

#Configure:
vi /usr/local/etc/authlib/authdaemonrc
Change authmodulelist="..." to authmodulelist="authvchkpw"

#Start Authlib's Authdaemon Server
/etc/init.d/courier-authlib start
cd ..

tar -xjvf courier-imap-4.1.1.tar.bz2

cd courier-imap-4.1.1

chown -R vpopmail:vchkpw ../courier-imap-4.1.1
su vpopmail
umask 0022

./configure --with-redhat

make
exit
make install-strip
make install-configure

cp courier-imap.sysvinit /etc/init.d/courier-imap
chmod 755 /etc/init.d/courier-imap
ln -s ../init.d/courier-imap /etc/rc0.d/K30courier-imap
ln -s ../init.d/courier-imap /etc/rc1.d/K30courier-imap
ln -s ../init.d/courier-imap /etc/rc2.d/S80courier-imap
ln -s ../init.d/courier-imap /etc/rc3.d/S80courier-imap
ln -s ../init.d/courier-imap /etc/rc4.d/S80courier-imap
ln -s ../init.d/courier-imap /etc/rc5.d/S80courier-imap
ln -s ../init.d/courier-imap /etc/rc6.d/K30courier-imap

#Configure:
vi /usr/lib/courier-imap/etc/imapd
Change 'IMAPDSTART=NO' to 'IMAPDSTART=YES'

vi /usr/lib/courier-imap/etc/imapd-ssl
Change 'IMAPDSSLSTART=NO' to 'IMAPDSSLSTART=YES'

# optional: The first time courier-imap is started, the SSL certificate
# is first created using "localhost" as the "common name".
# If you want to change this to match your hostname, you can customize
# the CN line in /usr/lib/courier-imap/etc/imapd.cnf (and pop3d.cnf of
# you choose to use courier's pop3d) so that the common name matches
# your server name BEFORE you start the server for the first time


#Start IMAP server
/etc/init.d/courier-imap start
cd ..



## autorespond ##

tar -xzvf autorespond-2.0.4.tar.gz
cd autorespond-2.0.4
patch -p1 < ../autorespond-2.0.4-2.0.5.patch
make
make install
cd ..



## ezmlm-idx ##

tar -xzvf ezmlm-0.53.tar.gz
tar -xzvf ezmlm-idx-0.443.tar.gz
mv ezmlm-idx-0.443/* ezmlm-0.53/ -f
cd ezmlm-0.53
patch -p0 < idx.patch
make
make setup
cd ..


## Qmailadmin ##

#Info: http://sourceforge.net/projects/qmailadmin

#Install:

tar -xzvf qmailadmin-1.2.10.tar.gz
cd qmailadmin-1.2.10
./configure --enable-help --enable-htmldir=/var/www/html --enable-cgibindir=/var/www/cgi-bin
make
make install-strip
cd ..
tar -xzvf qmailadmin-help-1.0.8.tar.gz
cd qmailadmin-help-1.0.8
mkdir /var/www/html/images/qmailadmin/help
cp -rp * /var/www/html/images/qmailadmin/help

cd ..


http://mail.shengmax.com/cgi-bin/qmailadmin

## qmail的防垃圾郵件 ##

1.封ip

針對有些垃圾郵件發送方是固定的ip或者固定ip段,那我們可以限制他們的smtp連接

vi tcp.smtp

218.61.128.61:deny
限制218.61.128.61的機器跟我的qmail服務器有任何smtp的連接
或者:

218.61.128.:deny
禁止218.61.128網段的機器跟我的qmail有任何的smtp連接。
然後

tcprules tcp.smtp.cdb tcp.smtp.tmp < tcp.smtp
生成新的tcp.smtp.cdb

當然你也可以通過iptables來限制smtp端口的連接。

2.封某個帳號
主要針對某些比較正規的垃圾郵件發送者

vi /var/qmail/control/badmailfrom

編輯/var/qmail/control/badmailfrom文件(如果沒有可以新建一個)將要拒收的郵件地址寫入,每條記錄?一行如:
    

123@123.com

  這樣所有FROM來自123@123.com的郵件都會被郵件服務器拒收。

  同樣也可以對一個域進行拒收,在badmailfrom文件中加入
    

@test.com

  這樣所有來自test.com的任何地址的電子郵件都會被服務器拒收。


3.設置.qmail-default文件
vi /var/qmail/alias/.qmail-default

/var/vpopmail/bin/vdelivermail '' bounce-no-mailbox
這樣垃圾郵件發過來,如果是一個不存在的郵箱,會自動彈回郵件,並告知no this mailbox


4。使用第三方的rbl服務,其實就是利用dns反查詢,可以防止有些人自架mail server發垃圾信的行為。

我用的是中國反垃圾郵件聯盟的CDL+DNS反查詢方式的實時黑名單技術,這個服務是免費的,但必須申請才能使用

申請服務後,在你的SMTP?動腳本,加上/usr/local/bin/rblsmtpd,如下

#!/bin/sh
QMAILDUID=qmaild
NOFILESGID=nofiles

/usr/local/bin/tcpserver -H -R -l 0 -t 1 -v -p -x /var/vpopmail/etc/tcp.smtp.cdb -u $QMAILDUID -g $NOFILESGID 0
smtp /usr/local/bin/rblsmtpd -r cblplus.anti-spam.org.cn/var/qmail/bin/qmail-smtpd hostname /var/vpopmail/bin
/vchkpw /bin/true /bin/cmd5checkpw /bin/true 2>&1 | /var/qmail/bin/splogger smtpd 3 &


## sqwebmail ##

查看/home/vpopmail/etc/目錄下有沒有inc_deps及lib_deps這兩個文件。
若沒則需建立這兩個文件。
內容如下:
inc_deps的內容如下:

  -I/home/vpopmail/include

ib_deps的內容如下:

  -L/home/vpopmail/lib -lvpopmail

(如不建的話./configure 時會出錯喲)

設置環境變數(加在root得.basrc)

INCS=-I/usr/include/mysql
export INCS
LIBS="-L/usr/lib/mysql -lmysqlclient -lz"
export LIBS
CPPFLAGS=-I/usr/include/mysql
LDFLAGS=-L/usr/lib/mysql
export CPPFLAGS
export LDFLAGS



./configure --with-cachedir --without-gzip --enable-webpass=yes --enable-softtimeout=300 --enable-autopurge=180 --enable-maxpurge=180 --with-htmldir=/ShareHome/php/sqwebmail --with-htmllibdir=/ShareHome/php/sqwebmail --enable-cgibindir=/ShareHome/php/sqwebmail/cgi-bin --enable-imagedir=/ShareHome/php/sqwebmail/images --enable-imageurl=/images --enable-mimecharset=big5 --with-maxargsize=5000000 --with-maxformargsize=5000000 --with-maxmsgsize=5000000 --without-ispell --with-authshadow --with-authmysql --with-authldap --with-authuserdb --with-authpwd --without-authpam --with-authvchkpw --without-authdaemon
./configure --with-cachedir --without-gzip --enable-webpass=yes --enable-softtimeout=300 --enable-autopurge=180 --enable-maxpurge=180 --with-htmldir=/ShareHome/php/sqwebmail --with-htmllibdir=/ShareHome/php/sqwebmail --enable-cgibindir=/ShareHome/php/sqwebmail/cgi-bin --enable-imagedir=/ShareHome/php/sqwebmail/images --enable-imageurl=/images --enable-mimecharset=big5 --with-defaultlang=big5 --with-maxargsize=5000000 --with-maxformargsize=5000000 --with-maxmsgsize=5000000 --without-ispell --with-authshadow --with-authmysql --with-authldap --with-authuserdb --with-authpwd --without-authpam --with-authvchkpw --without-authdaemon
make configure-check
make check
make
make install-strip
make install-configure

沒有留言: