LDAP

LDAP總體介紹

LDAP(輕量級目錄訪問協議,Lightweight Directory Access Protocol) 是實現提供被稱爲目錄服務的信息服務。目錄服務是一種特殊的數據庫系統,其專門針對讀取,瀏覽和搜索操作進行了特定的優化。目錄一般用來包含描述性的,基於屬性的信息並支持精細複雜的過濾能力。目錄一般不支持通用數據庫針對大量更新操作操作需要的複雜的事務管理或回捲策略。而目錄服務的更新則一般都非常簡單。這種目錄可以存儲包括個人信息、web鏈結、jpeg圖像等各種信息。爲了訪問存儲在目錄中的信息,就需要使用運行在TCP/IP之上的訪問協議—LDAP。

LDAP 目錄中的信息是是按照樹型結構組織,具體信息存儲在條目(entry)的數據結構中。條目相當於關係數據庫中表的記錄;條目是具有區別名DN(Distinguished Name)的屬性(Attribute),DN是用來引用條目的,DN相當於關係數據庫表中的關鍵字(Primary Key)。屬性由類型(Type)和一個或多個值(Values)組成,相當於關係數據庫中的字段(Field)由字段名和數據類型組成,只是爲了方便檢索的需要,LDAP中的Type可以有多個Value,而不是關係數據庫中爲降低數據的冗餘性要求實現的各個域必須是不相關的。LDAP中條目的組織一般按照地理位置和組織關係進行組織,非常的直觀。LDAP把數據存放在文件中,爲提高效率可以使用基於索引的文件數據庫,而不是關係數據庫。類型的一個例子就是mail, 其值將是一個電子郵件地址。

LDAP的信息是以樹型結構存儲的,在樹根一般定義國家(c=CN) 或域名(dc=com),在其下則往往定義一個或多個組織(organization)(o=Acme)或組織單元(organizationalunits) (ou=People)。一個組織單元可能包含諸如所有僱員、大樓內的所有打印機等信息。此外,LDAP支持對條目能夠和必須支持哪些屬性進行控制,這是有一個特殊的稱爲對象類別(objectClass)的屬性來實現的。該屬性的值決定了該條目必須遵循的一些規則,其規定了該條目能夠及至少應該包含哪些屬性。例如:inetorgPerson對象類需要支持sn(surname)和cn(common name)屬性,但也可以包含可選的如郵件,電話號碼等屬性。

在本系統中的LDAP目錄結構爲:

dc=xxx,dc=com       -------rootdn

  +o=commonUser     -------operation dn    

          +l=xxx      -------base dn

                +LoginName=xxx           -------用戶登錄名

                        +ServiceCode=xxx     -------用戶所訂購的服務的代碼

1.2閱讀對象

系統維護人員

2安裝說明

2.1設置系統環境

假設:

主機名:pp250

安裝路徑:/usr/netscape/

主機IP:192.168.11.96

設置以下系統環境:

1、使用系統管理員帳號登錄AIX系統,設置domainname

#domainname onewave.com

2、設置主機別名:pp250.onewave.com

編輯/etc/hosts 主機別名加入pp250.onewave.com


2.2安裝LDAP

得到directory.5.2p4.tar.gz的安裝包

解開:tar zxvf directory.5.2p4.tar.gz

cd directory

./setup

1Would you like to continue withinstallation? [Yes]:Yes

2Do you agree to the license terms?[No]: Yes

3,(選擇安裝內容)

Select the items you would like to install:

1.Netscape Servers

      InstallsNetscape Servers with the integrated Netscape Console onto your computer.

      2.NetscapeConsole

      InstallsNetscape Console as a stand-alone Java application on your computer.

To accept the default shown in brackets, press the Enterkey.Select the component you want to install [1]:1

4,(選擇自定義安裝)

Choose an installation type:

1.Express installation

      Allows you toquickly install the servers using the most common options and pre-defineddefaults. Useful for quick  evaluation of the products.

2.Typical installation

      Allows you tospecify common defaults and options.

