為什么使用FREEBSD?因為它有PORTS,有什么好處,就是你安裝軟件時就不用再考慮軟件的依賴關系,它自己會添加的。這一點就足以位列所有的UNIX,包括類UNIX之首!!!!!
本文力求使用最簡單的方法,構建出高效的大容量的郵件系統。本次實踐過程中得到了hefish的鼓勵和幫助,基本過程是hefish的KUNMAIL系統地freebsd上的一次試驗。由于新版openldap對某些字段定義的變化,kunmail.schema需要作一些變動,liut對此作些改動mail.schema,同時也使用了陳景峰的postfix.schema。其實直接使用qmail.schema就挺好。
本文旨在幫助初學者,通過基本的架設過程,理解mail系統的基本原理,所以構建的系統也是最基本的,病毒防護和垃圾過濾網上的參照文件很多,就不寫了。
本文假設你對類UNIX有一定的了解,最好是架設或使用過郵件系統。本文的重點在openldap,如果你想使用mysql,請參照我的另一篇文章。
本次試驗在freebsd4.10下和freebsd5.4下成功通過。SASL2認證采用courier的AUTHDAEMOND認證,認證方式簡單高效,只要courier認證通過,postfix認證肯定能通過。與postfix+mysql相比,只是數據庫更改了,便于使用現有的經驗來架設新的系統。
暫時只使用PLAIN LOGIN,大多數電信都是這兩種,對于openldap來說,這種認證方式并不比其自已本身的認證更好(openldap原文),但與sasl2結合,可以有更高的、更安全的認證方式。
參考文章:
1、http://kunmail.cz8.net/
2、http://www.huihoo.com/internet/postfix/pis/book1.html
第一章 系統準備
如果你能夠安裝基本系統,可以跳過本章。本文未特別申明的,一律是以root身份操作。
freebsd5.4安裝
選擇最小化安裝,配置好網絡,添加perl5.8軟件包。
在本例中,機器名:mail.chinake.com
域名:chinake.com
默認網關:192.168.0.1
IP地址:192.168.0.66
1、cvsup安裝
由于5.4將不少軟件包放在第二張盤上,所以只有通過網絡安裝了。
設計pkg_add環境變量,使它使用國內的服務器,freebsd默認的shell是csh。
bash shell
#export PACKAGEROOT="ftp://ftp.freebsdchina.org"
csh shell
#setenv PACKAGEROOT "ftp://ftp.freebsdchina.org"
#pkg_add -r cvsup-without-gui
2、設計/etc/make.conf
添加
MASTER_SITE_OVERRIDE=ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}
3、更新ports樹
#/usr/local/bin/cvsup -g -L 2 -h ftp.freebsdchina.org /usr/share/examples/cvsup/ports-supfile ;
第二章 郵件系統軟件的安裝
1、安裝openssl
#cd /usr/ports/security/openssl; make install clean
2 安裝apache
#cd /usr/ports/www/apache13-modssl;make install clean
支持https連接,web服務路徑為:/usr/local/www/data/。也可以選擇apache2。
#ee /etc/rc.conf;加入:apache_enable="YES"
3 安裝php4
#cd /usr/ports/lang/php4;make install clean
#cp /usr/local/etc/php.ini.dist /usr/local/etc/php.ini
#ee /usr/local/etc/apache/httpd.conf
在最后加入:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4 安裝expect
#cd /usr/ports/lang/expect
#make install clean
5 安裝SASL2
cd /usr/ports/security/cyrus-sasl2;make install WITH_AUTHDAEMON=yes clean;
或者使用:make -DWITH_AUTHDAEMOND install clean
#ln -s /usr/local/lib/sasl2 /usr/lib/sasl2;
下面的這個smtpd.conf就是postfix調用的,很簡單吧。
#ee /usr/local/lib/sasl2/smtpd.conf ;
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket
6 安裝courier-imap
#cd /usr/ports/mail/courier-imap
#make install clean
選擇添加:[auth_ldap],[openssl],[gdbm]如果沒有做,可以make config,進行重新選擇。
然后編輯/etc/rc.conf;增加courier_authdaemond_enable="YES"自啟動,并啟動:
#/usr/local/etc/rc.d/courier_authdaemond.sh start。
此時會在/var/run/authdaemond/下產生socket。
chmod +x /var/run/authdaemond;
給sasl可執行權限。
我們這里是使用authdaemond認證,不使用pam認證,所以以下的不需要做:
In case you use authpam, you should put the following lines
in your /etc/pam.d/imap
auth required pam_unix.so try_first_pass
account required pam_unix.so try_first_pass
session required pam_permit.so
至此,認證部分基本完成。
7、openldap安裝
#cd /usr/ports/net/openldap22-server;
#make WITH_SASL=yes install clean;
#ee /etc/rc.conf;
添加:
slapd_enable="YES"
slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://0.0.0.0/"'
slapd_sockets="/var/run/openldap/ldapi"
我們來啟動它:
#/usr/local/etc/rc.d/slapd.sh start
8、 安裝POSTFIX
3.3.1 cd /usr/ports/mail/postfix
安裝時選中[sasl2]+[tls]+[ldap]+[vda]+[test]。
make install clean
在安裝快結束時會提示兩個問題,分別是加入用戶組和修改mailer.conf。全部回答為y。
添加postfix別名:
#cd /etc;
#echo ‘postfix: root’ >> /etc/aliases
產生別名數據庫,每次改動都必須要做一次:
#/usr/local/bin/newaliases
如果提示opiekeys錯誤
#chown postfix:postfix /etc/opiekeys
替換并停止sendmail
#ee /etc/rc.conf;
修改sendmail_enable=’NONE’
建立啟動鏈接:
#cd /usr/local/etc/rc.d/;
#ln –s /usr/local/sbin/postfix postfix.sh
創建/etc/periodic.conf
#ee /etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
9、phpldapadmin安裝
強烈建議安裝此程序,這是一個web界面的openldap的管理程序,對于理解和運用openldap大有幫助,我們可以把它看作是mysql的phpmyadmin一樣。
#cd /usr/ports/net/phpldapadmin/
#ee Makefile,修改 www/為www/data/
#make install clean;
phpldapadmin的配置,與phpmyadmin基本上一樣,無非就是用戶名、密碼等。
#ee /usr/local/www/data/phpldapadmin/config.php;
$blowfish_secret = 'mytestopenldap'; //隨機加密碼字符串,默認是空,使用cooki認證時必須要填,內容隨便。
$servers[$i]['name'] = 'My LDAP Server'; //名稱,隨便。
$servers[$i]['host'] = '192.168.0.66'; //主機IP
$servers[$i]['base'] = 'dc=chinake,dc=com'; //與slapd.conf保持一致。下面有講到。
$servers[$i]['port'] = 389; //默認端口號。
$servers[$i]['auth_type'] = 'cookie'; //進入模式,開始的時候可以使用config(默認值)
$servers[$i]['login_dn'] = 'cn=chaohu,dc=chinake,dc=com' //與slapd.conf的rootdn保持一致。
$servers[$i]['login_pass'] = 'chaohu'; //rootpw的密碼。使用cookie時,不需要。
$language = 'zh-tw'; //語言,默認為 auto亂碼,設為zh-cn也亂碼,所以使用繁體的或en。
第三章 openldap的配置
1、關于schema
一個schema就是一張字段和字段關系的定義表(與mysql的數據庫相比)。postfix和courier需要查找的基本字段是用戶名(用戶郵件地址)、密碼(postfix不需要)、用戶郵件的存儲目錄。
①kunmail.schema基本字段:
kunmailuser: userName - 郵件系統用戶名 (是完整的用戶名,包括@后面的部分)
userHome - 用戶的home目錄
userMaildir - 用戶的maildir (一般為 userHome + “/Maildir/”)
userClearpw - 用戶密碼 (明碼)
②postfix.schema基本字段:
postfixAccount:mail – 用戶郵件地址
mailbox - 用戶的maildir
clearPassword - 用戶密碼
homeDirectory -用戶的home目錄
③mail.schema基本字段:
mailUser: mail – 用戶郵件地址
userPassword - 用戶密碼
homeDirectory -用戶的home目錄
mailMessageStore - 用戶的maildir
④qmail.schema基本字段:
qmailUser: mail – 用戶郵件地址
mailMessageStore - 用戶的maildir
homeDirectory -用戶的home目錄
userPassword - 用戶密碼
注意:用戶的home目錄+用戶的maildir要構成一個郵件用戶完整的絕對路徑。本文使用mail.schema進行講解。(幾個schema文件附后)
2、關于slapd.conf
這是openldap主要配置文件,這個文件可以分成三個部分來理解:
第一部分:載入schema文件,主要是裝載所有字段定義和屬性。其依賴關系可以這樣理解:如某個schema文件中未定義mailhost這個字段,而其屬性值里引用了這個字段,則定義了mailhost這個字段的schema必須先載入。我們先將mail.schema放到/usr/local/etc/openldap/schema/下,必須要先放。
根據其依賴關系我們加入了幾個schema文件:
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/nis.schema
include /usr/local/etc/openldap/schema/misc.schema
include /usr/local/etc/openldap/schema/mail.schema
對于openldap的配置文件,行尾一定不能有空格。
第二部分:控制權限。其默認的控制權限是rootdn任何時候都擁有寫入權,這一部分我們可以不加定義,直接使用rootdn,但這樣不太安全,所以我們添加一個用戶或組來擁有對郵箱用戶組寫入權,郵箱用戶自己可以讀寫。
access to dn.base="" by * read //只讀
access to dn.base="cn=Subschema" by * read //只讀
access to dn.subtree="ou=admin,dc=chinake,dc=com" attr=userPassword
by * auth //添加管理組ou=admin,對自己可以認證。
access to dn.subtree="ou=mail,dc=chinake,dc=com" attr=userPassword
by * auth //添加郵箱組ou=mail,對自己可以認證。
access to dn.subtree="ou=mail,dc=chinake,dc=com"
by dn="cn=kunmail,ou=admin,dc=chinake,dc=com" write
by * none //添加管理員kumail,對ou=mail擁有寫入權,對其它無權。
第三部分:根及根用戶
suffix "dc=chinake,dc=com" //默認前綴
rootdn "cn=chaohu,dc=chinake,dc=com" //根用戶,名稱隨便。
rootpw chaohu //根用戶密碼。
這種結構與我的路徑很相似,只是倒過來的,可以這樣對比:
/com/chinake/chaohu,這樣就容易理解多了。
那么我們的slapd.conf看起來就象這樣。
#ee /usr/local/etc/openldap/slapd.conf
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/nis.schema
include /usr/local/etc/openldap/schema/misc.schema
include /usr/local/etc/openldap/schema/mail.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 /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/libexec/openldap
# moduleload back_bdb
# moduleload back_ldap
# moduleload back_ldbm
# moduleload back_passwd
# moduleload back_shell
# 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
access to dn.base="" by * read
access to dn.base="cn=Subschema" by * read
access to dn.subtree="ou=admin,dc=chinake,dc=com" attr=userPassword
by * auth
access to dn.subtree="ou=mail,dc=chinake,dc=com" attr=userPassword
by * auth
access to dn.subtree="ou=mail,dc=chinake,dc=com"
by dn="cn=kunmail,ou=admin,dc=chinake,dc=com" write
by * none
#
# rootdn can always read and write EVERYTHING!
#######################################################################
# BDB database definitions
#######################################################################
database bdb
suffix "dc=chinake,dc=com"
rootdn "cn=chaohu,dc=chinake,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
rootdn "cn=chaohu,dc=chinake,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 chaohu
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /var/db/openldap-data
# Indices to maintain
index objectClass eq
3、配置ldap.conf,也可以不配置。
# LDAP Defaults
#
# See ldap.conf(5) for details
# This file should be world readable but not world writable.
BASE dc=chinake, dc=com
HOST localhost
#URI ldap://ldap.example.com ldap://ldap-master.example.com:666
#SIZELIMIT 12
#TIMELIMIT 15
#DEREF never
以上兩個配置文件中間和前面空的部分都是TAB鍵打出來的,不是空格。
重新啟動slapd
/usr/local/etc/rc.d/slapd.sh stop;
/usr/local/etc/rc.d/slapd.sh start;
4、建立用戶數據
建立導入文件,多個記錄間使用空行分隔,我在使用過程中發現根結點必須手動導入,其它記錄可以通過phpldapadmin導入,也可以直接建立。
第一步是建立DN:
文字不多,我們手動建立就可以了
ldapadd -x -D 'cn=chaohu,dc=chinake,dc=com' -W //輸入密碼,然后將下面的內容輸入,完成后按Ctrl+d 存盤。
dn: dc=chinake,dc=com
objectClass: dcObject
objectClass: organization
dc: chinake
Corporation
description: d Corporation
第二步建立組和用戶:
將下面的存為postfix.ldif,然后進入http://192.168.0.66/phpldapadmin/,使用其中的導入功能就可以了。
也可以手動導入:
# ldapadd -x -D "cn=chaohu,dc=chinake,dc=com" -W -f postfix.ldif
#管理組
#
主站蜘蛛池模板:
一本色道久久综合亚洲精品图片
|
一区在线免费视频
|
久久国产精品二国产精品
|
4p嗯啊巨肉寝室调教男男视频
|
久久狂草
|
欧美亚洲国产一区二区三区
|
国产亚洲精品一区二区三区
|
深夜网站在线观看
|
久久人人爽人人爽人人片av高清
|
毛片电影网址
|
男女羞羞视频在线观看免费
|
久久久国产电影
|
久久一级
|
日韩黄色片免费看
|
午夜视频在线看
|
三人弄娇妻高潮3p视频
|
成人免费观看av
|
黄色成人小视频
|
欧美一区二区精品夜夜嗨
|
在线无码|
国产日韩欧美
|
噜噜噜躁狠狠躁狠狠精品视频
|
午夜视频免费播放
|
国人精品视频在线观看
|
九色91视频
|
欧美18videos性处按摩
|
黄色影院一级片
|
黄色片网站免费在线观看
|
国产成人精品网站
|
亚州成人在线观看
|
最新影院
|
久久国产精品网
|
成人片免费视频
|
在线播放免费视频
|
麻豆国产网站
|
欧美一区二区黄色
|
91精品国啪老师啪
|
国产亚洲精品久久久久久久久
|
久久久久免费精品国产小说色大师
|
国产一区二区三区精品在线观看
|
99国产精品白浆在线观看免费
|