RHEL5 OpenLDAP Server端配置

42 views
Skip to first unread message

frozen

unread,
Jan 19, 2009, 1:53:46 AM1/19/09
to Linux-鸟巢
搞了一上午,终于可以用了。网上找了很多资料都是很不详细。。。最后终于找到一篇。。。现摘录如下:

1. 安装所需rpm包 ,步骤省略 。。。
所需rpm包主要为
* openldap-2.2.13-2:包含 OpenLDAP 配置文件、库和文档
* openldap-servers-2.2.13-2:包含 slapd 和 slurpd 服务器、迁移脚本和相关文件
* openldap-clients-2.2.13-2:包含客户机程序,用来访问和修改 OpenLDAP 目录

2. 配置slapd.conf文件,过程不写了,只是列出几个需要一般简单修改的参数:
suffix "dc=xxx,dc=xxx"
rootdn "cn=xxx,dc=xxx,dc=xxx"
rootpw xxx
更详细信息查阅:http://www.openldap.org/doc/admin24/slapdconfig.html

然后启动ldap进程。

3. 我个人认为最要紧的地方:把本地的用户和组迁移到LDAP目录中!
迁移工具所在目录:/usr/share/openldap/migration/
仅需要修改migrate_common.ph文件中的 $DEFAULT_BASE = "dc=xxx,dc=xxx" 和
$DEFAULT_MAIL_DOMAIN = "xxx.xxx"
然后参考下面步骤,(摘录自网络文章)

运行 migrate_base.pl

# migrate_base.pl > base.ldif

编辑 base.ldif,删除除下面之外的所有条目:

base.ldif 条目

# cat base.ldif
dn: dc=ibm,dc=com
dc: ibm
objectClass: top
objectClass: domain
dn: ou=People,dc=xxx,dc=xxx
ou: People
objectClass: top
objectClass: organizationalUnit
dn: ou=Group,dc=xxx,dc=xxx
ou: Group
objectClass: top
objectClass: organizationalUnit

在 LDAP 服务器上,使用 OpenLDAP 客户机工具 ldapadd 将以下条目插入到数据库中。简单身份验证必须要使用 -
x 选项指定。在 slapd.conf 中定义的 rootdn 身份验证识别名是 “cn=Manager,dc=xxx,dc=xxx”。对于

单身份验证来说,必须使用密码。选项 -W 强制提示输入密码。这个密码就是在 slapd.conf 文件中指定的 rootpw 参数的值。包含

些条目的 LDIF 文件是使用 -f 选项指定的:

使用 ldapadd 插入条目

# ldapadd -x -D "cn=Manager,dc=xxx,dc=xxx" -W -f base.ldif

接下来,从 /etc/group 中迁移 ldapuser 组:

迁移 ldapuser 组

# grep ldapuser /etc/group > group.in
# ./migrate_group.pl group.in > group.ldif
# cat group.ldif
dn: cn=ldapuser,ou=Group,dc=xxx,dc=xxx
objectClass: posixGroup
objectClass: top
cn: ldapuser
userPassword: {crypt}x
gidNumber: 500
# ldapadd -x -D "cn=Manager,dc=xxx,dc=xxx" -W -f group.ldif

最后,从 /etc/passwd 和 /etc/shadow 中迁移 ldapuser 的信息:

迁移 ldapuser 信息

# grep ldapuser /etc/passwd > passwd.in
# ./migrate_passwd.pl passwd.in > passwd.ldif
# cat passwd.ldif
dn: uid=ldapuser,ou=People,dc=xxx,dc=xxx
uid: ldapuser
cn: ldapuser
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt$1$TeOlOcMc$cpQaa0WpLSFRC1HIHW5bt1
shadowLastChange: 13048
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 500
gidNumber: 500
homeDirectory: /home/ldapuser
gecos: ldapuser
# ldapadd -x -D "cn=Manager,dc=xxx,dc=xxx" -W -f passwd.ldif

现在检查已经添加到数据库中的信息。给出了全部输出结果:

以 LDIF 格式填充的 OpenLDAP 数据库

