此博文为工作中的一次实例,各位观众如有不明白的地方可发表评论,大家一起探讨,共同了解,共同进步。

1.1    LDAP总体介绍

LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol) 是实现提供被称为目录服务的信息服务。目录服务是一种特殊的数据库系统,其专门针对读取,浏览和搜索操作进行了特定的优化。目录一般用来包含描述性的,基于属性的信息并支持精细复杂的过滤能力。目录一般不支持通用数据库针对大量更新操作操作需要的复杂的事务管理或回卷策略。而目录服务的更新则一般都非常简单。这种目录可以存储包括个人信息、web链结、jpeg图像等各种信息。为了访问存储在目录中的信息,就需要使用运行在TCP/IP之上的访问协议—LDAP<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

LDAP 目录中的信息是是按照树型结构组织,具体信息存储在条目(entry)的数据结构中。条目相当于关系数据库中表的记录;条目是具有区别名DNDistinguished Name)的属性(Attribute),DN是用来引用条目的,DN相当于关系数据库表中的关键字(Primary Key)。属性由类型(Type)和一个或多个值(Values)组成,相当于关系数据库中的字段(Field)由字段名和数据类型组成,只是为了方便检索的需要,LDAP中的Type可以有多个Value,而不是关系数据库中为降低数据的冗余性要求实现的各个域必须是不相关的。LDAP中条目的组织一般按照地理位置和组织关系进行组织,非常的直观。LDAP把数据存放在文件中,为提高效率可以使用基于索引的文件数据库,而不是关系数据库。类型的一个例子就是mail, 其值将是一个电子邮件地址。

LDAP的信息是以树型结构存储的,在树根一般定义国家(c=CN) 或域名(dc=com),在其下则往往定义一个或多个组织(organization)(o=Acme)或组织单元(organizational units) (ou=People)。一个组织单元可能包含诸如所有雇员、大楼内的所有打印机等信息。此外,LDAP支持对条目能够和必须支持哪些属性进行控制,这是有一个特殊的称为对象类别(objectClass)的属性来实现的。该属性的值决定了该条目必须遵循的一些规则,其规定了该条目能够及至少应该包含哪些属性。例如:inetorgPerson对象类需要支持sn(surname)cn(common name)属性,但也可以包含可选的如邮件,电话号码等属性。

在本系统中的LDAP目录结构为:

dc=xxx,dc=com       -------root dn

   +o=commonUser     ------- operation dn    

           + l=xxx      -------base dn

                 +LoginName=xxx           -------用户登录名

                         +ServiceCode=xxx     -------用户所订购的服务的代码

1.2    阅读对象

系统维护人员

2        安装说明

2.1    设置系统环境

假设:

主机名:pp250

    安装路径:/usr/netscape/

    主机IP192.168.11.96

设置以下系统环境:

1、使用系统管理员帐号登录AIX系统,设置domainname

#domainname onewave.com

2、设置主机别名:pp250.onewave.com

    编辑/etc/hosts 主机别名加入pp250.onewave.com

 

2.2    安装LDAP

得到directory.5.2p4.tar.gz的安装包

解开:tar zxvf directory.5.2p4.tar.gz

cd directory

./setup

1Would you like to continue with installation? [Yes]: Yes

2Do you agree to the license terms? [No]: Yes

3,(选择安装内容)

Select the items you would like to install:

1.Netscape Servers

       Installs Netscape Servers with the integrated Netscape Console onto your computer.

       2.Netscape Console

       Installs Netscape Console as a stand-alone Java application on your computer.

To accept the default shown in brackets, press the Enter key.Select the component you want to install [1]:1

4,(选择自定义安装)

Choose an installation type:

1.Express installation

       Allows you to quickly install the servers using the most common options and pre-defined defaults. Useful for quick  evaluation of the products.

2.Typical installation

       Allows you to specify common defaults and options.

3.Custom installation

       Allows you to specify more advanced options. This is recommended for experienced server administrators only.

To accept the default shown in brackets, press the Enter key.Choose an installation type [2]:3

5,(安装目录)

Install location [/usr/netscape]: /usr/netscape/

6,(产品组件)

    1. Netscape Server Products Core Components (3)

    2. Netscape Directory <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />
Suite (2)

    3. Administration Services (2)

Specify the components you wish to install [All]: 回车

7,(核心组件)

    1. Netscape Server Products Core Components

    2. Netscape Core Java classes

    3. Java Runtime Environment

Specify the components you wish to install [1, 2, 3]: 回车