3.Custom installation

      Allows you tospecify more advanced options. This is recommended for experienced serveradministrators only.

To accept the default shown in brackets, press the Enterkey.Choose an installation type [2]:3

5,(安裝目錄)

Install location [/usr/netscape]: /usr/netscape/

6,(產品組件)

   1. Netscape Server Products CoreComponents (3)

   2. NetscapeDirectory Suite (2)

   3. Administration Services (2)

Specify the components you wish to install [All]: 回車

7,(核心組件)

   1. Netscape Server Products CoreComponents

   2. Netscape Core Java classes

   3. Java Runtime Environment

Specify the components you wish to install [1, 2, 3]:回車

8,(Suitecomponents)

   1. Netscape Directory Server

   2. Netscape Directory Server Console

Specify the components you wish to install [1, 2]:回車

9,(AdministrationServices components)

   1. Netscape Administration Server

   2. Administration Server Console

Specify the components you wish to install [1, 2]: 回車

10,主機域名:<hostname>.<domainname>

注:要先在/etc/hosts中設置,例如:192.168.11.96  pp250.onewave.com

Computer name [pp250.onewave.com]:回車

11,指定執行該服務的用戶及組,通常情況下使用nobody用戶來執行。

System User [nobody]:回車

System Group [nobody]:回車

12Do you want to register this software withan existing Netscape configuration directory server? [No]: 回車

13,數據是否存放在本地目錄服務器中

If you want this directory server to store your data,answer No. Do you want to use another directory to store your data? [No]:回車

14,監聽端口

Directory server network port [389]:回車

15,輸入Directoryserver identifier

Directory server identifier [pp250]:回車

16,admin用戶名和密碼

Netscape configuration directory server administrator ID[admin]:回車

Password:

Password (again):

17,根節點標識:

Suffix[o=onewave.com]:dc=onewave,dc=com

18,輸入對目錄管理具有無限制權利的名稱和密碼:

Directory Manager DN [cn=Directory Manager]:cn=Manager

Password:

Password (again):

19,域名

Administration Domain [onewave.com]:回車

20,是否配置複製(可以在安裝完畢之後到console中配置)

Do you want to configure this directory server to usereplication? [No]:回車

21,創建sampleentry

Do you want to install the sample entries? [No]:回車

22,是否導入數據

Type the full path and filename, the word suggest, or theword none

[suggest]:回車

23,checkconfig

Do you want to disable schema checking? [No]:回車

24,管理端口

Administration port [8888]:

25,服務綁定ip

IP address [192.168.11.96]:

26,啓動用戶

Run Administration Server as [root]:回車


27,開始安裝:

Extracting Netscape core components...

[slapd-iptva1]: starting up server ...

... ...

[slapd-iptva1]: [02/Aug/2005:15:28:21 +0800] -Netscape-Directory/5.2 SP4 B02.079.1031 starting up

[slapd-iptva1]: [02/Aug/2005:15:28:22 +0800] -slapd started.

Your new directory server has been started.

startup: listening to [url]http://iptva1[/url], port30888 as root

……

Go to /data/netscape and type startconsole tobegin manaing your servers.


2.3啓動LDAP

啓動LDAP

#/usr/netscape/slapd-pp250/restart-slapd


停止LDAP:

#/usr/netscape/slapd-pp250/stop-slapd


2.4配置說明

2.4.1導入初始化數據

初始數據包含根節點、其它目錄節點的導入,可以通過ldap browser進行導入。如果是需要配置replication的,則只需要在主的LDAP中導入數據。


2.4.2BOSS添加的屬性、對象設置

