LDAP安装

                                                 LDAP安装
 

1、安装cyrus :
http://ftp.andrew.cmu.edu/pub/cyrus-mail/
下载cyrus-sasl-2.1.21.tar.gz 
tar -zxvf cyrus-sasl-2.1.19.tar.gz
cd cyrus-sasl-2.1.21
./configure
make
make install
ln -s /usr/local/lib/sasl2 /usr/lib/sasl2
=================================================
2。安装:Berkeley DB
由于openldap需要Berkeley DB来存放数据,所以需先安装Berkeley DB 4.5.20,运行下面的命令解压:
# tar -zxvf db-4.5.20.tar.gz
#cd db-4.5.20
#cd build_unix
# ../dist/configure
# make
# make install
# vi/etc/ld.so.conf
把/usr/local/BerkeleyDB.4.5/lib的库路径加到/etc/ld.so.conf文件内,添加完成后执行一次ldconfig
#sbin/ldconfig

该软件默认是安装在/usr/local/BerkeleyDB.4.5目录下。安装完成后,要把/usr/local/BerkeleyDB.4.5/lib的库路径加到/etc/ld.so.conf文件内,

添加完成后执行一次ldconfig,使配置文件生效。这样编译openldap时才能找到相应的库文件。 ld.so.conf是什么东西?它就是系统动态链接库的配

置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录/lib, /usr/lib除外),各个目录名间以空白字符(空格,换行等)或

冒号或逗号分隔。一般的LINUX发行版中,此文件均含一个共享目录 /usr/X11R6/lib,为X window窗口系统的动态链接库所在的目录。 ldconfig是它

的管理命令.

3.安装 openldap
到openldap官方网站下载最新的稳定版源码,并解压。
# tar -zxvf openldap-stable-20080813.tgz
#cd openldap-2.4.11/
#env CPPFLAGS="-I/usr/local/include/sasl -I/usr/local/BerkeleyDB.4.5/include" LDFLAGS="-L/usr/lib -L/usr/local/BerkeleyDB.4.5/lib"

./configure --prefix=/usr/local/openldap  --without-cyrus-sasl --enable-ldbm 

注意以上配置语句,要设置资料库的include和lib路径,否则在配置到资料库相关内容时会提示Berkeley DB版本不兼容,并中断配置。如果没有--

enable-ldbm选项,在make test时会提示ldbm找不到。为了减少出错,还是加上为好。

如果报错:
 checking   Berkeley   DB   version   for   BDB/HDB   backends...   no  
 configure:   error:   BDB/HDB:   BerkeleyDB   version   incompatible  
解决方法:
把/usr/local/BerkeleyDB.4.5/include中的所有文件拷贝到/usr/include  
  /usr/local/BerkeleyDB.4.5/lib中的所有文件拷贝到/usr/lib  

#make depend
#make

如果提示错误:
make[3]: *** [init.lo] Error 1
make[3]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers/slapd/back-bdb'
make[2]: *** [.backend] Error 1
make[2]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers/slapd'
make[1]: *** [all-common] Error 1
make[1]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers'
make: *** [all-common] Error 1
解决方法:
cd openldap-2.4.11/servers/slapd/back-bdb/
将init.c 和 cache.c中 #if DB_VERSION_FULL >= 0x04060012改为#if 0 && DB_VERSION_FULL >= 0x04060012之后再make 就能通过了。
#make test
#make install

通过配置命令可以看出,我们把openldap安装到/usr/local/openldap目录下。建议以源码安装的软件都放到独立的目录下,不要放到软件默认的目录

。好处是方便管理和控制,所有文件在统一的目录下,卸载软件只要删除整个目录就可以了。 安装完相关软件后就可以着手配置了。Berkeley DB资

料库没什么好配置的。主要是配置openldap 服务。配置文件在软件的安装目录的etc/openldap下,有四个文件,主要的是slapd.conf and ldap.conf

,其它两个是backup文件。

要服务器正常动作,要修改一些始初参数和设置,
vi /usr/local/openldap/etc/openldap/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
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程序。
启动服务器执行以下命令:
#cd /usr/local/openldap/libexec
# ./slapd
如果没有提示什么出错信息,直接返回shell状态,就说明服务器正常启动了,你可以查询日志或用ps -aux查看。或用以下命令查询服务器:
ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
如果命令执行成功,返回一些信息,则说明服务器正常运行了。如果启动不成功,它会提示一些出错信息,多数是slapd.conf配置出错。回头仔细核

查一下配置文档。

 

客户端配置文档是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====================================
启动服务/usr/local/openldap/libexec/slapd &===================================

四,管理LDAP服务
LDAP已经带了ldapadd,ldapdelete等命令行工具,但使用较复杂,常用的是基于Web的PhpLDAPadmin工具这里用的非常简单的安装
下载地址:phpldapadmin.sourceforge.net
安装过程:

tar -xvf phpldapadmin-0.9.8.2.tar.tar
mv  phpldapadmin-0.9.8.2 /usr/local/apache/htdocs/pda
cp /usr/local/apache/htdocs/pda/config/config.php.sample /usr/local/apache/htdocs/pda/config/config.php

访问:http://172.18.3.208/pda
出现如下错误
Your install of PHP appears to be missing GETTEXT support. GETTEXT is used for language translation. Please install GETTEXT support

before using phpLDAPadmin. (Dont forget to restart your web server afterwards)

安装gettext
tar -xvf gettext-0.12.1.tar.tar 
./configure --prefix=/usr/local/gettext
make
make check
make install

在访问还有问题
重新编译php 加两个参数:
--with-gettext=/usr/local/gettext --with-ldap=/usr/local/openldap/

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-

gettext=/usr/local/gettext --with-ldap=/usr/local/openldap/

make
make install

在访问没问题了。

可以用匿名用户登陆或者输入用户名和密码登陆
======================================================

ldap 日志配置

要查OpenLDAP的log,必須先在/etc/syslog.conf裏加上一行:
local4.* /var/log/ldap.log
service syslog restart
这样就会生成该日志/var/log/ldap.log

五、配置文件
1.vi /usr/local/openldap/etc/openldap/slapd.conf
include      /usr/local/openldap/etc/openldap/schema/core.schema  #设置schema配置文档包含

pidfile         /usr/local/openldap/var/slapd.pid
argsfile        /usr/local/openldap/var/slapd.args  #设置pid和args文档位置

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       #设置目录项索引                

2. cd/usr/local/openldap/libex
./slapd启动服务
 
3.vi  /usr/local/openldap/etc/openldap/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值