# ldapsearch -x
# extended LDIF
#
# LDAPv3
# base <> with scope sub
# filter: (objectclass=*)
# requesting: ALL
#
# xxx.xxx
dn: dc=xxx,dc=xxx
dc: xxx
objectClass: top
objectClass: domain
# People, xxx.xxx
dn: ou=People,dc=xxx,dc=xxx
ou: People
objectClass: top
objectClass: organizationalUnit
# Group, xxx.xxx
dn: ou=Group,dc=xxx,dc=xxx
ou: Group
objectClass: top
objectClass: organizationalUnit
# ldapuser, Group, xxx.xxx
dn: cn=ldapuser,ou=Group,dc=xxx,dc=xxx
objectClass: posixGroup
objectClass: top
cn: ldapuser
gidNumber: 500
# ldapuser, People, xxx.xxx
dn: uid=ldapuser,ou=People,dc=xxx,dc=xxx
uid: ldapuser
cn: ldapuser
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 500
gidNumber: 500
homeDirectory: /home/ldapuser
gecos: test2
# search result
search: 2
result: 0 Success
# numResponses: 6
# numEntries: 5

4. 配置客户端,很简单了,直接setup命令。

参考的文档: http://linux.chinaitlab.com/administer/519684.html
希望原作者不要追究版权哦~~~

Message has been deleted

jerrymy

unread,
Jan 21, 2009, 3:56:57 AM1/21/09
to Linux-鸟巢
我也发点:

OpenLDAP学习笔记
整理:Jims of 肥肥世家

<jims...@gmail.com>

Copyright (c) 2004,2005, 本文遵从GNU 的自由文档许可证(Free Document License)的条款,欢迎转载、
修改、散布。

发布时间:2004年04月07日

最近更新:2005年08月08日

Abstract

LDAP(轻量级目录服务访问协议,Lightweight Directory Access Protocol)基于X.500标准,支持TCP/
IP,使用简单方便。现在越来越多的网络应用系统都支持LDAP。OpenLDAP是LDAP的一种开源实现,本笔记基于
OpenLDAP2.1.29。

Table of Contents

1. 目录服务简介

1.1. X.500和LDAP
1.2. LDAP产品

2. OpenLDAP安装笔记

2.1. 源码安装
2.2. 数据录入

2.2.1. 手动录入方法
2.2.2. 文件方式
2.2.3. 脚本方式

2.3. 常用命令介绍
2.4. 启用sasl验证
2.5. 配置服务器复制

3. 管理工具

3.1. phpldapadmin
3.2. gq
3.3. CPU
3.4. JXplore
3.5. kldap
3.6. LAM

4. HowTo

Chapter 1. 目录服务简介

Table of Contents

1.1. X.500和LDAP
1.2. LDAP产品

目录是一个为查询、浏览和搜索而优化的专业分布式数据库,它成树状结构组织数据,就好象Linux/Unix系统中的文件目录一样。目录数据库和关系数
据库不同,它有优异的读性能,但写性能差,并且没有事务处理、回滚等复杂功能,不适于存储修改频繁的数据。所以目录天生是用来查询的,就好象它的名字一
样。目录服务是由目录数据库和一套访问协议组成的系统。类似以下的信息适合储存在目录中:

*

企业员工和企业客户之类人员信息;
*

公用证书和安全密钥;
*

邮件地址、网址、IP等电脑信息;
*

电脑配置信息。
*

...

1.1. X.500和LDAP

现在国际上的目录服务标准有两个,一个是较早的X.500标准,一个是较新的LDAP标准。

*

X.500是一个协议族,由一系列的概念和协议组成,包括:
o

X.501是模型定义,定义目录服务的基本模型和概念;
o

X.509是认证框架,定义如何处理目录服务中客户和服务器认证;
o

X.511是抽象服务定义,定义X.500提供的功能性服务;
o

X.518是分布式操作过程定义,定义如何跨平台处理目录服务;
o