屬性、對象存儲位置:/usr/netscape/slapd-pp250/config/schema/*.ldif

通過LDAP的系統管理窗口(console)對屬性、對象進行維護。


屬性顯示器

啓動控制檯圖形界面:

#/data/netscape/startconsole


https://s1.51cto.com/attachment/200812/200812081228707070406.jpg

輸入admin賬戶。密碼,正確的Administration URL,如上圖所示。

添加屬性

LDAP中需要添加BOSS系統定義的一些新屬性。

進入控制檯界面後,點Console:Directory Server(pp250)àConfiguration:Schema:Attributes

顯示屬性維護頁面,如下圖所示:可以對屬性進行添加、修改和刪除

https://s1.51cto.com/attachment/200812/200812081228707092625.jpg

添加對象

屬性添加後進行對象類的定義。

點Console:Directory Server(pp250)àConfiguration:Schema:Object Classes

顯示對象類維護頁面,如下圖所示:可以對對象類性進行添加、修改和刪除

https://s1.51cto.com/attachment/200812/200812081228707116609.jpg

2.4.3系統參數配置

使用console圖形界面設置一些系統參數。

1、設置Index
打開directory server的控制面板

configurationàdatabaseàIndexs
【注】不要刪除已有的Index
點擊Add Attribute,加入l, loginName, ServiceCode作爲Index
保存所作修改

2、設置performance
打開directory server的控制面板

configurationàdatabaseàperformance
修改下列各值,並保存。
Maximum entries incache:       2000
Maximum cache size:            20000000
Look-through limit:              5000



2.4.4replication配置

假設pp250(主),iptv副,則pp250設置爲Supplier,iptv設置爲Customer。

設置時候先設置Customer,再設置Supplier。


通過console配置replication

1,consumer配置

啓動控制檯圖形界面:

#/data/netscape/startconsole

注:用戶名密碼及端口同安裝的16步中設定的用戶名密碼及24步中設置的管理端口

https://s1.51cto.com/attachment/200812/200812081228707150593.jpg

雙擊Directory Server(iptv),選擇configuration ,進入配置頁面,如下圖:

https://s1.51cto.com/attachment/200812/200812081228707174109.jpg

選中“Replication Agreements”,在右邊的consumer setting中進行配置:

<<consumer settings>>

Supplier DN:cn=supplier

New supplier password

Confirm new supplier password

<<supplier settings>>(not set)

保存之後退出

https://s1.51cto.com/attachment/200812/200812081228707192859.jpg

2,supplier配置

同上,進入圖形界面中

<<cosumer settings>>(no set)
<<supplier settings>>

databasedir:/usr/netscape/slapd-pp250/changlogdb    (use default)
   changelogsuffix:cn=changelog
   Max changelog records:unlimited(V)
   Max changelog age: 2 days unlimited[]

保存之後重啓ldap

https://s1.51cto.com/attachment/200812/200812081228707213312.jpg

3,創建replication agreement

在主ldap中右鍵點擊Replication Agreements,選擇new replication agreement,如下圖:

https://s1.51cto.com/attachment/200812/200812081228707258125.jpg

選擇supplier initiated agreement,如下圖,輸入agreementname:

https://s1.51cto.com/attachment/200812/200812081228707284687.jpg

點擊next,如下圖:

https://s1.51cto.com/attachment/200812/200812081228707312828.jpg

在consumer中點擊other,輸入consumer的主機和服務端口:

https://s1.51cto.com/attachment/200812/200812081228707325578.jpg

bind ascn=supplier(同consumer中的配置一致)

password:supplier(同consumer中的配置一致)

subtree:dc=onewave,dc=com(l=ipauth,dc=onewave,dc=com)(可以同步跟節點,也可以選擇部分葉節點進行同步)

https://s1.51cto.com/attachment/200812/200812081228707336437.jpg

點擊next,如下:選擇同步時間

https://s1.51cto.com/attachment/200812/200812081228707353812.jpg

點擊next,初始化consumer,如下圖:

初始化consumer(在數據量大的情況下,不要選擇立即初始化,選擇創建ldif文件或者以後再初始化),配置完成之後,再利用手工的方式進行初始化。

手工初始化的步驟見附錄。

https://s1.51cto.com/attachment/200812/200812081228707363296.jpg


2.5LDAP使用和基本維護

2.5.1NetscapeDirectory Server安裝參數

1Netscape Directory Server安裝目錄:/usr/netscape/slapd-`hostname`/

2Netscape Directory Server 目錄列表:

目錄

作用

bak

Ldap數據庫備份目錄

changelogdb

主ldap上存放同步用的changelog信息

confbak

Ldap配置信息備份目錄

config

Ldap配置文件目錄

db

Ldap數據庫目錄

ldif

Ldif文件導出目錄

locks

記錄ldap的鎖信息的目錄

logs

Ldap log 目錄

ssl

Ssl信息存儲目錄

3Netscape Directory Server 主目錄下腳本列表:

腳本名

作用

腳本範例

bak2db

將Ldap數據庫備份目錄下最新的archived備份恢復回ldap

./bak2db  bak/2004_03_25_155704

db2bak

將ldap數據庫數據備份到bak目錄下

./db2bak

db2ldif

將ldap數據庫數據導出爲ldif格式的文件,備份到ldif目錄

./db2ldif

getconf

獲得ldap數據庫配置參數

./getconf

getpwenc

獲得ldap密碼加密後的祕文

./getpwenc sha  123456

./getpwenc crypt  123456

ldif2db

將ldif文件中的信息直接寫入數據庫

具體用法請見4.3.5

ldif2ldap

將ldif文件中的信息按照ldapadd的格式寫入數據庫

具體用法請見4.3.5

ldifbak

在cron中定義的每天備份ldap的腳本

30 1 * * *  /data3/netscape/server4/ slapd-ldap1/ldifbak

monitor

Ldap是否正常運行的監控腳本

./monitor

restart-slapd

Ldap重啓腳本

./restart_slapd

restoreconfig

將confbak目錄下最新的ldap配置信息恢復回ldap

./restoreconfig

saveconfig

將ldap配置信息備份至confbak目錄

./saveconfig

start-slapd

Ldap啓動腳本

./start-slapd

stop-slapd

Ldap停止腳本

./stop-slapd

vlvindex

reserved


注:以上表格中,粗體標註的命令,會對ldap產生一定破壞操作,不要輕易嘗試。

2.5.2DirectoryCosole的使用

使用圖形軟件(如:XManager)登錄AIX系統,並設置顯示到本機:如:本機IP爲192.168.11.160,則使用命令設置:#set DISPLAY=192.168.11.160:0.0 。

1.啓動Directory Server 控制檯

a.確定directory server daemon,slapd_serverID運行着,否則,以root身份啓動它。

#/usr/netscape/slapd_pp250/start-slapd

b.確定管理服務器daemon,admin-serv正在運行,否則,以root身份啓動它。

#/usr/netscape/start-admin

c.啓動iplanet控制檯,將出現控制檯登錄對話框。

% /usr/netscape/startconsole

d.用具有足夠權限的用戶登錄,並輸入相應的約束DN和密碼。

例:


e.在拓撲表中,沿着導航樹直到看見Directory Server的圖標,雙擊它,則可進入Directory Server控制檯。

2.改變登錄身份

a.在Directory Server控制檯上選擇任務表。

b.點擊“log on to the Directory Server as a new user”,便出現一個登錄對話框。

c.輸入新的DN和密碼,點擊OK。

3.從iplanet控制檯上查看當前的DN

點擊左下角的login圖標,則可出現當前的DN。

2.5.3DirectoryServer監控程序的使用

slapd進程的監控:/usr/netscape/slapd_*/ldapmon