8,(Suite components

    1. Netscape Directory Server

    2. Netscape Directory Server Console

Specify the components you wish to install [1, 2]: 回车

9,(Administration Services components

    1. Netscape Administration Server

    2. Administration Server Console

Specify the components you wish to install [1, 2]: 回车

10,主机域名:<hostname>.<domainname>

注:要先在/etc/hosts中设置,例如:192.168.11.96  pp250.onewave.com

Computer name  [pp250.onewave.com]: 回车

11,指定执行该服务的用户及组,通常情况下使用nobody用户来执行。

System User [nobody]: 回车   

System Group [nobody]: 回车

12Do you want to register this software with an existing Netscape configuration directory server? [No]: 回车

13,数据是否存放在本地目录服务器中

If you want this directory server to store your data, answer No. Do you want to use another directory to store your data? [No]: 回车

14,监听端口

Directory server network port [389]: 回车

15,输入Directory server identifier

Directory server identifier [pp250]: 回车

16admin用户名和密码

Netscape configuration directory server administrator ID [admin]: 回车

Password:

Password (again):

17,根节点标识:

Suffix [o=onewave.com]:dc=onewave,dc=com

18,输入对目录管理具有无限制权利的名称和密码:

Directory Manager DN [cn=Directory Manager]:cn=Manager

Password:

Password (again):

19,域名

Administration Domain [onewave.com]: 回车

20,是否配置复制(可以在安装完毕之后到console中配置)

Do you want to configure this directory server to use replication? [No]: 回车

21,创建sample entry

Do you want to install the sample entries? [No]: 回车

22,是否导入数据

Type the full path and filename, the word suggest, or the word none

 [suggest]: 回车

23check config

Do you want to disable schema checking? [No]: 回车

24,管理端口

Administration port [8888]:

25,服务绑定ip

IP address [192.168.11.96]:

26,启动用户

Run Administration Server as [root]: 回车

 

27,开始安装:

Extracting Netscape core components...

[slapd-iptva1]: starting up server ...

... ...

[slapd-iptva1]: [02/Aug/2005:15:28:21 +0800] - Netscape-Directory/5.2 SP4 B02.079.1031 starting up

 [slapd-iptva1]: [02/Aug/2005:15:28:22 +0800] - slapd started.

Your new directory server has been started.

startup: listening to [url]http://iptva1[/url], port 30888 as root

……

Go to /data/netscape and type startconsole to begin manaing your servers.

 

2.3    启动LDAP

启动LDAP

#/usr/netscape/slapd-pp250/restart-slapd

 

停止LDAP:

#/usr/netscape/slapd-pp250/stop-slapd

 

2.4    配置说明

2.4.1            导入初始化数据

初始数据包含根节点、其它目录节点的导入,可以通过ldap browser进行导入。如果是需要配置replication的,则只需要在主的LDAP中导入数据。

 

2.4.2            BOSS添加的属性、对象设置

属性、对象存储位置:/usr/netscape/slapd-pp250/config/schema/*.ldif

通过LDAP的系统管理窗口(console)对属性、对象进行维护。

 

属性显示器

启动控制台图形界面:

#/data/netscape/startconsole

 
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />

输入admin账户。密码,正确的Administration URL,如上图所示。

添加属性

LDAP中需要添加BOSS系统定义的一些新属性。

进入控制台界面后,点Console:Directory Server(pp250)àConfiguration:SchemaAttributes

显示属性维护页面,如下图所示:可以对属性进行添加、修改和删除

添加对象

属性添加后进行对象类的定义。

Console:Directory Server(pp250)àConfiguration:SchemaObject Classes

显示对象类维护页面,如下图所示:可以对对象类性进行添加、修改和删除

2.4.3            系统参数配置

使用 console 图形界面设置一些系统参数。

1、设置 Index
打开directory server的控制面板
configuration
àdatabaseà Indexs
【注】不要删除已有的Index
点击Add Attribute,加入l, loginName, ServiceCode作为 Index
保存所作修改
2、设置 performance
打开directory server的控制面板
configuration
àdatabaseà performance
修改下列各值,并保存。
Maximum entries in cache:       2000
Maximum cache size:             20000000
Look-through limit:               5000

 

 

2.4.4            replication配置

假设pp250(),iptv副,则pp250设置为Supplier,iptv设置为Customer

设置时候先设置Customer,再设置Supplier

 

通过console配置replication

1,consumer配置

启动控制台图形界面:

#/data/netscape/startconsole

注:用户名密码及端口同安装的16步中设定的用户名密码及24步中设置的管理端口

 

双击Directory Serveriptv),选择configuration ,进入配置页面,如下图:

 

选中“Replication Agreements”,在右边的consumer setting中进行配置:

<<consumer settings>>

Supplier DN:cn=supplier

New supplier password

Confirm new supplier password

<<supplier settings>>not set

保存之后退出

 

2,supplier配置

同上,进入图形界面中

<<cosumer settings>>(no set)
<<supplier settings>>

database dir:/usr/netscape/slapd-pp250/changlogdb    use default
    changelog suffix:cn=changelog
    Max changelog records:unlimited(V)
    Max changelog age: 2 days unlimited[]

保存之后重启ldap

3,创建replication agreement

在主ldap中右键点击Replication Agreements,选择new replication agreement,如下图:

 

选择supplier initiated agreement,如下图,输入agreement name

点击next,如下图:

consumer中点击other,输入consumer的主机和服务端口:

bind ascn=supplier(同consumer中的配置一致)

password:supplier(同consumer中的配置一致)

subtree:dc=onewave,dc=com(l=ipauth,dc=onewave,dc=com)(可以同步跟节点,也可以选择部分叶节点进行同步)

点击next,如下:选择同步时间

 

点击next,初始化consumer,如下图:

初始化consumer(在数据量大的情况下,不要选择立即初始化,选择创建ldif文件或者以后再初始化),配置完成之后,再利用手工的方式进行初始化。

手工初始化的步骤见附录。

 

 

2.5    LDAP使用和基本维护

2.5.1             Netscape Directory Server 安装参数

1.  Netscape Directory Server 安装目录:/usr/netscape/slapd-`hostname`/

2.  Netscape Directory Server 目录列表:

目录

作用

bak

Ldap 数据库备份目录

changelogdb

ldap上存放同步用的changelog信息

confbak

Ldap 配置信息备份目录

config

Ldap 配置文件目录

db

Ldap 数据库目录

ldif

Ldif 文件导出目录

locks

记录ldap的锁信息的目录

logs

Ldap log 目录

ssl

Ssl 信息存储目录

3.  Netscape Directory Server 主目录下脚本列表:

脚本名

作用

脚本范例

bak2db

Ldap数据库备份目录下最新的archived备份恢复回ldap

./bak2db bak/2004_03_25_155704

db2bak

ldap数据库数据备份到bak目录下

./db2bak

db2ldif

ldap数据库数据导出为ldif格式的文件,备份到ldif目录

./db2ldif

getconf

获得ldap数据库配置参数

./getconf

getpwenc

获得ldap密码加密后的秘文

./getpwenc sha 123456

./getpwenc crypt 123456

ldif2db

ldif文件中的信息直接写入数据库

具体用法请见4.3.5

ldif2ldap

ldif文件中的信息按照ldapadd的格式写入数据库

具体用法请见4.3.5

ldifbak

cron中定义的每天备份ldap的脚本

30 1 * * * /data3/netscape/server4/ slapd-ldap1/ldifbak

monitor

Ldap 是否正常运行的监控脚本

./monitor

restart-slapd

Ldap 重启脚本

./restart_slapd

restoreconfig

confbak目录下最新的ldap配置信息恢复回ldap

./restoreconfig

saveconfig

ldap配置信息备份至confbak目录

./saveconfig

start-slapd

Ldap 启动脚本

./start-slapd

stop-slapd

Ldap 停止脚本

./stop-slapd

vlvindex

reserved

 

注:以上表格中,粗体标注的命令,会对ldap产生一定破坏操作,不要轻易尝试。

2.5.2            Directory Cosole的使用

使用图形软件(如:XManager)登录AIX系统,并设置显示到本机:如:本机IP192.168.11.160,则使用命令设置:#set DISPLAY=192.168.11.160:0.0

1.启动Directory Server 控制台

a.确定directory server daemonslapd_serverID运行着,否则,以root身份启动它。

#/usr/netscape/slapd_pp250/start-slapd

b.确定管理服务器daemonadmin-serv正在运行,否则,以root身份启动它。

#/usr/netscape/start-admin

c.启动iplanet控制台,将出现控制台登录对话框。

% /usr/netscape/startconsole

d.用具有足够权限的用户登录,并输入相应的约束DN和密码。

例:

 

e.在拓扑表中,沿着导航树直到看见Directory Server的图标,双击它,则可进入Directory Server控制台。

2.改变登录身份

a.Directory Server控制台上选择任务表。

b.点击“log on to the Directory Server as a new user”,便出现一个登录对话框。

c.输入新的DN和密码,点击OK

3.iplanet控制台上查看当前的DN

点击左下角的login图标,则可出现当前的DN

2.5.3            Directory Server监控程序的使用

slapd 进程的监控:/usr/netscape/slapd_*/ldapmon

编辑/var/spool/cron/crontabs/root文件,添加下列内容:

     * * * * * su – root –c ‘/usr/netscape/slapd_*/ ldapmon

   然后重启cron:

    /etc/rc2.d/S75cron stop

    /etc/rc2.d/S75cron start

2.5.4             Directory Server基本命令使用

ldapsearch

ldapsearch –h server –p port –D binddn –w password –b “basedn” filter

-h: ldap server的主机名或IP

-p: ldap server的端口

-D: bind的用户DN通常为: “cn=Manager”

-w: bind的用户的密码

-b: 需要搜索的dn

filter: 用以搜索的过滤器。例如objectclass=*, loginName=xxx等。

例子

%/usr/netscape/shared/bin/ldapsearch -h 192.168.11.96 -p 389 -D cn=Manager -w onewaveinc -b cn=period,dc=onewave,dc=com  -s sub "objectclass=*"

 

ldapmodify:

ldapmodify –h server –p port –D binddn –w password -f /path/to/your/file/modify_file

-h: ldap server的主机名或IP

-p: ldap server的端口

-D: bind的用户DN通常为: “cn=Manager”

-w: bind的用户的密码

-f: 指定modify_file的路径及文件名

modify_file的格式

dn:

changetype: modify

replace: attribute

attribute_name: attribute_value

注:modify_file里的每一行记录的冒号之后都必须有一个空格

例如:修改用户test的密码为123456。其中test用户的dn: loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com,相应的modify_file如下:

dn: loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com

changetype: modify

replace: userPassword

userPassword: 123456

例子:

./ldapmodify -a -h 192.168.11.96 -p 389 -D cn=Manager -w onewaveinc  -f /usr/netscape/test.ldif

 

ldapdelete:

ldapdelete –h server –p port –D binddn –w password -f /path/to/your/file/deldn_file

-h: ldap server的主机名或IP

-p: ldap server的端口

-D: bind的用户DN通常为: “cn=Manager”

-w: bind的用户的密码

-f: 指定deldn_file的路径及文件名deldn_file里记录了要删除的每一个entrydn信息,注意:要删除节点不能包含子节点,若要删除带子节点的数据,则先删除子节点后再删除该节点。。

例如要删除用户test其中test用户的dn: loginName=test,o=commonUser,l=radtest,dc=onewave,dc=comdeldn_file的内容为

loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com

 

db2ldif:

db2ldif 是可以在线导出ldif文件的,导出的文件在$Server_root/slapd-*/ldif下。

-r ,-a参数的ns-slapd db2ldif 是一定要在ldap 服务停下来之后执行的。

cd $Server_root/bin/slapd/server

./ns-slapd db2ldif -f $Server_root/slapd-*/config/slapd.conf -n [-r] -a $ldif_file -s "baseDN"

db2ldif 是可以在线导出ldif文件的,导出的文件在$Server_root/slapd-*/ldif下。

-f: Directory Server 配置文件slapd.conf的绝对路径

-r: 需要导出ldif文件为复制副本时,加上该参数。这个参数加不加的区别在于加上-r参数,会有一句copied from的话,这个在配置主备的时候有用,其它情况可以不用。

-a: 导出ldif文件的绝对路径及文件名

-s: 导出的baseDN,通常为:dc=xxx,dc=com

ldif2db:

cd $Server_root/bin/slapd/server

ns-slapd ldif2db -f $Server_root/slapd-*/config/slapd.conf \

-i $ldif_file -s "baseDN" -x o=NetscapeRoot

-f: Directory Server 配置文件slapd.conf的绝对路径

    如果使用-f指定配置文件,是先倒数据,再一个一个index建的(每次处理只能建一个index,多个index情况下,一次又一次处理,所以在数据量大的情况下挺慢的)。

    如果不用-f ,可以直接使用-noconfig ,这个是不管配置文件,直接原来ldif文件中有什么数据,就在导入的时候全部覆盖,在导入的同时生成index,比较快。

   我觉得,如果自己作了一个完整的ldif文件,比如有配置信息,然后加上数据信息,再导入,可以直接使用noconfig来倒。

-i: 需导入的ldif文件的绝对路径及文件名

-s: 导出的baseDN,通常为:dc=xxx,dc=com

-x: 不要导入的dn

 

2.5.5            数据备份

数据目录:/usr/netscape/slapd-pp250/db/

定期做数据备份。可以使用cron处理。