红联Linux门户
Linux帮助

openldap的配置手册

发布时间:2005-12-28 08:55:35来源:红联作者:reing
最近一直在安装opneldap-2.0.25,现在终于搞定了,所以拿来和大家分享一下,如果有什么意见,可以共同讨论一下:

1) 一般需要安装以下四个rpm包:
openldap-2.0.25-1.i386.rpm
openldap-servers-2.0.25-1.i386.rpm
openldap-clients-2.0.25-1.i386.rpm
openldap-devel -2.0.25-1.i386.rpm
Openldap-2.0*是必要套件,一定要先安装;Openldap-servers*是服务器套件;openldap-clients*是操作程序套件;openldap-devel*是开发工具套件.
如果需要用ldap做一些高级应用,还需要加装如下套件:
auth_ldap*
nss_ldap*
php_ldap*

2)下一步就是配置了
配置文件一般在/etc/openldap/下:
ldapfilter.conf ldap.conf
ldapsearchprefs.conf schema ldaptemplates.conf slapd.conf
文件slapd.conf是设置ldap服务器连接,进入文件,修改相应的部分:
在include /etc/openldap/schema/……
部分添加完整的方案,即schema目录下的所有方案。
在“ldbm database definitions”部分,用suffix命令设置ldap服务器的基础搜索路径(BDN):
suffix “dc=buct, dc=edu.cn”
rootdn “cn=root, dc=buct, dc=edu.cn”
rootpw 123456
其它大多数的缺省设置都是适当的。
然后检查两个文件,以保证可以在同一台机器上实现服务器与客户端同机操作:
/etc/hosts :
127.0.0.1 localhost.localdomain localhost
202.xxx.xxx.xxx buct.edu.cn
/etc/openldap/ldap.conf:
HOST 202.4.155.91
BASE dc=buct , dc=edu.cn

3)测试服务器:
#service ldap start
#ldapsearch -x -b ‘’ -s base ‘(objectclass=*)’
namingContexts
如果正确配置了,应该出现下面输出:
version :2
#filter(objectclass=*)
#requesting: namingContexts
dn:
namingContexts: dc=buct, dc=edu.cn
#search result
search :2
result :0 success
# numResponses: 2
# numEntries: 1
如果出现错误消息,则返回并检查配置。

4)最后一步是设置一些基本的访问控制,Redhat 将ACL添加到slapd.conf文件里:
#define ACLs ……access control definitions
access to dn=“.* , dc=buct, dc=edu.cn” attr=password
by dn=“cn=root, dc=buct, dc=edu.cn” write
by self write
by * read

access to dn=“.* , dc=buct, dc=edu.cn”
by * read

最后在重起一下ldap服务器,就ok了。
文章评论

