郵件HA系統(postfix系統的)
發表于:2007-05-25來源:作者:點擊數:
標簽:
郵件HA系統 NOTE: Thisisaprojectinwork,soitcanbechangedonthefly.There'salsonoguar ant eethissetupwillworkforyou. 本項目正在進行中,隨時會有所改變,所以不會保證你的安裝是否有效。 TestedonFreeBSD4.4-RELEASEwithPostfix1.1.4,1(PCRE,OpenLDAP)and
郵件HA系統
NOTE:
This is a project in work, so it can be changed on the fly. There's also no guar
antee this setup will work for you.
本項目正在進行中,隨時會有所改變,所以不會保證你的安裝是否有效。
Tested on FreeBSD 4.4-RELEASE with Postfix 1.1.4,1 (PCRE, OpenLDAP) and OpenLDAP v2. 0. Description簡介
This setup is build with four freebsd boxes, three running postfix, one OpenLDAP. One is "smtp forwarder", reffered to as "forwarder" while other two's are "backend mail storage servers" reffered to as "backends". OpenLDAP server is reffered to as "ldap server".
本安裝需要4個freebsd的系統,3個運行postfix,1個運行OpenLDAP。1個postfix作為smtp轉發器,本文以后稱作“轉發器”,另外兩個作為后端郵件存儲
服務器,本文以后稱作“后端”,OpenLDAP服務器本文稱作ldap服務器。
The idea is to have N forwarders and M backends, all living inependently. When mail comes to forwarder, mail is sent to all, I repeat, all backend servers.
設想有N個轉發器和M個后端,都獨立運行,當郵件到達轉發器,將發送到所有的后端。
Forwarder is publicly available, while others (backends and LDAP) are in private network with LAN IP's (10.10.10.0/24). Forwarder has two NIC's between which is no routing - backends and ldap do not have Internet access!
轉發器可以被公共訪問,后端和LDAP在私有網段(10.10.10.0/24)。轉發器有兩個網卡,之間沒有路由,后端和ldap不能從internet訪問。
This setup allows us to fine-tune access rights for all servers and also to know there's no way for intruders to get to our data (ldap and backends).
本文介紹的安裝可以優化所有服務器的訪問權限,禁止入侵者獲得我們的數據(ldap和后端)。
Here's a picture: 示意圖
For failover system we'll use freevrrpd daemon. Installation and setup is described in my previous article (http://uni.x-si.org/vrrpd.html).
對于故障恢復,我們采用freevrrpd daemon,其安裝和設置請參照http://uni.x-si.org/vrrpd.html
1. LDAP server setup(LDAP服務器設置)
Install OpenLDAP2 on ldap server (http://www.openldap.org/software/download/).
在ldap服務器安裝OpenLDAP2
Ldap schema we use:
#---- start here ----
attributetype ( 2.5.4.80 NAME 'maildrop' SUP mail 
attributetype ( 2.5.4.81 NAME 'mailacceptinggeneralid' SUP mail 
attributetype ( 2.5.4.82 NAME 'mailowner' SUP name 
attributetype ( 2.5.4.83 NAME 'homedir' SUP name 
attributetype ( 2.5.4.90 NAME 'maildrop1' SUP mail 
attributetype ( 2.5.4.91 NAME 'maildrop2' SUP mail 
objectclass ( 2.16.840.1.113730.3.3.1
NAME 'mailUser'
DESC 'x-si.org user'
SUP top
STRUCTURAL
MUST ( uid $ mailowner $ mailacceptinggeneralid $ maildrop
$ maildrop1 $ maildrop2 $ homedir 
MAY ( cn $ mail 
)
#---- end here ----
And relevant parts od slapd.conf:
Od slapd.conf中相關部分:
#---- start here ----
# x-si.org
include /etc/openldap/schema/x-si.schema
database ldbm
suffix "dc=x-si,dc=org"
rootdn "cn=Manager,dc=x-si,dc=org"
# and last, read only access to all
access to *
by * read
#---- end here ----
Ldif file for mail user:
郵件用戶的Ldif文件:
#---- start here ----
dn: cn=makalonca, dc=x-si, dc=org
cn: makalonca
uid: makalonca
mailowner: uid=makalonca, dc=x-si, dc=org
mailacceptinggeneralid: makalonca@x-si.org
mail: makalonca@x-si.org
forward: makalonca@x-si.org
maildrop1: makalonca@backend1.x-si.org
maildrop2: makalonca@backend2.x-si.org
homedir: mail-storage/makalonca/
userPassword: {crypt}agdxu.da.cI5o
mail: makalonca@x-si.org
mail: lonca@x-si.org
mail: hulahup@x-si.org
objectclass: top
objectclass: mailUser
#---- end here ----
Next thing is to populate ldap with this data. Use ldapadd utility to add entries to ldap database (man ldapadd is your friend).
下面就是用這些數據建立ldap,使用ldapadd工具添加ldap
數據庫的記錄(用man ldapadd察看幫助)。
Perhaps quick explanation, why maildrop1 and maildrop2. maildrop1 is result_attribute for postfix on first backend server, while maildrop2 is result_attrribute on second backend server.
簡單解釋一下為什么有maildrop1和maildrop2。Maildrop1是第一個后端服務器postfix的result_attribute,maildrop2是第二個后端服務器的result_attribute。
Obviously, if you want to set up N backend servers, than you need all entries from maildrop1 to maildropN (where N is the count of your backend servers).
顯然,如果需要建立N個后端服務器,就需要所有的記錄,從maildrop1到maildropN,N是后端服務器的數量。
2. Postfix setup(postfix設置)
Install Postfix 1.1.4,1 (with PCRE and OpenLDAP support) on forwarder and both backends (http://x-si.org/postfix/). On backends we'll use postfix's virtual delivery agent to act as local_transport.
在轉發器和后端安裝postfix 1.1.4.1(需要PCRE和OpenLDAP支持),在后端我們用postfix的虛擬分發代理作為local_transport。
On forwarder we'll use PCRE with virtusertable. This will also solve one of the biggest problem - updating aliases in real-time.
在轉發器我們用虛擬用戶表的PCRE,這樣可以解決最大的一個問題——及時更新aliases。
2.1 Forwarder setup (inbound traffic only)(轉發器設置,只接收郵件)
Setup this box to accept mail for our domain x-si.org. No need to define home_mailbox, mailbox_command or mail_spool_directory, because all mail will be forwarded. Nothing will stay on this machine.
安裝本系統接收x-si.org的郵件,無需定義home_mailbox、mailbox_command或mail_spool_directory,因為所有郵件將被轉發,本機不保存任何郵件。
The only thing left to do is, to forward all mails for domain x-si.org to all, I repeat, all backend servers. Here's how:
剩下的就是將x-si.org的所有郵件轉發到所有的后端服務器,操作如下:
/etc/postfix/main.cf:
#---- start here ----
virtual_maps = pcre:/etc/postfix/virtusertable
#---- end here ----
Note: Watch for pcre: (not hash

.
And /etc/postfix/virtusertable:
#---- start here ----
/^(.+)@x-si\.org$/ $1@backend1.x-si.org, $1@backend2.x-si.org
#---- end here ----
(Thanks to Ralf Hildebrandt for this hack)
Now here's a bit of magic. That PCRE regexp will memorize part in parenthesis, to which we have access through $1 variable. In other words, every alias name will be written to all destination addresses.
這里有個技巧,PCRE regexp將記住圓括號中的部分,即$1變量,也就是說,所有的alias名將被寫入所有的目的地址。
This is great if you have few thousand users. There's no need to update this table, nor running postmap after every update.
如果沒有幾千個用戶,這樣就足夠了,沒必要更新這個表,也不用每次更新后運行postmap。
I guess there's no need to mention there can be more than two destinations - backend servers. Neat, huh?
我想沒有必要再說兩個以上后端服務器的情況了。
About that destination addressess... For example john.doe@backend1.x-si.org. This is address to which mail will be forwarded and exactly this is the value of result_attribute in main.cf on backend1 machine (defined as maildrop1). This is a value which postfix expects to get from virtual_maps.
關于目的地址,例如john.doe@backend1.x-si.org,這是將被轉發的地址也是后端1服務器(maildrop1)main.cf中定義的result_attribute,這是postfix希望從virtual_maps獲取的值。
Our servers are not 100% reliable, so we need to hold mail in queue until backend gets up again. We'll use Postifx's Fast ETRN Service.
我們的服務器不是100%可靠,所以需要保存郵件隊列,直到后端服務器重啟,可以使用postfix的Fast ETRN Service。
2.2 Forwarder setup (inbound & outbound traffic)(轉發器設置,接收/發送)
Main configuration is the same as for the inbound traffic. Difference is in using LDAP lookups instead of hashed tables.
主要的設置與接收設置一樣,不同點在于使用LDAP查詢,而不是hashed表。
Needed main.cf changes: 需要更新main.cf的部分:
#---- start here ----
# from
virtual_maps = pcre:/etc/postfix/virtusertable
# to
virtual_maps = ldap:ldapalias
# plus LDAP lookups:
ldapalias_server_host = ldap.x-si.org
ldapalias_server_port = 389
ldapalias_search_base = dc=x-si,dc=org
ldapalias_timeout = 30
ldapalias_query_filter = (mail=%s)
ldapalias_domain = hash:/usr/local/etc/postfix/ldapvirtualdomains
ldapalias_result_attribute = forward,maildrop1,maildrop2
#---- end here -----
File "/usr/local/etc/postfix/ldapvirtualdomains" contain domains, for which we're accepting mail for:
#---- start here -----
x-si.org OK
#---- end here ------
Note: run postmap /usr/local/etc/postfix/ldapvirtualdomains after altering the file.
注意:更改后需要運行postmap /usr/local/etc/postfix/ldapvirtualdomains。
Here we get few options, which we haven't had before (with inbound only setup). Mail sent to any of 'mail =' attributes, will result in mail being delivered to all 'result_attribute =' values; here we got forward, maildrop1 and maildrop2.
我們這里有些以前只做接收時沒有用到的選項,將郵件發送到所有mail=的值,將發送郵件到所有result_attribute =的值,包括轉發、maildrop1和maildrop2。
If forward field is empty (ie. contains a single space character) and is listed as result_attribute, mail will be delivered only to maildrop1 and maildrop2 values.
如果轉發域空(如包含一個空字符),并且列入result_attribute,郵件將只發往maildrop1和maildrop2。
However, if forward is defined, mail will be forwarded to that address. Next, with forward value defined, empty (not defined) maildrop1 and maildrop2 attributes will result as mail being forwarded and not stored on local system. With defined maildrop1, maildrop2 and forward, mail will get forwarded and stored on local system.
如果定義了轉發,郵件將被發往定義的地址,根據轉發值的定義,maildrop1和maildrop2屬性值為空(無定義)表示郵件被轉發而不被本地存儲。當定義了maildrop1、maildrop2和轉發時,郵件將被轉發并存儲在本地。
I'm not really sure 'result_attribute = forward,maildrop1,maildrop2' is the right way to specify multiple return attributes. Perhaps multiple LDAP 'result_attribute =' with only one value each would be "more" right than this. Anyway, please sent comments.
我不確定'result_attribute = forward,maildrop1,maildrop2'是指定多個返回值的正確方法,或許多個LDAP的只有一個值的'result_attribute ='更好,請大家提意見。
2.3 Fast ETRN service
In main.cf add these: 在main.cf中添加:
#---- start here ----
fast_flush_domains = $relay_domains
transport_maps = hash:/etc/postfix/transport
#---- end here ----
Only domains, we relay for will be able to use ETRN service. In transport_maps we say:
只有轉發域能夠用ETRN service,在transport_maps中需要增加:
#---- start here ----
backend1.x-si.org smtp:[IP_of_backend1_machine]
backend2.x-si.org smtp:[IP_of_backend2_machine]
#---- end here ----
NOTE: run postmap on transport file.
注意:傳送文件時運行postmap。
This way, forwarder will deliver all mail for backend1 to it's IP, without doing a DNS query. All forwarders should have all backends in transport_maps. In case of backend server failure, mail on all forwarders will stay queued util ETRN command is issued.
這樣,轉發器將發送所有到后端1的郵件至其IP,不需要DNS查詢。所有轉發器在transport_maps都有所有的后端服務器表。如果后端服務器失效,所有轉發器上的郵件將繼續排隊直到ETRN命令發出。
2.4 Backend1 setup(后端1設置)
Add user and group "vmail" to your system. Here, vmail user has UID and GID 5000. This user vill be owner of directory structure for all LDAP mail users.
在系統中添加用戶和組"vmail",vmail用戶的UID和GID為5000。該用戶是所有LDAP郵件用戶的目錄結構的擁有者
Edit main.cf, so it accepts mail for your domain (x-si.org in this case). Here's relevant part of main.cf that deals with ldap:
編輯main.cf,接收域中的郵件,下面是main.cf中與ldap相關的部分:
#---- start here ----
transport_maps = hash:/etc/postfix/transport
local_transport = virtual
virtual_maps = ldap:ldapalias
ldapalias_server_host = ldap.x-si.org
ldapalias_server_port = 389
ldapalias_search_base = dc=x-si,dc=org
ldapalias_timeout = 30
ldapalias_query_filter = (mail=%s)
ldapalias_domain = hash:/etc/postfix/ldapvirtualdomains
ldapalias_result_attribute = maildrop1
virtual_mailbox_base = /virtmail
virtual_mailbox_maps = ldap:ldapvirtual
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
ldapvirtual_server_host = ldap.x-si.org
ldapvirtual_server_port = 389
ldapvirtual_search_base = dc=x-si,dc=org
ldapvirtual_timeout = 30
ldapvirtual_query_filter = (mail=%s)
ldapvirtual_domain = hash:/etc/postfix/ldapvirtualdomains
ldapvirtual_result_attribute = homedir
#---- end here ----
/etc/postfix/transport contains:
#---- start here ----
x-si.org virtual
backend1.x-si.org virtual
#---- end here ----
/etc/postfix/ldapvirtualdomains:
#---- start here ----
x-si.org virtual
backend1.x-si.org virtual
#---- end here ----
Note: Don't forget to run postmap on transport and ldapvirtualdomains.
注意,不要忘記在傳送和ldapvirtualdomains運行postmap。
ldapavirtual parameter will search LDAP server for email addres (mail=%s), when found, it returns homedir (result_attribute). This way postfix knows where to deploy email message.
Ldapavirtual參數將搜索LDAP服務器查找郵件地址(mail=%s),找到后,返回homedir (result_attribute),這樣postfix就會知道向哪里發送信息。
If you look closely at homedir value in ldif file, you'll notice there's no leading slash (i.e. /) in the path. Also, the path ends with a slash.
如果仔細考察ldif文件的homedir值,就會發現路徑前沒有/斜線,路徑結尾有/。
Leading slash is ommited because postfix's virtual_mailbox_base is prepended to path returned from LDAP query. Tailing slash means, postfix will store email messagess in Maildir format (every message in separate file). While this may lead to inode consumption, it's far easier to administrate and faster to load mail for clients.
路徑前的斜線省略是因為postfix的virtual_mailbox_base是從LDAP查詢返回的偽裝路徑,結尾的斜線表示postfix將用Maildir格式保存郵件(每個郵件是獨立文件)。這種方式雖然消耗資源,但是易于管理,客戶端可以快速加載郵件。
To do ETRN with forwarders, I use small perl script. This should be run right after machine comes up and postfix starts. You can get it here. Be sure you user right FQDN's

.
在轉發器運行ETRN,我用了一個小perl腳本,在機器啟動和postfix啟動時運行,可以從這里
下載。
2.3 Backend2 setup(后端2設置)
Use same configuration as for backend1. In main.cf only change:
與后端1設置相同,更改main.cf中:
#---- start here ----
ldapalias_result_attribute = maildrop2
#---- end here ----
/etc/postfix/transport should also change to:
#---- start here ----
x-si.org virtual
backend2.x-si.org virtual
#---- end here ----
/etc/postfix/ldapvirtualdomains:
#---- start here ----
x-si.org virtual
backend2.x-si.org virtual
#---- end here ----
Note: Don't forget to run postmap on both files.
注意:不要忘記運行postmap。
3. Conclusion(結論)
Ok, this is it. Restart (or reload) postfix and telnet to forwarders address port 25. Send mail to user@x-si.org and watch the maillogs on both backends.
好了,重新啟動postfix,telnet到轉發器端口25,發送郵件給user@x-si.org,觀察所有后端服務器的郵件日志文件。
Mail should arrive and all needed directories should be created.
郵件到達,同時創建所有需要的目錄。
You can setup M backends this way. Because of running freevrrpd daemon, you can retrieve or add as many boxes as you like, service will still be up & running.
按照這個方法可以創建M個后端,運行freevrrpd daemon,可以找回或增加任意多的系統。
The only problem here is mail header. It shows, mail
was delivered to backend1 or backend2, not to x-si.org. This can be altered with canonical_maps in postfix configuration, but to tell the truth, I didn't tried this yet.
唯一的問題是郵件頭,將被顯示是發送到后端1或后端2,而不是x-si.org。這個可以用postfix設置中的canonical_maps進行調整,但是我還沒有試過。
In case one backend server crashes, freevrrpd daemon will take care of IP's and Fast ETRN Service will take care of queued mail delivery.
如果一個后端服務器崩潰,freevrrpd daemon將控制IP,而Fast ETRN Service控制郵件隊列。
3.1 Mail hosting(郵件服務托管)
Using setup as described in 2.2 section, ISP can easy setup mail hosting.
利用2.2的設置,ISP可以建立郵件服務托管。
For specific domain, let say lamerz.si, one should add this domain into '/usr/local/etc/postfix/ldapvirtualdomains' and add another 'mail =' attribute for that domain (ie. lart@lamerz.si) on forwarders only. We don't need to change anything on backends for mail hosting.
對于某個域,比如lamerz.si,在'/usr/local/etc/postfix/ldapvirtualdomains'加入該域,在轉發器增加一個'mail ='(比如lart@lamerz.si),不需要在后端進行任何修改。
Again, all mail destined to lart@lamerz.si will go to all attributes of 'result_attribute =' filed.
所有發往lart@lamerz.si的郵件將送到'result_attribute ='指定的值。
peijun.jiang 回復于:2003-05-15 09:22:40
|
這是讓一位同事幫助翻譯的,大家可以參考一下,希望對大家有幫助!
|
unix菜鳥 回復于:2003-05-15 21:37:59
|
不錯,可惜我沒有那么多Server試。
|
startdd 回復于:2003-05-15 21:57:17
|
感覺很難配置!而且調試時間肯定很長,而且會遇到這樣那樣的問題!希望給份“中文”的安裝指南!
|
hzqbbc 回復于:2003-05-15 23:17:08
|
[quote:6c2f5c49e8="peijun.jiang"]ckend2_machine]
#---- end here ----
NOTE: run postmap on transport file.
注意:傳送文件時運行postmap。
This way, forwarder will deliver all mail for backend1 to it's IP, without doing a DNS q..........[/quote:6c2f5c49e8]
it's old
很早就看過這個了。不過做法是不錯的??上Хg的就。。努力努力~
我一直還是用mx的方法做backup server的。
|
peijun.jiang 回復于:2003-05-16 09:15:39
|
[quote:52ade92811="hzqbbc"]
it's old
很早就看過這個了。不過做法是不錯的??上Хg的就。。努力努力~
我一直還是用mx的方法做backup server的。 [/quote:52ade92811]
hzqbbc老大對postfix是最熟悉的,有時間你還是給我們教教postfix系統
和郵件服務器的HA系統!
|
原文轉自:http://www.kjueaiud.com
老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月
|