X.519 是协议规范,定义了X.500协议,包括DAP(Directory Access Protocol,目录访问
协议)、DSP(Directory System Protocol,目录系统协议)、DOP(Directory Operator
Protocol,目录操作绑定协议)、DISP(Directory Information Shadowing Protocol,目录信息阴影
协议 );
o

X.520定义属性类型要求;
o

X.521定义对象类型;
o

X.525定义如果在目录服务器间复制内容。

X.500标准中定义了很多内容,包括:
o

定义了信息模型,确定目录中信息的格式和字符集,如何在项中表示目录信息(定义对象类、属性等模式);
o

定义命名空间,确定对信息进行的组织和引用,如何组织和命名项-目录信息树DIT和层次命名模型;
o

定义功能模型,确定可以在信息上执行的操作;
o

定义认证框架,保证目录中信息的安全,如何实现目录中信息的授权保护-访问控制模型;
o

定义分布操作模型,确定数据如何分布和如何对分布数据执行操作,如何将全局目录树划分为管理域,以便管理。
o

定义客户端与服务器之间的通信的各种协议。

由于X.500较复杂,且需严格遵照OSI七层协议模型。造成应用开发较困难。所以开发了LDAP,以便在INTERNET上使用。
*

LDAP协议于1993年获批准,产生LDAPv1版,1997年发布最新的LDAPv3版,该版本是LDAP协议发展的一个里程碑,它作
为X.500的简化版提供了很多自有的特性,使LDAP功能更为完备,具有更强大的生命力。

LDAP也是一个协议族,包含以下内容:
o

RFC 2251--LDAPv3核心协议,定义了LDAPv3协议的基本模型和基本操作;
o

RFC 2252--定义LDAPv3基本数据模式(Schema)(包括语法、匹配规则、属性类型和对象类)以及标准的系统
数据模式;
o

RFC 2253--定义LDAPv3中的分辩名(DN)表达式;
o

RFC 2254--定义了LDAPv3中的过滤表达式;
o

RFC 2255--定义LDAPv3统一资源地址的格式;
o

RFC 2256--定义LDAPv3中使用X.500的Schema列表;
o

RFC 2829--定义了LDAPv3中的认证方式;
o

RFC 2830--定义了如何通过扩展使用TLS服务;
o

RFC 1823--定义了C的LDAP客户端API开发接口;
o

RFC 2847--定义了LDAP数据导入、导出文件接口LDIF。

这些协议定义了LDAP的内容,包括:
o

定义了一个信息模型,确定了LDAP目录中信息的格式和字符集,如何表示目录信息(定义对象类、属性、匹配规则和语法等模
式);
o

定义了命名空间,确定信息的组织方式--目录树DIT,以DN和RDN为基础的命名方式,以及LDAP信息的Internet
表示方式;
o

定义了功能模型,确定在可以在信息上执行的操作及API。
o

定义了安全框架,保证目录中信息的安全,定义匿名、用户名/密码、SASL等多种认证方式,以及与TLS结合的通讯保护框
架;
o

定义分布式操作模型,基于指引方式的分布式操作框架;
o

定义了LDAP扩展框架。

1.2. LDAP产品

现在市场上有关LDAP的产品已有很多,各大软件公司都在他们的产品中集成了LDAP服务,如Microsoft的ActiveDirectory、
Lotus的Domino Directory、IBM的WebSphere中也集成了LDAP服务。LDAP的开源实现是OpenLDAP,它比商业
产品一点也不差,而且源码开放。
Chapter 2. OpenLDAP安装笔记

Table of Contents

2.1. 源码安装
2.2. 数据录入

2.2.1. 手动录入方法
2.2.2. 文件方式
2.2.3. 脚本方式

2.3. 常用命令介绍
2.4. 启用sasl验证
2.5. 配置服务器复制

2.1. 源码安装

我的安装方法是以源码编译的方式进行的,以root用户进行安装。安装所需软件如下:

*

openldap-2.1.29
*

Berkeley DB 4.2.52

具体的安装步骤如下:

1.

由于openldap需要Berkeley DB来存放数据,所以需先安装Berkeley DB 4.2.52,可到它的网站下载,网址
见上面。运行下面的命令解压:

# tar -zxvf db-4.2.52.tar.gz

解完压后,会生成一个db-4.2.52目录,进行该目录下的build_unix目录。执行以下命令进行配置安装。

# ../dist/configure
# make
# make install

也是按linux源码安装的三步曲完成,没有什么好说的了。该软件默认是安装在/usr/local/BerkeleyDB.4.2目录
下。安装完成后,要把/usr/local/BerkeleyDB.4.2/lib的库路径加到/etc/ld.so.conf文件内,添加完成后执行
一次ldconfig,使配置文件生效。这样编译openldap时才能找到相应的库文件。这样资料库就安装完成了,接下来可以安装openldap
了。 ld.so.conf是什么东西?它就是系统动态链接库的配置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录/
lib, /usr/lib除外),各个目录名间以空白字符(空格,换行等)或冒号或逗号分隔。一般的LINUX发行版中,此文件均含一个共享目录/
usr /X11R6/lib,为X window窗口系统的动态链接库所在的目录。 ldconfig是它的管理命令,具体操作方法可查询man手
册,这里就不细讲了。
2.

到openldap官方网站下载最新的稳定版源码,并解压。查看INSTALLT 和README文档,这个很重要,因为安装方法和一些注
意事项都在里面有介绍。认真弄明白文档内容能节省你不少的安装调试时间。这也是开源软件的一个特点,给用户提供了最大的灵活性和可配置性。但也增加了系
统安装配置的难度,需要有相关的文档配置说明和指导。在官方网站上还有详细的帮助文件,在整个系统配置中需要经常查询。

# tar -zxvf openldap-stable-20040329.tgz

解压完成后,会生成一个openldap-2.1.29目录。进行该目录,执行以下命令进行配置安装。

# env CPPFLAGS="-I/usr/local/BerkeleyDB.4.2/include"
LDFLAGS="-L/usr/local/BerkeleyDB.4.2/lib" ./configure --prefix=/
usr/local/openldap
--enable-ldbm

注意以上配置语句,要设置资料库的include和lib路径,否则在配置到资料库相关内容时会提示Berkeley DB版本不兼容,并
中断配置。如果没有--enable-ldbm选项,在make test时会提示ldbm找不到。为了减少出错,还是加上为好。

#make depens
#make
#make test

在make test阶段要花费较长时间进行测试,好像有16项吧。你可以放松一下,上上网,聊聊天,听听歌,呵呵,开玩笑了,这个时间应
该是最紧张的了。成与不成就看这下的了,如果没问题就可安装了。

#make install

通过配置命令可以看出,我们把openldap安装到/usr/local/openldap目录下。建议以源码安装的软件都放到独立的目
录下,不要放到软件默认的目录。好处是方便管理和控制,所有文件在统一的目录下,卸载软件只要删除整个目录就可以了。
3.

安装完相关软件后就可以着手配置了。Berkeley DB资料库没什么好配置的。主要是配置openldap 服务。配置文件在软件的安
装目录的etc/openldap下,有四个文件,主要的是slapd.conf and ldap.conf,其它两个是backup文件。首先,我
们先来配置slapd.conf文档。系统默认的slapd.conf文件如下:

# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8
2003/05/24 23:19:14 kurt 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
#设置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
#设置pid和args文档位置
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:
# 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!


#######################################################################
# ldbm database definitions

#######################################################################

database bdb
#设置使用的资料库,也可用lbdm。
suffix "dc=my-domain,dc=com"
#设置目录后缀
rootdn "cn=Manager,dc=my-domain,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 secret
#设置管理密码,这里用了明文的"secret"密码。这样设置不安全,需使用加密的密码,下面会讲到如何设置加密密码。
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /usr/local/openldap/var/openldap-data
#设置资料库路径
# Indices to maintain
index objectClass eq
#设置目录项索引

要服务器正常动作,要修改一些始初参数和设置,修改后的配置文档如下:

# $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8
2003/05/24 23:19:14 kurt 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/
corba.schema
include /usr/local/openldap/etc/openldap/schema/
cosine.schema
include /usr/local/openldap/etc/openldap/schema/
inetorgperson.schema
include /usr/local/openldap/etc/openldap/schema/
misc.schema
include /usr/local/openldap/etc/openldap/schema/
openldap.schema
include /usr/local/openldap/etc/openldap/schema/
nis.schema
include /usr/local/openldap/etc/openldap/schema/
samba.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

loglevel 1
#增加了日志功能,需修改syslog配置文件,在文件中增加一项:local4.* /var/log/ldap.log日志级别定义可
查相官方网站的文档。
#1级记录的信息很多,可用于调试。
# 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!


#######################################################################
# ldbm database definitions

#######################################################################

database bdb
suffix "dc=it,dc=com"
#改成你自已的目录后缀,
rootdn "cn=root,dc=it,dc=com"
#设置root为管理员,与linux的root没有什么关系。
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw {MD5}mjkiuPt0wXhpxxkdiOOO+0000000AKq0by
#设置root密码,用MD5加密。密码串用slappasswd -h {MD5}指令生成
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /usr/local/openldap/var/openldap-data
# Indices to maintain
index objectClass eq
#这里可根据你的需要设置相关索引,以加快查询速度。具体内容可查询官方网站管理手册。

#ACL configure以下内容定义访问控制
access to attr=userPassworduserPassword
#只能由自已修改,有效验证用户查询。
by self write
by anonymous auth
access to attr=mail
by dn="cn=root,dc=it,dc=tigerhead" writemail
#只能由自已修改,有效验证用户查询。
by self write
by anonymous auth
access to dn=".*,dc=it,dc=tigerhead"
#允许所有人查询没受控制访问限制的信息。
by self write
by * read

到现在为止,服务器基本就配置完成了,可以启动了,服务器程序是位于安装目录的libexec下的slapd程序。注意,不是 sldap
哦。ok,到现在为止,服务器基本就配置完成了,可以启动了,服务器程序是位于安装目录的libexec下的slapd程序。注意,不是 sldap
哦。启动服务器执行以下命令:

# ./slapd

如果没有提示什么出错信息,直接返回shell状态,就说明服务器正常启动了,你可以查询日志或用ps -aux查看。或用以下命令查询服
务器:

ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts

如果命令执行成功,返回一些信息,则说明服务器正常运行了。如果启动不成功,它会提示一些出错信息,多数是slapd.conf配置出错。
回头仔细核查一下配置文档。
4.

客户端配置文档是ldap.conf。该文档相当简单,其实不用配置也能正常操作。

# $OpenLDAP: pkg/ldap/libraries/libldap/ldap.conf,v 1.9
2000/09/04 19:57:01 kurt Exp $
#
# LDAP Defaults
#

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

BASE dc=it, dc=com设置目录起点
#URI ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT 12
#TIMELIMIT 15
#DEREF never

jerrymy

unread,
Jan 21, 2009, 4:06:12 AM1/21/09
to Linux-鸟巢
http://zh.wikipedia.org/w/index.php?title=%E8%BD%BB%E5%9E%8B%E7%9B%AE%E5%BD%95%E8%AE%BF%E9%97%AE%E5%8D%8F%E8%AE%AE&variant=zh-cn

我还是没弄明白LDPA是什么,做什么用?

On 1月21日, 下午4时56分, jerrymy <jerr...@126.com> wrote:
> 我也发点:
>
> OpenLDAP学习笔记
> 整理:Jims of 肥肥世家
>

> <jims.y...@gmail.com>

> ...
>
> 阅读更多 >>

frozen

unread,
Jan 21, 2009, 8:03:48 AM1/21/09
to Linux-鸟巢
目前我只是用来和NIS一样玩了一下,帐户集中管理了。。

On Jan 21, 5:06 pm, jerrymy <jerr...@126.com> wrote:
> http://zh.wikipedia.org/w/index.php?title=%E8%BD%BB%E5%9E%8B%E7%9B%AE...

> ...
>
> read more >>

Reply all
Reply to author
Forward
0 new messages