共有 1 条评论

  1. tujp123 于 2012-06-06 22:04:01发表:

    为什么我一直找不到ldap目录,
    [root@localhost openldap]# ls
    cacerts ldap.conf schema slapd.conf slapd.conf.bak slapd.d






















    #
    # LDAP Defaults
    #

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

    #BASE dc=example, dc=com
    #URI ldap://ldap.example.com ldap://ldap-master.example.com:666

    #SIZELIMIT 12
    #TIMELIMIT 15
    #DEREF never
    #HOST 127.0.0.1
    HSOT 192.168.1.21
    BASE dc=buct ,dc=edu.cn BASEDN
    TLS_CACERTDIR /etc/openldap/cacerts
    ~
    ~
    ~
    ~
    ~
    "ldap.conf" 17L, 347C written
    [root@localhost openldap]# service ldap star
    ldap: unrecognized service
    [root@localhost openldap]# service ldap start
    ldap: unrecognized service
    [root@localhost openldap]# ldapsearch -x -b ‘’ -s base ‘(objectclass=*)’
    -bash: syntax error near unexpected token `('
    [root@localhost openldap]# ldapsearch -x -b ‘’ -s base ‘(objectclass=*)’
    -bash: syntax error near unexpected token `('
    [root@localhost openldap]# ldapsearch -x -b ‘-s base ‘(objectclass=*)’
    -bash: syntax error near unexpected token `('
    [root@localhost openldap]#
    [root@localhost openldap]#
    [root@localhost openldap]#
    [root@localhost openldap]#
    [root@localhost openldap]#
    [root@localhost openldap]# ls
    cacerts ldap.conf schema slapd.conf slapd.conf.bak slapd.d
    [root@localhost openldap]# vi slapd.conf

    #
    # See slapd.conf(5) for details on configuration options.
    # This file should NOT be world readable.
    #

    include /etc/openldap/schema/corba.schema
    include /etc/openldap/schema/core.schema
    include /etc/openldap/schema/cosine.schema
    include /etc/openldap/schema/duaconf.schema
    include /etc/openldap/schema/dyngroup.schema
    include /etc/openldap/schema/inetorgperson.schema
    include /etc/openldap/schema/java.schema
    include /etc/openldap/schema/misc.schema
    include /etc/openldap/schema/nis.schema
    include /etc/openldap/schema/openldap.schema
    include /etc/openldap/schema/ppolicy.schema
    include /etc/openldap/schema/collective.schema

    # Allow LDAPv2 client connections. This is NOT the default.
    allow bind_v2

    # 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:
    # Module syncprov.la is now statically linked with slapd and there
    # is no need to load it here
    # modulepath /usr/lib/openldap # or /usr/lib64/openldap
    # moduleload accesslog.la
    # moduleload auditlog.la
    ## To load this module, you have to install openldap-server-sql first
    # moduleload back_sql.la
    ## Following two modules can't be loaded simultaneously
    # moduleload dyngroup.la
    # moduleload dynlist.la
    # moduleload lastmod.la
    # moduleload pcache.la
    # moduleload ppolicy.la
    # moduleload refint.la
    # moduleload retcode.la
    # moduleload rwm.la
    # moduleload translucent.la
    # moduleload unique.la
    # moduleload valsort.la

    # The next three lines allow use of TLS for encrypting connections using a
    # dummy test certificate which you can generate by changing to
    # /etc/pki/tls/certs, running "make slapd.pem", and fixing permissions on
    # slapd.pem so that the ldap user or group can read it. Your client software
    # may balk at self-signed certificates, however.
    # TLSCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
    # TLSCertificateFile /etc/pki/tls/certs/slapd.pem
    # TLSCertificateKeyFile /etc/pki/tls/certs/slapd.pem

    # 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
    # allows anyone and everyone to read anything but restricts
    # updates to rootdn. (e.g., "access to * by * read")
    #
    # rootdn can always read and write EVERYTHING!

    #######################################################################
    # ldbm and/or bdb database definitions
    #######################################################################

    database bdb
    suffix "dc=buct,dc=edu.cn"
    rootdn "cn=root,dc=buct,dc=edu.cn"
    cachesize 10000
    searchstack 8
    dbnosync
    dirtyread
    # Cleartext passwords, especially for the rootdn, should
    # be avoided. See slappasswd(8) and slapd.conf(5) for details.
    # Use of strong authentication encouraged.
    rootpw 123456
    rootpw {crypt}ijFYNcSNctBYg

    # 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/lib/ldap

    # Indices to maintain for this database
    index objectClass eq,pres
    index ou,cn,mail,surname,givenname eq,pres,sub
    index uidNumber,gidNumber,loginShell eq,pres
    index uid,memberUid eq,pres,sub
    index nisMapName,nisMapEntry eq,pres,sub

    # Replicas of this database
    #replogfile /var/lib/ldap/openldap-master-replog
    #replica host=ldap-1.example.com:389 starttls=critical
    # bindmethod=sasl saslmech=GSSAPI
    # authcId=host/ldap-master.example.com@EXAMPLE.COM


    # enable monitoring
    database monitor

    # allow onlu rootdn to read the monitor
    access to *
    by dn.exact="cn=Manager,dc=my-domain,dc=com" read
    by * none