編輯/var/spool/cron/crontabs/root文件,添加下列內容:

    * * * * * su – root –c ‘/usr/netscape/slapd_*/ldapmon

然後重啓cron:

   /etc/rc2.d/S75cronstop

   /etc/rc2.d/S75cronstart

2.5.4DirectoryServer基本命令使用

ldapsearch

ldapsearch –h server –p port –Dbinddn –w password –b “basedn” filter

-h: ldap server的主機名或IP

-p: ldap server的端口

-D: bind的用戶DN,通常爲: “cn=Manager”

-w: bind的用戶的密碼

-b: 需要搜索的dn

filter: 用以搜索的過濾器。例如:objectclass=*,loginName=xxx等。

例子:

%/usr/netscape/shared/bin/ldapsearch -h 192.168.11.96 -p389 -D cn=Manager -w onewaveinc -b cn=period,dc=onewave,dc=com  -ssub "objectclass=*"


ldapmodify:

ldapmodify –h server –p port –Dbinddn –w password -f /path/to/your/file/modify_file

-h: ldap server的主機名或IP

-p: ldap server的端口

-D: bind的用戶DN,通常爲: “cn=Manager”

-w: bind的用戶的密碼

-f: 指定modify_file的路徑及文件名

modify_file的格式:

dn:

changetype: modify

replace: attribute

attribute_name: attribute_value

注:modify_file裏的每一行記錄的冒號之後都必須有一個空格

例如:修改用戶test的密碼爲123456。其中test用戶的dn爲:loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com,相應的modify_file如下:

dn: loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com

changetype: modify

replace: userPassword

userPassword: 123456

例子:

./ldapmodify -a -h 192.168.11.96 -p 389 -D cn=Manager -wonewaveinc  -f /usr/netscape/test.ldif


ldapdelete:

ldapdelete–h server –p port –D binddn –w password -f/path/to/your/file/deldn_file

-h: ldap server的主機名或IP

-p: ldap server的端口

-D: bind的用戶DN,通常爲: “cn=Manager”

-w: bind的用戶的密碼

-f: 指定deldn_file的路徑及文件名,deldn_file裏記錄了要刪除的每一個entrydn信息,注意:要刪除節點不能包含子節點,若要刪除帶子節點的數據,則先刪除子節點後再刪除該節點。。

例如:要刪除用戶test,其中test用戶的dn: loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com,則deldn_file的內容爲:

loginName=test,o=commonUser,l=radtest,dc=onewave,dc=com


db2ldif:

db2ldif是可以在線導出ldif文件的,導出的文件在$Server_root/slapd-*/ldif下。

帶-r ,-a參數的ns-slapd db2ldif 是一定要在ldap 服務停下來之後執行的。

cd $Server_root/bin/slapd/server

./ns-slapd db2ldif -f$Server_root/slapd-*/config/slapd.conf -n [-r] -a $ldif_file -s"baseDN"

db2ldif是可以在線導出ldif文件的,導出的文件在$Server_root/slapd-*/ldif下。

-f: Directory Server配置文件slapd.conf的絕對路徑

-r: 需要導出ldif文件爲複製副本時,加上該參數。這個參數加不加的區別在於加上-r參數,會有一句copied from的話,這個在配置主備的時候有用,其它情況可以不用。

-a: 導出ldif文件的絕對路徑及文件名

-s: 導出的baseDN,通常爲:dc=xxx,dc=com

ldif2db:

cd $Server_root/bin/slapd/server

ns-slapd ldif2db -f$Server_root/slapd-*/config/slapd.conf \

-i $ldif_file -s "baseDN" -xo=NetscapeRoot

-f: Directory Server配置文件slapd.conf的絕對路徑

如果使用-f指定配置文件,是先倒數據,再一個一個index建的(每次處理只能建一個index,多個index情況下,一次又一次處理,所以在數據量大的情況下挺慢的)。

如果不用-f ,可以直接使用-noconfig ,這個是不管配置文件,直接原來ldif文件中有什麼數據,就在導入的時候全部覆蓋,在導入的同時生成index,比較快。

我覺得,如果自己作了一個完整的ldif文件,比如有配置信息,然後加上數據信息,再導入,可以直接使用noconfig來倒。

-i: 需導入的ldif文件的絕對路徑及文件名

-s: 導出的baseDN,通常爲:dc=xxx,dc=com

-x: 不要導入的dn


2.5.5數據備份

數據目錄:/usr/netscape/slapd-pp250/db/

定期做數據備份。可以使用cron處理。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章