由于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手冊,這里就不細講了。
到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目錄下。建議以源碼安裝的軟件都放到獨立的目錄下,不要放到軟件默認的目錄。好處是方便管理和控制,所有文件在統一的目錄下,卸載軟件只要刪除整個目錄就可以了。
安
裝完相關軟件后就可以著手配置了。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配置出錯。回頭仔細核查一下配置文檔。
客戶端配置文檔是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