天天看點

qmail+LDAP的配置

确認下面的軟體是否已經安裝:

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]

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

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編譯安裝

#注:qmail的更新檔在vpopmail安裝之後再打。

# 用你自己的主機名代替下面的mail.domain.com

./config-fast mail.domain.com

#設定管理者的郵箱位址。

#發往root/postmaster/mailer-daemon位址的郵件将會由定義的管理者郵箱接收。

#将如下的“[email][email protected][/email]"替換成你的管理者郵箱。

cd /var/qmail/alias

echo "[email][email protected][/email]" > .qmail-postmaster

echo "[email][email protected][/email]" > .qmail-mailer-daemon

echo "[email][email protected][/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

#啟動腳本:

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 install-strip

#管理:

echo 'export PATH=$PATH:/home/vpopmail/bin' >> /etc/profile

source /etc/profile

# 添加域,紅色部份前面是域名,後面是管理者(postmaster)密碼

vadddomain domain.com xukixu

# 添加使用者,紅色部份為注解,不用輸入

vadduser -q 10485760S(郵箱大小) [email][email protected][/email](郵箱帳号) 1234(密碼)

vmoduser -c 許靖(郵箱描述) [email][email protected][/email]

# 設定郵箱容量達到90%的警告資訊

vi /home/vpopmail/domains/.quotawarn.msg

From: 郵箱管理者

Reply-To: [email][email protected][/email]

To: 郵箱使用者

Subject: 郵箱空間警告

Mime-Version: 1.0

Content-Type: text/html; charset=gb2312

Content-Transfer-Encoding: base64

您的郵箱空間已經達到90%.如果想繼續使用,請删除一些信件.

如果需要幫助,請聯系郵箱管理者:

Email : [email][email protected][/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

qmailctl stop

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 []:[email protected]

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

#POP3和SMTP測試

用outlook測試qmail的smtp和pop3是否正常,注意由于vpopmail支援虛拟域名,是以在outlook中設定郵件帳号時,使用者名後要加上域名,如[email][email protected][/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][email protected][/email] 1121221

         Authenticated: [email][email protected][/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

    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"選項

    exit

    make install-strip

    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

    [email protected]

# 修改檔案/usr/lib/courier-imap/etc/pop3d.cnf

#啟動:

    /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就行了)

    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

    mv squirrelmail-1.4.4 /var/www/html/squirrelmail

     

#登入[url]http://domain.com/squirrelmail[/url] 驗證是否安裝成功。

安裝Ezmlm

exmlm是一個快速,強大的郵件清單程式,可以通過qmailadmin對其進行配置

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 man

#漢字GB2312支援

make ch_GB

make setup

第十三節:安裝qmailadmin TOP

qmailadmin除了不能添加删除虛拟域外,幾乎可以完成所有的虛拟域管理

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

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。現在我們将其更新到最新版:

    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

下圖是我在安裝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

#安裝軟體

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

LogFile /var/log/clamav/clamd.log \\去掉前面的#

LogFileMaxSize 2M \\去掉前面的#

LogTime \\去掉前面的#

PidFile /var/run/clamd.pid \\去掉前面的#

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 }"

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:

#               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 設定目錄項索引

要伺服器正常動作,要修改一些始初參數和設定,修改後的配置文檔如下:

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

pidfile         /usr/local/openldap/var/slapd.pid

loglevel 1 增加了日志功能,需修改syslog配置檔案,在檔案中增加一項:local4.* /var/log/ldap.log

                                日志級别定義可查相官方網站的文檔。1級記錄的資訊很多。可用于調試。

allow bind_v2 (這裡一定要設,因為squirrelmail支援LDAP——v2)

#                Allow anonymous users to authenticate

database        bdb

suffix          "dc=it,dc=com" 改成你自已的目錄字尾,

rootdn          "cn=root,dc=it,dc=com" 設定root為管理者,與linux的root沒有什麼關系。

rootpw          {MD5}mjkiuPt0wXhpxxkdiOOO+0000000AKq0by 設定root密碼,用MD5加密。密碼串用slappasswd -h {MD5}指令

directory       /usr/local/openldap/var/openldap-data   

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:[email protected]

輸入完所有資訊後,按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][email protected][/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)

allow bind_v2    在這裡加上這行,讓他支援V2版本

                     因為我們把 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,就可以顯示了,可能是版本不相容吧!!

繼續閱讀