postfix郵件系統(tǒng)
Funcity mail system 運(yùn)維部Postfix mail system一、
Funcity mail system 運(yùn)維部
Postfix mail system
一、 所需軟件包 . .......................................................... 2
二.查看系統(tǒng)的AMP 環(huán)境是否搭建好,建議關(guān)閉selinux ........................... 3
三、安裝BerkeleyDB (BerkeleyDB ,在配置虛擬域后并沒(méi)有用到可跳過(guò)) ............ 3
四、安裝Postfix ............................................................. 4
五、安裝courier-authlib ..................................................... 5
編輯/etc/ authmysqlrc文件,并將其內(nèi)容清空,然后增加如下內(nèi)容: ........... 5
六、編譯安裝cyrus-sasl ...................................................... 6
smtp 測(cè)試 ................................................................ 8
七、安裝courier-imap ........................................................ 9
1) 配置Courier-IMAP ,為用戶提供pop3服務(wù): ............................. 9
2) 設(shè)置Courier-IMAP 開(kāi)機(jī)自動(dòng)運(yùn)行: . ..................................... 9
八、安裝maildrop ............................................................ 9
編輯master.cf .......................................................... 10
編輯main.cf ............................................................ 10
更改/usr/sbin/suexec文件權(quán)限 ........................................... 11
查看 suexec . ............................................................ 11
九、extmail extman . ......................................................... 13
十、啟動(dòng)相關(guān)程序并將其加入啟動(dòng)項(xiàng),一個(gè)具有收發(fā)功能的mail server到至設(shè)置完畢 14
十一、下面介紹使用 foxmail,outlook 收發(fā)郵件 ................................ 14
十二、收郵件測(cè)試 . ........................................................... 15
POP 測(cè)試 ................................................................ 15
IMAP 測(cè)試 ............................................................... 15
本地域名與虛擬域名沖突 . ................................................. 15
十三、配置Mailgraph_ext .................................................... 15
1
,Funcity mail system 運(yùn)維部
(注:綠色部分可以跳過(guò)不執(zhí)行,紅色部分請(qǐng)注意)
郵件系統(tǒng)搭建之前確定DNS 的一條MX 記錄和一條A 記錄指向mail server
注意MX 記錄,與A 記錄的指向mail server如果不用A 記錄用ip 直接訪問(wèn)應(yīng)該也可以
1)#dig mm.qeedoo.com mx
2)#nslookup
>set q=mx
>mm.qeedoo.com
一、所需軟件包
1) 環(huán)境(LAMP )linux apache mysql php本文均采用redhat (AS 4)自帶的軟件包安裝
2)其它rpm 包(基本的gd 庫(kù)gdbm jpeg zlib png freetype quote 一般會(huì)默認(rèn)安裝如果系統(tǒng)為定制請(qǐng)檢查下)下面三個(gè)包中的pcre 請(qǐng)?zhí)貏e注意下一般不會(huì)默認(rèn)安裝
·ldap
[root@localhost ~]# rpm -qa|grep ldap
python-ldap-2.2.0-2.1
openldap-2.3.43-3.el5
openldap-clients-2.3.43-3.el5
nss_ldap-253-17.el5
·sasl
[root@localhost ~]# rpm -qa|grep sasl
cyrus-sasl-2.1.22-4
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-lib-2.1.22-4
·pcre
[root@localhost ~]# rpm -qa|grep pcre
pcre-6.6-2.el5_1.7
pcre-devel-6.6-2.el5_1.7
·libdbi
·libdbi-drivers
·libdbi-dbd-mysql
·openssl
3) 編譯使用的tar 包
a)
·courier-imap
·ourier-authlib
·maildrop
上述三個(gè)包均可從下面地址下載 http://www.courier-mta.org/download.php
b)
·postfix
可從下面地址下載postfix 需要手動(dòng)編譯支持mysql ,一般系統(tǒng)自帶的postfix 不支持mysql http://www.postfix.org/
c)
·extmail
2
,Funcity mail system 運(yùn)維部
·extman http://www.extmail.org
d )
Unix-Syslog http://search.cpan.org/~mharnisch/Unix-Syslog-1.1/Syslog.pm
e)
BerkeleyDB http://www.oracle.com/technology/products/berkeley-db/index.html
二.查看系統(tǒng)的AMP 環(huán)境是否搭建好,建議關(guān)閉selinux
1)/etc/sysconfig/selinux
SELINUX=disabled
Disable 掉后需要重啟系統(tǒng)
2)如果使用了selinux 使用ls 查看文件相關(guān)設(shè)置,一般http 需要訪問(wèn)的需要帶有httpd_sys_content_t字段,如果文件通過(guò)web 界面執(zhí)行后發(fā)現(xiàn)web 程序執(zhí)行有問(wèn)題請(qǐng)查看message 和http 的error.log 兩日志文件判斷是否是由于selinux 的開(kāi)啟所造成的
[root@localhost ~]# ls -laZ /var/www/
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 .
drwxr-xr-x root root system_u:object_r:var_t:s0 ..
drwxr-xr-x root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 error
drwxr-xr-x root root extsuite
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 html
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 icons
3)如果是selinux 所造成的,但又暫時(shí)不能關(guān)閉selinux, 或者使用網(wǎng)上所說(shuō)的不重啟關(guān)閉時(shí),一時(shí)無(wú)法解決時(shí),即要根據(jù)能訪問(wèn)的目錄來(lái)設(shè)置策略字段
[root@localhost html]# chcon -R -t httpd_sys_content_t /var/www/mail/
再查看策略字段,一般/var/www目錄下的不需要設(shè)置,在該目錄添加時(shí)會(huì)自動(dòng)加上策略,注意mail 的存放目錄/var/mailbox的selinux 策略
[root@localhost ~]# ls -laZ /var/www/mail
三、安裝BerkeleyDB (BerkeleyDB ,在配置虛擬域后并沒(méi)有用到可跳過(guò))
[root@localhost ~]# cd db-4.7.25/build_unix/
[root@localhost build_unix]# ../dist/configure --prefix=/usr/local/BerkeleyDB&& make && make install
[root@localhost build_unix]# mv /usr/include/db4 /usr/inculde/db4.OFF
[root@localhost build_unix]# rm -rf /usr/include/db_cxx.h /usr/include/db.h /usr/include/db_185.h
[root@localhost build_unix]# ln -sv /usr/local/BerkeleyDB/include /usr/include/db4
[root@localhost build_unix]# ln -sv /usr/local/BerkeleyDB/include/db.h /usr/include/db.h
[root@localhost build_unix]# ln -sv /usr/local/BerkeleyDB/include/db_cxx.h 3
,Funcity mail system 運(yùn)維部
/usr/include/db_cxx.h
配置庫(kù)文件搜索路徑
[root@localhost build_unix]# echo "/usr/local/BerkeleyDB/lib" >> /etc/ld.so.conf
[root@localhost build_unix]# ldconfig -v
四、安裝Postfix
如postfix rpm已安裝把它刪除掉進(jìn)行編譯安裝
a)postfix 帳戶
[root@localhost ~]# adduser postfix -s /sbin/nologin
重新添加postfix 帳戶,注意postfix 的UID 必須大于500因?yàn)槲沂鞘褂盟鼇?lái)執(zhí)行apache suexec 權(quán)限的,此要求執(zhí)行帳戶為普通帳戶即uid 500以上
b) 編譯安裝
[root@localhost postfix-2.6.5]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -I/usr/local/BerkeleyDB/include -DUSE_TLS -I/usr/include/openssl ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2/lib -lsasl2 -L/usr/local/BerkeleyDB/lib -L/usr/lib/ssl/lib -lssl -lcrypto'
[root@localhost postfix-2.6.5]# make && make install
進(jìn)行安裝時(shí)全部使用默認(rèn)選項(xiàng)
生成別名二進(jìn)制文件,這個(gè)步驟如果忽略,會(huì)造成postfix 效率極低:
[root@localhost postfix-2.6.5]# newaliases
進(jìn)行一些基本配置,測(cè)試啟動(dòng)postfix 并進(jìn)行發(fā)信
#vi /etc/postfix/main.cf
修改以下幾項(xiàng)為您需要的配置
myhostname = test.com
myorigin = test.com
mydomain = test.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
使用虛擬域時(shí)綠色部分文字需要注釋掉
inet_interfaces = all開(kāi)啟允許所有網(wǎng)絡(luò)訪問(wèn)
說(shuō)明:
myorigin 參數(shù)用來(lái)指明發(fā)件人所在的域名;
mydestination 參數(shù)指定postfix 接收郵件時(shí)收件人的域名,即您的postfix 系統(tǒng)要接收到哪個(gè)域名的郵件;
myhostname 參數(shù)指定運(yùn)行postfix 郵件系統(tǒng)的主機(jī)的主機(jī)名,默認(rèn)情況下,其值被設(shè)定為本地機(jī)器名;
mydomain 參數(shù)指定您的域名,默認(rèn)情況下,postfix 將myhostname 的第一部分刪除而作為mydomain 的值;
mynetworks 參數(shù)指定你所在的網(wǎng)絡(luò)的網(wǎng)絡(luò)地址,postfix 系統(tǒng)根據(jù)其值來(lái)區(qū)別用戶是遠(yuǎn)程的還是本地的
inet_interfaces 參數(shù)指定postfix 系統(tǒng)監(jiān)聽(tīng)的網(wǎng)絡(luò)接口;
注意:
1、在postfix 的配置文件中,參數(shù)行和注釋行是不能處在同一行中的;
4
,Funcity mail system 運(yùn)維部
2、任何一個(gè)參數(shù)的值都不需要加引號(hào),否則,引號(hào)將會(huì)被當(dāng)作參數(shù)值的一部分來(lái)使用;
3、每修改參數(shù)及其值后執(zhí)行 postfix reload 即可令其生效;但若修改了inet_interfaces,則需重新啟動(dòng)postfix ;
4、如果一個(gè)參數(shù)的值有多個(gè),可以將它們放在不同的行中,只需要在其后的每個(gè)行前多置一個(gè)空格即可;postfix 會(huì)把第一個(gè)字符為空格或tab 的文本行視為上一行的延續(xù);
五、安裝courier-authlib
[root@localhost ~]# tar jxvf courier-authlib-0.62.4.tar.bz2
[root@localhost courier-authlib-0.62.4]#./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --sysconfdir=/etc --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-mailuser=postfix --with-mailgroup=postfix --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
注意redhat 安裝時(shí)需要--with-redhat 選項(xiàng)
[root@localhost courier-authlib-0.62.4]# make && make install&& make install-migrate&& make install-configure
chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
cp /etc/authdaemonrc.dist /etc/authdaemonrc
cp /etc/authmysqlrc.dist /etc/authmysqlrc
cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib
chmod 755 /etc/rc.d/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig courier-authlib on
echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf ldconfig
ldconfig –v
service courier-authlib start啟動(dòng)服務(wù)
[root@localhost ~]# vi /etc/authmysqlrc
[root@localhost ~]# echo "" > /etc/authmysqlrc
[root@localhost ~]# vi /etc/authmysqlrc
編輯/etc/ authmysqlrc文件,并將其內(nèi)容清空,然后增加如下內(nèi)容:
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
5
,Funcity mail system 運(yùn)維部
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD 501
MYSQL_GID_FIELD 501
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD homedir
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber, CONCAT('/var/mailbox/',homedir), CONCAT('/var/mailbox/',maildir), quota, name FROM mailbox WHERE username = '$(local_part)@$(domain)'
紅色部分需要根據(jù)情況更改,我這里的用戶是直接用postfix 所以UID ,GID 均是postfix 的,目錄是/var/mailbox下
六、編譯安裝cyrus-sasl
自帶的cyrus-sasl 不支持authdaemon 連接mysql 進(jìn)行帳戶認(rèn)證
下載地址 http://www.linuxfromscratch.org/blfs/view/svn/postlfs/cyrus-sasl.html
刪掉原來(lái)的sasl 目錄,因?yàn)榫幾gpostfix 曾指定sasl2的lib 目錄為/usr/lib/sasl2/,在編譯好sasl 后需要做個(gè)鏈接到/usr/lib/sasl2
[root@s2 cyrus-sasl-2.1.22]# export LDFLAGS="-lpthread"
[root@s2 cyrus-sasl-2.1.22]# ./configure --with-mysql --enable-anon --enable-plain --enable-login --disable-krb4 --disable-otp --disable-cram --disable-digest --disable-gssapi --with-pam --with-authdaemond
[root@s2 cyrus-sasl-2.1.22]# make&& make install
[root@s2 cyrus-sasl-2.1.22]# rm -rf /usr/lib/sasl
[root@s2 cyrus-sasl-2.1.22]# rm -rf /usr/lib/sasl2
[root@s2 cyrus-sasl-2.1.22]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@s2 cyrus-sasl-2.1.22]ln -s /usr/local/lib/sasl2/ /usr/lib/
[root@s2 cyrus-sasl-2.1.22]# ldconfig
[root@s2 usr]# ldconfig -v
[root@s2 usr]# vi /etc/ld.so.conf
Smtpd.conf 的認(rèn)證方法還有courier-authlib 的socket 這兩個(gè)得注意,如果選擇了pam 什 6
,Funcity mail system 運(yùn)維部
么的認(rèn)證方法那請(qǐng)跟著那文章一直走下去吧
[root@s2 sasl2]# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket mech_list: PLAIN LOGIN
log_level: 3
#pwcheck_method: saslauthd
[root@localhost ~]# vi /etc/postfix/main.cf
##############SASL####################
smtpd_sasl_security_options = noanonymous
smtpd_sasl_auth_enable = yes
smtpd_sasl2_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_unauth_destination,
permit
mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
mysql:/etc/postfix/mysql_virtual_alias_maps.cf
smtpd_reject_unlisted_sender = yes
smtpd_sender_restrictions =
# reject_sender_login_mismatch,
# reject_authenticated_sender_login_mismatch,
# reject_unauthenticated_sender_login_mismatch
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
注:
smtpd_sasl_security_options = noanonymous 這個(gè)選項(xiàng)與outlook 有關(guān)如果沒(méi)有使用這個(gè)可能會(huì)造成outlook 使用不正常
mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
mysql:/etc/postfix/mysql_virtual_alias_maps.cf
這兩個(gè)是用來(lái)連接數(shù)據(jù)庫(kù)進(jìn)進(jìn)發(fā)送用的
7
,Funcity mail system 運(yùn)維部
后面的幾個(gè)掉是因?yàn)?/p>
[root@s2~]#postmap -q
mysql:/etc/postfix/mysql_virtual_sender_maps.cf wjh@test.com
查看/etc/postfix/mysql_virtual_sender_maps.cf語(yǔ)句有沒(méi)有問(wèn)題,或返回值
/etc/init.d/saslauthd 這個(gè)服務(wù)不要啟動(dòng),因?yàn)閜ostfix 只是用到里面的一些庫(kù)文件之類的
重啟服務(wù)courier-authlib 與postfix 后測(cè)試:
通過(guò)以下命令獲得test@test.com的用戶名及密碼的BASE64編碼:
perl -e 'use MIME::Base64; print encode_base64("wjh@mm.qeedoo.com")'
d2poQG1tLnFlZWRvby5jb20=
perl -e 'use MIME::Base64; print encode_base64("wjh")'
d2po
smtp 測(cè)試
telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.xsbn.net ESMTP Postfix
auth login
334 VXNlcm5hbWU6
dGVzdEBkYW95b3UuY29t
334 UGFzc3dvcmQ6
dGVzdA==
235 Authentication successful
quit
221 Bye
Vi /etc/authdaemonrc
DEBUG_LOGIN=2 原來(lái)默認(rèn)是打開(kāi)日志信息
[root@s2 ~]# vi /etc/syslog.conf
*.debug /var/log/debug.log
打開(kāi)debug 日志文件 wjh@test.com
8
,Funcity mail system 運(yùn)維部
然后看看/var/log/maillog 在認(rèn)證失敗時(shí)有什么提示。
/var/log/debug.log
七、安裝courier-imap
[root@localhost courier-imap-4.6.0]# ./configure --prefix=/usr/local/courier-imap --with-trashquota --without-ipv6 --with-redhat --enable-unicode=utf-8,iso-8859-1,gb2312,big5 --disable-root-check CPPFLAGS='-I/usr/include/openssl -I/usr/local/courier-authlib/include' LDFLAGS='-L/usr/local/courier-authlib/lib/courier-authlib -L/usr/lib' COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig'
CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
[root@localhost courier-imap-4.6.0]# make && make install && make install-configure
1) 配置Courier-IMAP ,為用戶提供pop3服務(wù):
vi /usr/local/courier-imap/etc/pop3d
POP3DSTART=yes
#DEFDOMAIN="@test.com"此句使用客戶端軟件登錄時(shí),直接使用用戶名登錄即可,但這得配置smtp 服務(wù)一起使用如果smtp 不能直接使用用戶名登錄使用時(shí)這選項(xiàng)最好別用
提供imap 服務(wù)
[root@localhost courier-imap-4.6.0]# vi /usr/local/courier-imap/etc/imapd IMAPDSTART=YES
2) 設(shè)置Courier-IMAP 開(kāi)機(jī)自動(dòng)運(yùn)行:
cp courier-imap.sysvinit /etc/rc.d/init.d/imap
chmod x /etc/rc.d/init.d/imap
chkconfig --add imap
service imap start
注:如果你想為用戶提供IMAP 服務(wù),可以在“/usr/local/courier-imap/etc/imapd”文件中設(shè)置“IMAPDSTART=yes”。
八、安裝maildrop
[root@localhost maildrop-1.7.0]# ./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root postfix' --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=502--enable-maildrop-gid=502 --with-trashquota --with-dirsync
這里直接使用postfix 用戶,安裝時(shí)可以考慮添加vuser,vgroup 等虛擬用戶虛擬組替換 9
,Funcity mail system 運(yùn)維部
postfix
[root@localhost maildrop-1.7.0]# make&& make install
[root@localhost maildrop-1.7.0]# vi /etc/maildroprc
logfile "/var/log/maildrop.log"
[root@localhost maildrop-1.7.0]# touch /var/log/maildrop.log
[root@localhost maildrop-1.7.0]# chown postfix.postfix /var/log/maildrop.log
[root@localhost maildrop-1.7.0]# maildrop –v
配置Postfix
編輯master.cf
# vi /etc/postfix/master.cf
啟用如下兩行
maildrop unix - n n - - pipe
flags=DRhu user=postfix argv=/usr/local/bin/maildrop -d ${recipient}
注意:定義transport 的時(shí)候,即如上兩行中的第二行,其參數(shù)行必須以空格開(kāi)頭,否則會(huì)出錯(cuò)。
編輯main.cf
# vi /etc/postfix/main.cf
####################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:502
virtual_gid_maps = static:502
#virtual_transport = virtual
mailbox_command = maildrop
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps =
mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
10