安裝 LDAP 伺服器

LDAP ?!

解釋 LDAP 及其用途


LDAP 代表 Lightweight Directory Access Protocol (輕量目錄存取協定)。

透過 OpenLDAP,您可以將資料儲存在樹狀結構,讓他人存取。例如您可以建立一個完整的地址和電郵樹狀,或以 OpenLDAP建立公司完整的結構。

在本 HOWTO 中,我們將會講述在 SuSE Linux 7.0 上安裝 OpenLDAP 伺服器。

為甚麼會撰寫本文呢?因為我們需要建立一個 LDAP 伺服器,在互聯網上找到現有的 HOWTOs 太複雜,因此我們要靠自己才能戰勝 LDAP。

安裝

安裝 OpenLDAP 十分容易,選取兩個套件: openldap.rpm 和 ldaplib.rpm 

這兩個套件放在 "n" 子群組中。
現在您需要更改數個設定檔案,往 "/etc/openldap" 並修改 ldap.conf 檔案

以下會以我們的檔案作範例解釋設定:

/etc/openldap/ldap.conf

 ##########/etc/openldap/ldap.conf#########

# More details in the man page ldap.conf(5)
# This file should be globally readable

# here you specify the LDAP server: host name and IP address
host 127.0.0.1

# starting a search this is the first point in your directory
# tree of the database.

base o=testnet.de

# that is all

############################################


接著您需要修改 sladp.conf 檔案

/etc/openldap/slapd.conf

 ######### /etc/openldap/slapd.conf ###########

# this file must not be globally readable

# slapd.at.conf <-- here you find a description of the attributes
# slapd.oc.conf <-- here you find a description of the object classes

include /etc/openldap/slapd.at.conf
include /etc/openldap/slapd.oc.conf
schemacheck off

pidfile /var/run/slapd.pid
argsfile /var/run/slapd.args

# settings for the LDAP database
# here you specify the database which has to be used

database ldbm

# Suffix / root directory. this is the highest entry in the
# LDAP directory
suffix "o=testnet.de"

# Here the LDAP database is saved
directory /var/lib/ldap

# the administrator's name of this directory
rootdn "cn=Manager, o=testnet.de"


# here you specify the administrator's password
rootpw secret
############################################


現在可以啟動 OpenLDAP 伺服器了。

您可以輸入:

/sbin/init.d/ldap start

伺服器便會執行了﹗

建立資料庫

建立資料庫是十分複雜的,因為您需要在事前知道整個結構。

在這部分,我們會嘗試講述建立資料庫的步驟和解釋如何新增資料和容器物件 (container objects)。

首先您要在 /etc/openldap 建立一個名為 "ldif" 的新目錄:

>> cd /etc/openldap

>> mkdir ldif

>> cd ldif

以任何編輯器建立資料庫,我們就叫它做 datenbank.ldif

datenbank.ldif

dn: o=testnet.de
o: testnet.de
objectclass: top
objectclass: organization

dn: ou=linux, o=testnet.de
ou: linux
objectclass: organizationalUnit

dn: uid=tover, ou=linux, o=testnet.de
uid: tover
cn: Tom Over
sn: Over
givenname: Tom
objectclass: person
userpassword: clearpass
mailacceptinggeneralid: overmindtom@gmx.net
ou: linux

dn: uid=tslider, ou=linux, o=testnet.de
uid: tslider
cn: The Slider
sn: Slider
givenname: The
objectclass: person
userpassword: clearpass
mailacceptinggeneralid: slider_e-mai@gmx.de
ou: linux


現在已建立第一個資料庫,要新增至 LDAP 伺服器﹗

使用以下指令便可以做到:

>> ldapadd -D "cn=Manager, o=testnet.de" -w secret < /etc/openldap/ldif
/datenbank.ldif

程式應該會複製該指令。

要確定它可以運作,您只需執行指令:

>> ldapsearch uid=tover

您應該可以取得這個 "uid"的所有資料。

新增更多資料組

要新增更多資料組,就需要另一個檔案,我們叫它做 new.ldif

new.ldif

dn: uid=mmuster, ou=linux, o=testnet.de
uid: mmuster
cn: Max Maxample
sn: Maxample
givenname: Max
objectclass: person
userpassword: clearpass
mailacceptinggeneralid: mmaxample@testnet.de
ou: linux


這項資料可以透過 ldapadd 指令新增:
>> ldapadd -D "cn=Manager, o=testnet.de" -w secret < /etc/openldap/ldif
/new.ldif

新增更多容器物件 (container objects):

如果您想新增另一個容器物件,需要進行類似的步驟,您同樣要建立一個叫 container.ldif 的檔案。

container.ldif

dn: ou=abt2, o=testnet.de
ou: abt2
objectclass: organizationalUnit

dn: uid=hwurst, ou=abt2, o=testnet.de
uid: hwurst
cn: Hans Wurst
sn: Wurst
givenname: Hans
objectclass: person
userpassword: clearpass
mailacceptinggeneralid: hwurst@testnet.de
ou: abt2


您可以透過 ldapadd指令新增這個容器物件:

>> ldapadd -D "cn=Manager, o=testnet.de" -w secret < /etc/openldap/ldif
/container.ldif

在這容器內,id 為 hwurst 的使用者已存在,我們希望透過這些例子,您會清楚這些語法。

(另一個管理方法是使用 kldap 工具,不過在這兒不會講述這工具﹗ )

 

 

使用 Netscape 來存取資料

 

您可以透過 Netscape 的地址簿來存取 LDAP 伺服器,以下會講述如何運作:

開啟 Netscape,按:

 Communicator
> Address Book

選取 File 並建立一個新的 Directory,在這兒填上相對的欄位:

現在您可似使用 "Search For..."來搜尋資料。

這是這樣了﹗希望本文有助您更容易建立 LDAP 伺服器。

arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()