天天看點

RH423-4 LDAP的功能模型一

LDAP的功能模型

一、功能子產品

功能模型主要是對這個目錄服務進行操作

1、查找的功能

2、更新或者修改的功能

3、認證的功能

在指令行中如何使用這些方法進行操作

1、通過openldap-clients 這個包的安裝使得有些指令可以進行操作

2、通過紅帽的目錄服務

最好還是使用openldap-clients的這,因為在很多的不同發行版的Linux都是通用的。

openldap-clients 都有些什麼基本的操作指令

ldapsearch 在目錄服務中進行搜尋

ldapadd 經一個LDIF的 檔案更新到目錄服務中

ldadmodify 修改一個已經存在在目錄服務中的條目

ldappasswd ,ldapmodrdn,ldapdelete 等都是常用的操作指令

二、OpenLDAP Client 的配置

為什麼要先進行配置,以為如果我們不配置client服務, 那麼每一次查詢或者修改一些資料的時候都将是很麻煩的如:

1、修改配置檔案(/etc/openldap/ldap.conf):

[root@station2 dirsrv]# vim /etc/openldap/ldap.conf

BASE dc=station2,dc=example,dc=com

HOST station2.example.com                          

#添加以上兩行,為了在使用openldap的時候簡化操作

2、如果想要在本個使用者進行修改,删除等操作,還要對~/.ldaprc進行修改

[root@station2 ~]# vim .ldaprc

BINDDN cn=Directory Manager            

#這裡說的就是使用這個超級使用者使用者進行操作

三、查詢ldapsearch

1、導入測試用資料庫

[root@station2 ~]# cp /usr/share/dirsrv/data/Example.ldif /root/example.ldif   

#Example.ldif為redhat的ds伺服器安裝時自帶

[root@station2 ~]#vi /root/example.ldif

:%s/dc=example,dc=com/dc=station2,dc=example,dc=com/gi

:%s/dc:\ example/dc: station2/gi

#将其相關資料改成自身ldap伺服器資料

[root@station2 ~]# ldapadd -x -c -W -f Example.ldif

Enter LDAP Password:

adding new entry "dc=station2,dc=example,dc=com"

#導入example.ldif到資料庫

2、使用ldapsearch查詢資料(匿名)

[root@station2 ~]# ldapsearch -x "uid=zhangsan123"

# extended LDIF

#

# LDAPv3

# base <> with scope subtree

# filter: uid=zhangsan123

# requesting: ALL

# zhangsan123, People, station2.example.com

dn: uid=zhangsan123,ou=People,dc=station2,dc=example,dc=com

cn: zhangsam 123

sn: zhang

givenName: Emanuel

objectClass: top

objectClass: person

objectClass: organizationalPerson

objectClass: inetOrgPerson

ou: Product Testing

ou: People

l: Santa Clara

uid: zhangsan123

telephoneNumber: +1 408 555 0933

facsimileTelephoneNumber: +1 408 555 9752

roomNumber: 3906

manager: uid=jwalker, ou=People, dc=station2,dc=example,dc=com

mail: [email protected]

# search result

search: 2

result: 0 Success

# numResponses: 2

# numEntries: 1

不同參數的使用說明

-H: url Use server at url        #這裡的大寫H 是加的URL路徑,如果是小寫的h 那麼就加主機名

-x :Use simple, not SASL binds     #隻是用簡單的認證,而沒有經過加密。如上面的搜尋的時候使用[root@station2 ~]# ldapsearch -x "uid=xduan"   這個時候使用匿名這個使用者進行的搜尋。

-D dn :Bind using dn                   #指定DN的名字 

-W :Prompt for simple bind password         #指定使用什麼使用者進行操作

-Z “Try to use StartTLS; -ZZ requires it; for LDAPS: -H ldaps://server   #設定是否是用加密的機制

-L Less verbose LDIF; up to -LLL

-b dn Base DN in tree to start search from

-s scope Search scope: sub, one, or base

據-L使顯示小的資訊,而-LLL是顯示更小的資訊

如:

[root@station2 ~]# ldapsearch -x "uid=zhangsan123" -LLL

#這樣的好處可已将這個檔案導出來,然後進行修改,然後就可以導入到ldap資料庫中

-b :要開始搜尋的DN字段

-s:指搜尋的範圍,一共有三種:1、sub:所有的都搜尋,包括子條目  2、one :搜自己和自己的下一級,下下級不可以搜尋到  3、base 隻是搜尋自己 ,不包含下一級

 3、采用運算符進行搜尋

ldapsearch -x '(uid=burns)' mail   #隻是所搜某一個關鍵字

LDAP的搜尋也可以使用:

= Exact match

>= Greater than or equal to     #這裡是根據字元串來搜尋的

<= Less than or equal to

~= Approximate match                 #可以使用約等于

LDAP同樣也可以邏輯運算

NOT:                (!(age>=21))

AND:                (&(sn=jones)(o=IBM))

OR:                  (|(sn=laurel)(sn=hardy))

執行個體:

root@station2 ~]# ldapsearch -x "(|(uid=zhangsan123)(uid=jvedder))"

# filter: (|(uid=zhangsan123)(uid=jvedder))

# jvedder, People, station2.example.com

dn: uid=jvedder, ou=People, dc=station2,dc=example,dc=com

cn: Jeff Vedder

sn: Vedder

givenName: Jeff

ou: Product Development

uid: jvedder

mail: [email protected]

telephoneNumber: +1 408 555 4668

facsimileTelephoneNumber: +1 408 555 0111

roomNumber: 3445

manager: uid=bparker, ou=People, dc=station2,dc=example,dc=com

# numResponses: 3

# numEntries: 2

本文轉自netsword 51CTO部落格,原文連結:http://blog.51cto.com/netsword/541775