`
hugang357
  • 浏览: 181613 次
  • 性别: Icon_minigender_2
  • 来自: 深圳
社区版块
存档分类
最新评论

网络管理:openldap详解

    博客分类:
  • java
阅读更多

简介

LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP。它是基于X.500标准的,但是简单多了并且可以根据需要定制。与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的。LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到。 简单说来,LDAP是一个得到关于人或者资源的集中、静态数据的快速方式。 LDAP是一个用来发布目录信息到许多不同资源的协议。通常它都作为一个集中的地址本使用,不过根据组织者的需要,它可以做得更加强大。

安装

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

数据录入

服务器正常运作后,就可以录入信息了。信息的录入有三种方法,一种是手工录入,一种是.ldif文件格式录入,一种是脚本自动录入。我们先从最基础的手工录入方式开始介绍,了解录入信息的格式。明白了手工录入的格式,其它两种方式都很容易明白。信息录入用到ldapadd这个程序。可在安装目录的bin目录下找到。

手动录入方法

第一步是要建立DN:

    # ldapadd -x -D 'cn=root,dc=it,dc=com' -W
    dn: dc=it,dc=com
    objectClass: dcObject
    objectClass: organization
    dc: it
    o: Corporation
    description: d Corporation

注意:如果你用复制/粘贴功能把以上内容拷贝过去,一定要注意每行后面不要有空格,建议还是手工输入,按Ctrl+d存盘。

第二步是建立RDN:

    # ldapadd -x -D 'cn=root,dc=it,dc=com' -W        
    #-x表示用简单验证,-D表示指定目录,-W表示弹出密码输入提示

输入密码,这里的密码是在配置文件中rootpw项设置的密码,不是操作系统中root用户的密码。验证通过后就可输入以下内容:

    dn: uid=qq,dc=it,dc=com
    objectClass: person
    objectClass: organizationalPerson
    objectClass: inetOrgPerson
    uid: qq
    cn: qq
    sn: qq
    telephoneNumber: 138888888
    description: openldap test
    telexNumber: tex-8888888
    street: my street
    postOfficeBox: postofficebox
    displayName: qqdisplay
    homePhone: home1111111
    mobile: mobile99999
    mail:qq@qq.com

输入完所有信息后,按Ctrl+d结束存盘。如果出现出错信息,请查一下对象类和属性的对应关系有没有错或输入失误。初学者就容易出错的地方是对象类和属性的对应关系没有处理好。对象类和属性是在schema文档中定义的。它们之间的关系是这样的,对象类中有些属性是必选的,有些属性是可选的。录入信息的属性必须在对象类中有定义才能用。

输入以下命令可查询到刚才输入的信息。

# ldapsearch -x -b 'dc=it,dc=com'            
-b选项是设置目录起点,如果设置了客户端的BASE配置参数,该项可不用。

如果按以上配置文件设置了acl,用上面的查询命令是查询不到受保护的内容的。如上面的userPassword and mail。要查询到这些受限内容,需要通过验证才可以:

# ldapsearch -x -LLL -h it.com -b 'dc=it,dc=com' -D 'uid=qq,dc=it,dc=com' -W 'uid=qq'
接着提示输入密码。输入userPassword的密码回车,所有信息就都出来了。

文件方式

.ldif文件方式也就是把以上手工输入的内容先写入一个.ldif文件中,然后,用ldapadd命令的-f参数导入。

# ldapadd -x -D "cn=root,dc=it,dc=com" -W -f test.ldif

一个完整的global.ldif文件例子:

dn: dc=info, dc=net
objectClass: top
objectClass: organization
o: info.net
dn: ou=People, dc=info, dc=net
objectClass: top
objectClass: organizationalUnit
ou: People
description: User Info
dn: cn=Admin, dc=info, dc=net
objectClass: top
objectClass: person
objectClass: organizationalPerson
cn: Admin
sn: Admin
userPassword: Admin
description: Administrator for info.net
dn: id=1, ou=People, dc=info, dc=net
objectclass: top
objectclass: InfoPerson
id: 1
username: 张三
tel:021-63138990
card_id:ABC001

我们也可用slapadd命令来导入数据。该命令可以导入包含一些系统信息的ldif文件,如:

dn: dc=it,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
dc: it
structuralObjectClass: organization
entryUUID: d97b06da-d77e-1028-9866-d4ec7ac00d12
creatorsName: cn=anonymous            #系统信息
createTimestamp: 20041201005115Z      #系统信息
o:: 5bm/5bee5biC6JmO5aS055S15rGg6ZuG5Zui5pyJ6ZmQ5YWs5Y+4
userPassword:: e01ENX14TXBDT0tDNUk0SU56RkNhYjNXRW13PT0=
entryCSN: 2004120603:50:08Z#0x0001#0#0000     #系统信息
modifiersName: cn=admin,dc=it,dc=com          #系统信息
modifyTimestamp: 20041206035008Z              #系统信息

[Note] 再次提醒,注意每行后面不要留有空格。

脚本方式

脚本录入方式需要自已编写脚本,或到网上下载。有一个用PHP写的LDAP管理工具不错,叫phpLDAPadmin。可以到以下网址下载:http://phpldapadmin.sourceforge.net。安装方法也很简单,只要解压出来,拷贝到apache的web目录下,按说明配置一下设定文档,就ok了。

<!-- wikipage stop -->
分享到:
评论

相关推荐

    docker-openldap:OpenLDAP Docker微服务

    OPENLDAP服务器 Docker的基本LDAPServer安装。 我创建它只是为了好玩。 快速开始 将构建文件下载到您的Docker主机服务器 选项1:从openldap-server.tar.gz下载所有文件 wget tar -xzvf openldap-server.tar.gz mv...

    用GO和Vue实现管理 openLDAP 和 IM 的后台项目

    它是一个基于 Go+Vue 实现的 openLDAP 后台管理项目。它主要实现了以下功能: openLDAP 服务端管理:用户可以通过图形界面对 openLDAP 服务端进行配置、初始化、备份、恢复等操作。 组织架构管理:用户可以通过图形...

    openldap-devel-2.4.44-23.el7_9.x86_64.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    ansible-role-openldap:OpenLDAP服务器角色

    安装openldap服务器 要求 FreeBSD 11/12,debian 8(+?) 角色变量(默认) openldap_schmas ([core,cosine,inetorgperson,nis])如果在files / openldap / {{name}}。schema中存在文件,则LDAP模式要包含在...

    openldap:OpenLDAP服务器的Docker映像

    OpenLDAP Docker映像关于该项目的目的是创建一个容器化且可伸缩的OpenLDAP映像,以用于各种开发项目和/或生产环境。 它旨在尽可能避免交互,并充分利用环境变量进行配置。快速开始运行docker-compose up -d (确保...

    openldap-subordinate-AD:OpenLDAP的初始配置以将AD DIT粘贴为OpenLDAP DIT中的后缀

    openldap从属AD OpenLDAP的初始配置,以使用Ubuntu 18.04 TLS将AD DIT粘贴为OpenLDAP DIT中的后缀安装OpenLDAP:#apt-get install slapd ldap-utils -y 在启动时启用OpenLDAP:#systemctl enable slapd 通过重写...

    openldap-clients-2.4.44-24.el7_9.x86_64.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    openldap详解

    安装配置!confluence的安装以及与LDAP集成

    openldap_hook:OpenLDAP的钩子覆盖-开源

    一个OpenLDAP叠加层,可以在您添加,更改或删除指定组织单位中的条目时启动脚本。 可以在slapd.conf文件或cn = config dn中配置脚本名称和组织单位。

    openldap2.4.48-centos7部署日志

    此文件为centos7部署openldap全过程的日志文件,非常详细,照此操作基本无误 ######################################## #### OS:CentOS Linux release 7.3.1611 (Core) #### db:berkeleydb-5.1.29 #### lpad:...

    docker-ldap:OpenLDAP Docker映像

    它带有预先配置的用户和组基础: dn: ou=Users,dc=elastic,dc=co group:是ES群集管理员组dn: ou=Marvels,dc=elastic,dc=co group:是Marvel UI用户组dn: ou=Watcher,dc=elastic,dc=co组:是Watcher管理器组安装$ ...

    ldap-ui:OpenLDAP的简约Web前端

    简单的LDAP编辑器 这是LDAP目录的最小Web界面。 特征: 目录树视图 条目创建/修改/删除 LDIF导入/导出 JPEG支持inetOrgPerson 模式感知 简单搜索(可配置) 具有可扩展性的异步LDAP后端 ...该应用程序始终需要身份...

    openLDAP 管理员手册

    openLDAP 管理员手册

    Python库 | openldap-config-parser-1.0.2.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:openldap-config-parser-1.0.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    OpenLDAP 管理工具(2.1)

    站点管理工具2.1软件环境: Linux + php + OpenLDAP +ProFTPD 硬件环境: IA-32 开发工具: Dreamweaver 项目描述: Site Manager...OpenLDAP 管理工具,可实现对dn的:浏览、过滤、添加、修改、删除 。支持GB18030

    OpenLDAP2.4管理员指南

    OpenLDAP2.4管理员指南 OpenLDAP2.4管理员指南

    docker-openldap:运行OpenLDAP的docker镜像

    docker-openldap:运行OpenLDAP的docker镜像

    ansible-role-ldap-master-replication:OpenLDAP主复制的Ansible角色

    Ansible Galaxy角色 ,用于在Perun主OpenLDAP服务器上配置复制 角色变量 slapd_base_dn-ldap服务器的基本dn plication_user_uid-用于复制的用户的uid,如果不存在则将创建(因为有效的复制必须具有数据树的读取...

    OpenLDAP2_1管理员指南

    OpenLDAP2_1管理员指南 OpenLDAP2_1管理员指南

    OpenLDAP 管理工具

    2002/12--2002/12:站点管理...OpenLDAP 管理工具,可实现对dn的:浏览、过滤、添加、修改、删除 。支持GB18030 责任描述: 分析,设计,开发 软件界面贴图:http://www.9812.net/xuser/pic/site/release.html 新版 ...

Global site tag (gtag.js) - Google Analytics