二.郵件發送接收相關包的安裝
再繼續安裝前先清理一下系統自帶的一些軟件
Sendmail相關包rpm –q sendmail
sendmail-8.13.8-2.el5
----------------------------------------------
清除:
rpm -e sendmail --nodeps
Sasl 相關包列出 rpm -qa|grep sasl
cyrus-sasl-2.1.22-4
cyrus-sasl-devel-2.1.22-4
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-lib-2.1.22-4
---------------------------------------------
清除:
rpm -e --nodeps cyrus-sasl cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-lib
然後是創建以下用戶及組
用戶名 |
組名 |
作用 |
備註 |
mysql |
mysql |
數據庫mysql運行用戶 |
以上已創建 |
vmail |
vmail |
nginx 服務運行用戶 |
以上已創建 |
vmail |
vmail |
Postfix虛擬郵件帳號所使用的用戶及組 |
uid,gid:1001,1001 |
postfix |
Postfix |
Postfix主程序使用的帳號和組 |
Uid,gid:1000,1000 |
|
Postdrop |
Postfix setgid_group |
setgid_group=postdrop 1002 |
amavis |
amavis |
郵件掃描 |
|
clamav |
Clamav |
病毒掃描 |
|
ln -s /usr/src/kernels/2.6.18-128.el5-i686 /usr/src/linux //避免以下安裝編譯出現問題
一.安裝courier-authlib
安裝過程:
……………………………安裝開始………………………………………………
Shell> tar jxvf courier-authlib-0.62.2.tar.bz2
Shell> cd courier-authlib-0.62.2
Shell>./configure
--with-mailuser=vmail --with-mailgroup=vmail
--with-mysql-libs=/usr/local/mysql/lib/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql
--prefix=/usr/local/authlib
--without-stdheaderdir
Shell> make && make install
Shell> make install-configure
…………………………安裝結束……………………………………………
---------------------------------------------------------
一般情況下,anthlib的安裝應該是容易完成的。
配置:
配置authlib.在目錄/usr/local/authlib/etc/authlib中,修改文件authdaemonrc及authmysqlrc。
vim /usr/local/authlib/etc/authlib/authdaemonrc
vi /usr/local/authlib/etc/authlib/authdaemonrc authmodulelist="authmysql" authmodulelistorig="authmysql" DEBUG_LOGIN=2
修改上面3項,其他的項保持不變。這個修改前2行表示用mysql認證模塊;把DEBUG_LOGIN的值有默認的“0”改成“2”的用意是運行postfix時有更多的信息輸出,通過生成的日誌以幫助排錯。 |
vi /usr/local/authlib/etc/authlib/authmysqlrc MYSQL_SERVER localhost MYSQL_USERNAME extmail MYSQL_PASSWORD extmail
MYSQL_DATABASE extmail
MYSQL_SOCKET /usr/local/mysql/tmp/mysql.sock
MYSQL_PORT 3306 MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password //這裏需要注意 #MYSQL_CLEAR_PWFIELD password
DEFAULT_DOMAIN mail.test.com MYSQL_UID_FIELD ‘1001’ MYSQL_GID_FIELD ‘1001’
MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD '/var/mailbox/'
MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD maildir MYSQL_QUOTA_FIELD concat(quota,'S') MYSQL_WHERE_CLAUSE active='1'
特別注意MYSQL_UID_FIELD和MYSQL_GID_FIELD字段的值,這裏是‘1001’,也可以是其它的,但一定要與vmail用戶及組相一致(id vmail可以得出這2者的值) |
後續工作還有,所以現在還不能測試。
-------------------------------------------------------
二.安裝SASL
cyrus-sasl-2.1.22.tar.gz
安裝過程:
……………………………安裝開始………………………………………………
Shell> tar zxvf cyrus-sasl-2.1.22.tar.gz
Shell> cd cyrus-sasl-2.1.22
Shell> ./configure --disable-anon
--disable-gssapi //授權
--disable-sample
--disable-digest //授權
--enable-plain
--enable-login
--enable-sql
--with-mysql=/usr/local/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql
--with-mysql-libs=/usr/local/mysql/lib/mysql
--with-authdaemond=/usr/local/authlib/var/spool/authdaemon/socket
Shell> make
Shell> make install
…………………………安裝結束……………………………………………
配置:
ln -s /usr/local/lib/sasl2 /usr/lib/sasl2 //sasl的安裝目錄是/usr/local/lib/sasl //安裝結束後有Warning警告
echo “/usr/local/lib” >> ld.so.conf //否則postfix 編譯裏會找不到libsasl2.so.2
創建文件 /usr/local/lib/sasl2/smtpd.conf,並加入如下內容:
pwcheck_method: authdaemond
mech_list: PLAIN LOGIN
log_level: 3
authdaemond_path: /usr/local/authlib/var/spool/authdaemon/socket |
Sasl2需要使用文件/usr/local/authlib/var/spool/authdaemon/socket,但默認情況下,其屬性是744,需要把它加上執行權限,以便文件屬組(主)而外的其它用戶可以執行。運行命令
chmod +x /usr/local/authlib/var/spool/authdaemon即可,如果不這樣處理,smtp驗證無一例外會失敗的。
創建運行時需要的目錄並調試啓動
# mkdir -pv /var/state/saslauthd
# /usr/local/sbin/saslauthd -v //看看版本是不是2.1.22
saslauthd 2.1.22
authentication mechanisms: getpwent pam rimap shadow
# /usr/local/sbin/saslauthd -a shadow pam -d //正常不會報錯
啓動並測試
# /usr/local/sbin/saslauthd -a shadow pam
# /usr/local/sbin/testsaslauthd -u root -p password //正常顯示0: OK "Success"成功
(Password改成機器登錄賬號root 的密碼,這裏不是賬號不是指的MySQL賬號密碼。否則會提示:
0: NO "authentication failed",同時,注意這裏測試不用開啓authdaemond(authlib)
加入開機自啓動
Echo “/usr/local/sbin/saslauthd -a shadow pam” >>/etc/rc.local
三.安裝postfix
Make參數參考:安裝源文件READ_FILES目錄
# more README_FILES/MYSQL_README
安裝過程:
……………………………安裝開始………………………………………………
Shell> tar zxvf postfix-2.5.6.tar.gz
Shell> cd postfix-2.5.6
Shell> make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/local/lib -lsasl2'
@@注意:1. 如果沒有Makefile文件,需要設置成make -f Makefile.init
2. /usr/local/mysql/include 如果此目錄下還有mysql目錄,應改成/usr/local/mysql/include/mysql
3. /usr/local/mysql/lib 如果此目錄下還有mysql目錄,應改成/usr/local/mysql/lib/mysql
如果沒有意外,make這一步很快就執行完了,接下來就是安裝,使用的命令是
Shell> make install
程序先自動執行一陣子,然後會進入交互狀態,等待用戶的輸入,一般情況下,一路回車即可完成所有的安裝。
最後:
生成別名二進制文件,這個步驟如果忽略,會造成postfix效率極低:
shell> /usr/bin/newaliases
…………………………安裝結束……………………………………………
檢驗postfix是否支持sasl認證,如果輸出爲以下結果,則支持:
shell> /usr/sbin/postconf -a //postfix 安裝沒有指定目錄
cyrus
dovecot
shell> /usr/sbin/postconf -m |grep mysql
mysql //沒有的話需重新編譯postfix
四.安裝imap
Postfix只是實現郵件系統的smtp功能,pop3或imap則需要另外的軟件來實現,這個軟件就是courier-imap(當然也有別的軟件可以選擇)。
……………………………安裝開始………………………………………………
Shell> tar jxvf courier-imap-4.4.1.tar.bz2
Shell> cd courier-imap-4.4.1
Shell>./configure
--prefix=/usr/local/imap
--with-redhat
--disable-root-check
--enable-unicode=utf-8,iso-8859-1,gb2312,gbk,gb18030
--with-trashquota
--with-dirsync
--with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql
--with-authmysql
--with-authmysql=yes
CPPFLAGS='-I/usr/local/authlib/include' LDFLAGS='-L/usr/local/authlib/lib/courier-authlib'
COURIERAUTHCONFIG='/usr/local/authlib/bin/courierauthconfig'
[以上時間長一些]
Shell> make
Shell> make install
Shell> make install-configure
……………………………安裝結束………………………………………………
配置:
……………………………配置開始………………………………………………
修改配置文件/usr/local/imap/etc/pop3d及/usr/local/imap/etc/imapd。把/usr/local/imap
/etc/pop3d 文件的行“POP3DSTART=NO”改成“POP3DSTART=YES”,再依照這個形式把文件/usr/local/imap/etc/imapd的行“IMAPDSTART=NO”改成“IMAPDSTART=YES”即可。
加入開機啓動:
cp courier-imap.sysvinit /etc/rc.d/init.d/imapd // courier-imap.sysvinit在安裝源文件中
chmod +x /etc/rc.d/init.d/imapd
chkconfig --add imapd
[chkconfig --level 2345 imapd on]
Service imapd start //輸出Starting Courier-IMAP server: imap pop3
檢測:
netstat -tnl|egrep "110|143"
五.安裝pcre
安裝前先卸載系統自帶的pcre-6.6-1.1
Rpm –e pcre
自帶的pcre RPM包可能與一些有衝突,可以先卸載掉
Shell> rpm –e pcre如果提示libpcre.so.0與別的軟件有依存關係。可以這樣
先備份一下libpcre.so.0這個文件,然後。
Shell> rpm -e pcre –nodeps
……………………………安裝開始………………………………………………
Shell> tar zxvf pcre-7.8.tar.gz
Shell> cd pcre-7.8
Shell> ./configure
Install prefix .................. : /usr/local
C preprocessor .................. : gcc -E
C compiler ...................... : gcc
C++ preprocessor ................ : g++ -E
C++ compiler .................... : g++
Linker .......................... : /usr/bin/ld
C preprocessor flags ............ :
C compiler flags ................ : -O2
C++ compiler flags .............. : -O2
Linker flags .................... :
Extra libraries ................. :
Build C++ library ............... : yes
Enable UTF-8 support ............ : no
Unicode properties .............. : no
Newline char/sequence ........... : lf
\R matches only ANYCRLF ......... : no
EBCDIC coding ................... : no
Rebuild char tables ............. : no
Use stack recursion ............. : yes
POSIX mem threshold ............. : 10
Internal link size .............. : 2
Match limit ..................... : 10000000
Match limit recursion ........... : MATCH_LIMIT
Build shared libs ............... : yes
Build static libs ............... : yes
Link pcregrep with libz ......... : no
Link pcregrep with libbz2 ....... : no
Link pcretest with libreadline .. : no
Shell> make
Shell> make install
……………………………安裝結束………………………………………………
六.安裝maildrop
注意%源碼安裝的,將courierauthconfig 命令鏈接到/usr/bin裏,假設裝在:
/usr/local/authlib/bin/courierauthconfig,則:
ln -s /usr/local/authlib/bin/courierauthconfig /usr/bin/courierauthconfig
這樣編譯出來的maildrop纔會Courier Authentication Library extension enabled.
……………………………安裝開始………………………………………………
Shell> tar jxvf maildrop-2.0.4.tar.bz2
Shell> cd maildrop-2.0.4
Shell>./configure
--enable-sendmail=/usr/sbin/sendmail
--enable-trusted-users='root vmail'
--enable-syslog=1
--enable-maildirquota
--enable-maildrop-uid=1001
--enable-maildrop-gid=1001
--with-trashquota
--with-dirsync
Shell> make
Shell> make install
Shell> cp /usr/local/bin/maildrop /usr/bin //可有可無
……………………………安裝結束………………………………………………
驗證安裝是否成功:
Shell> maildrop –v
[root@localhost postfix]# /usr/local/bin/maildrop -v
maildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.
GDBM extensions enabled.
Courier Authentication Library extension enabled. //這行重要,沒有的話要查一下原因
Maildir quota extension enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.
FAQ:
如果沒有顯示Courier Authentication Library extension enabled.說明你的maidrop還不支持courier auth,請仔細檢查,重新編譯maildrop建議不要自定義目錄安裝,可以減少不必要的麻煩,刪除很方便:直接在已經編譯的源代碼目錄 make uninstall 就行
知道maildrop把郵件移動到哪個用戶目錄還是非常有必要的,這個操作就是maildrop的日誌記錄。這裏我們創建一個新文件/etc/maildroprc,這個文件就2行內容:如果加入反SPAM,需要更改以下內容
[root@mail mailbox]# more /etc/maildroprc
logfile "/var/log/maildrop.log"
to "$HOME/$DEFAULT" |
Shell> touch /var/log/maildrop.log
Shell> chown vmail.vmail /var/log/maildrop.log
shell> chown vmail.vmail /var/mailbox