前言
本文章是一篇类似教程的东西,不过内容多半属于流水账,它记述了作者多次安装postfix+ldap的过程。也许本文会不断更新,也许不会,看作者有没有空了。
第一篇
第一篇讲系统和ldap的安装。我们的系统选用的是debian Linux(woody)或者freebsd 4.9,其他的系统没有测试过,solaris上可以安装,就是有很多注意事项,这个相关的软件里面都有,读者可以自行参考一下。有兴趣的同仁们也可以翻译一下,以方便不熟悉英文的同学。
系统的安装
系统的安装外面的文章很多,也不是这里的重点,就针对我们采用的debian和freebsd系统稍微讲一下。
分区
某种意义上说,分区的好坏关系到系统跑得好坏。这方面读者可以参考一下相关的文章,我们建议分区这么分比较合适:
| 代码: |
/boot 256M
/ 2G
/usr 2G
/usr/local 2G
/var 4G
swap 内存的2倍
/home 余下的硬盘空间。
|
具体的可以根据实际情况来调整。上面的说的分区方案也并不是说就是最好的。只是给刚接触unix的同学参考用。
一些必备的库
安装/运行邮件系统,有一些库是必须安装的。比如:berkeley-db,zlib等。我不清楚redhat的默认安装是不是安装了这些,不过debian是没有,所以就必须手工安装。幸好debian下手工安装并不是难事:
| 代码: |
# apt-get install libdb3 libdb3++-dev libdb3-dev libdb3++ libdb3-util
# apt-get install zlib1g zlib1g-dev zlibc
|
系统的安装
openldap是一个数据库,只不过不是关系型的。可以这么理解,一个数据库就是一张表。
源代码下载
openldap可以从http://www.openldap.org/取得:
| 代码: |
# wget ftp://ftp.openldap.org/pub/OpenLDAP/openldap-release/openldap-2.1.29.tgz
|
解压缩/配置/编译
openldap可以采用多种数据库作为后台,包括berkeley-db, gdbm, mysql, oracle等。我们这里采用的是gdbm,因为安装很方便。
| 代码: |
# tar xzvf openldap-2.1.29.tgz
# cd openldap-2.1.29
# ./configure --prefix=/usr/local/openldap --enable-bdb=no --enable-ldbm=yes
# make depend
# make
# make install
|
到这里,openldap就算装完了。还算方便吧。
ldap的配置
我们这么来安排我们的ldap目录,以便让他保存邮件系统的一些用户信息。(我们的域名是cz8.net)
邮件数据保存在ou=mail,dc=cz8,dc=net这个dn的树下面,ou=admin,dc=cz8,dc=net这个目录下面,存放得是邮件管理员的帐号信息,它对ou=mail,dc=cz8,dc=net这个dn及他的子树有些得权限。所有这些数据,都保存在硬盘的/home/ldap目录下面。这样方便备份。于是,我们的openldap配置文件(slapd.conf),看起来就像这个样子:
| 代码: |
# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8 2003/05/24 23:19:14 ku
rt Exp $
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /usr/local/openldap/etc/openldap/schema/core.schema
include /usr/local/openldap/etc/openldap/schema/kunmail.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
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!
#access to * by dn="ou=admin,dc=cz8,dc=net" read
access to dn.base="" by * read
access to dn.base="cn=Subschema" by * read
access to dn.subtree="ou=admin,dc=cz8,dc=net"
attr=userPassword
by * auth
access to dn.subtree="ou=mail,dc=cz8,dc=net"
by dn="cn=kunmail,ou=admin,dc=cz8,dc=net" write
by * none
#######################################################################
# ldbm database definitions
#######################################################################
database ldbm
suffix "dc=cz8,dc=net"
rootdn "cn=Manager,dc=cz8,dc=net"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw 54321
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /home/ldap
# Indices to maintain
index objectClass eq
index userName eq
index userClearpw eq
|
上面还有一些东西,后面会讲到。
定制schema
schema文件相当于数据库的字段定义,上面的配置文件中的kunmail.schema就是我们自己定义的schema文件。他的内容基本如下:
| 代码: |
#
# kunmail-ldap v3 directory schema
#
# written by hefish@cz8.net
#
# Attribute Type Definitions
attributetype ( 1.3.6.1.4.1.7914.1.2.1.1 NAME 'userNo'
DESC 'id of the user on the mailsystem'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{32}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.2 NAME 'userName'
DESC 'name of the user on the mailsystem'
EQUALITY caseIgnoreIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{64}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.3 NAME 'userUid'
DESC 'UID of the user on the mailsystem'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{32}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.4 NAME 'userGid'
DESC 'GID of the user on the mailsystem'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{32}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.5 NAME 'userHome'
DESC 'home of user in mail system'
EQUALITY caseExactMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.6 NAME 'userMaildir'
DESC 'maildir of user'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.7 NAME 'userQuota'
DESC 'The amount of space the user can use until all further messages get bounc
ed.'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.44{32}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.8 NAME 'userClearpw'
DESC 'clear password of the user on the mailsystem'
EQUALITY caseExactIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.9 NAME 'userFullname'
DESC 'full name of user'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.10 NAME 'userActive'
DESC 'The status of a user account'
ORDERING integerOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27{16}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.11 NAME 'userMailReplyText'
DESC 'A reply text for every incoming message'
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.44{4096}
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.12 NAME 'userRegisterDate'
DESC 'timestamp of user registration'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.13 NAME 'userExpireDate'
DESC 'timestamp of user mailbox expiration'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE )
# Object Class Definitions
objectclass ( 1.3.6.1.4.1.7914.1.2.2.1 NAME 'kunmailUser'
DESC 'KunMail-LDAP User' SUP top STRUCTURAL
MUST ( userNo $ userName $ cn $ userUid $ userGid )
MAY ( userMaildir $ userHome $ userClearpw $ userQuota $ userFullname $ userMailReplyText $ userActive $ userRegisterDate $ userExpireDate ) )
|
如果还需要什么其他字段的话,可以自己再添加。下面说说这些字段的含义。
| 代码: |
userNo - 用户号 (整数)
userName - 邮件系统用户名 (是完整的用户名,包括@后面的部分)
userUid, userGid - 用户的uid, gid。
userHome - 用户的home目录
userMaildir - 用户的maildir (一般为 userHome + “/Maildir/”)
userQuota - 用户邮箱大小 (单位: byte)
userClearpw - 用户密码 (明码)
userFullname - 用户全称
userActive - 用户帐号状态 (停用,仅允许web收发,允许pop等,具体根据应用来制定)(整数)
userMailReplyText - 用户自动回复的内容 (这个系统中间没用到)
userRegisterDate - 注册日期
userExpireDate - 到期日期
|
启动slapd,创建数据库,导入基本数据
启动数据库还是比较简单的:
| 代码: |
# cd /usr/local/openldap/libexec
# ./slapd
|
为了让我们能把数据存放到ldap目录里,我们必须按照slapd.conf里面的设置来创建这个ldap数据库(也可以说是创建ldap目录吧),为此我们要准备一下LDIF文件。我们的ldif文件如下:
| 代码: |
dn: dc=cz8,dc=net
dc: cz8
objectClass: dcObject
objectClass: organization
description: kunmail system made by YuCa Studio.
o: YuCa Studio.
dn: ou=admin, dc=cz8,dc=net
ou: admin
objectClass: top
objectClass: organizationalUnit
dn: ou=kunmail, dc=cz8,dc=net
ou: kunmail
objectClass: top
objectClass: organizationalUnit
|
把它保存成cz8.ldif
然后我们去http://www.iit.edu/~gawojar/ldap/ 下在一个LDAP Browser/Editor来用(简称lbe)。我们把rootdn和密码填进去之后,一点Connect,就连接上这个ldap目录了。
这时候我们还看不到任何信息,因为我们还没把目录创建起来。为了创建这个ldap目录,我们可以使用lbe里面的import功能,把我们刚才的cz8.ldif文件导入到ldap里面,这样,ldap目录就创建好了。 更多的lbe的操作,可以另外找资料看。这里就说这么些了。
第一篇差不多就说到这里吧。关于ldap的,大致就说这么多了。 |